Unit testing with jest multiple fails but one pass? - jestjs
I am just trying to do a simple test to extract a json form a collections call and I am getting weird errors that make no sense. Like all of my tests fail except one meaning it went through? Here is my test:
const base64Image = "BASE_64_IMAGE";
const imageBuffer = new Buffer(base64Image, "base64"); //1 of them passed? I am confused
var imgfile = fs.readFileSync('./tests/testImages/crystal.png', imageBuffer);
describe("POST /collections", () => {
/*
test("should respond with a 200 status code", async () => {
const response = await request(app).post("/collections").send({
myImage: imgfile
})
expect(response.statusCode).toBe(200)
})
*/
test("should Retrieve a Image", async () => { // it passed?
const response = await request(app).post("/retrievImageJson").send({
_id: "626702aa313718fb12cc11b6"
})
expect(response.headers['content-type']).toEqual(expect.stringContaining("json"))
})
})
here is the route I am testing:
router.post("/retrievImageJSON", requireLogin, async (req, res) => {
User.findOne({_id: req.user}).select("collectionArray").then( result =>{
res.send(result)
}
).catch((err) =>{
console.log(err);
})
});
and here is the test failures (there is alot weirdly)
FAIL tests/uploadImages.test.js
● Test suite failed to run
SyntaxError: C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend\tests\uploadImages.test.js: Unexpected token, expected "," (34:0)
32 |
33 |
> 34 |
| ^
at instantiate (node_modules/#babel/parser/src/parse-error/credentials.js:61:22)
at instantiate (node_modules/#babel/parser/src/parse-error.js:58:12)
at Parser.toParseError [as raise] (node_modules/#babel/parser/src/tokenizer/index.js:1736:19)
at Parser.raise [as unexpected] (node_modules/#babel/parser/src/tokenizer/index.js:1781:16)
at Parser.unexpected [as expect] (node_modules/#babel/parser/src/parser/util.js:153:28)
at Parser.expect [as parseCallExpressionArguments] (node_modules/#babel/parser/src/parser/expression.js:988:14)
at Parser.parseCallExpressionArguments [as parseCoverCallAndAsyncArrowHead] (node_modules/#babel/parser/src/parser/expression.js:863:29)
at Parser.parseCoverCallAndAsyncArrowHead [as parseSubscript] (node_modules/#babel/parser/src/parser/expression.js:748:19)
at Parser.parseSubscripts [as parseExprSubscripts] (node_modules/#babel/parser/src/parser/expression.js:689:17)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.678 s
Ran all test suites.
npm ERR! code 1
npm ERR! path C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c "jest"
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\tquig\AppData\Local\npm-cache\_logs\2022-05-05T19_19_58_127Z-debug.log
PS C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend> npm test
> team2#1.0.0 test
> jest
FAIL tests/uploadImages.test.js
● Test suite failed to run
ReferenceError: Cannot access 'app' before initialization
1 |
2 | const supertest = require('supertest')
> 3 | const request = supertest(app)
| ^
4 | const fs = require('fs');
5 | const path = require('path')
6 | const app = require('../server/server.js')
at TestScheduler.scheduleTests (node_modules/#jest/core/build/TestScheduler.js:317:13)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.75 s
Ran all test suites.
npm ERR! code 1
npm ERR! path C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c "jest"
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\tquig\AppData\Local\npm-cache\_logs\2022-05-05T19_21_05_748Z-debug.log
PS C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend> npm test
> team2#1.0.0 test
> jest
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Listening on port 5000".
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at Server.<anonymous> (server/server.js:60:11)
(node:1852) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
FAIL tests/uploadImages.test.js
POST /collections
× should respond with a 200 status code (1 ms)
● POST /collections › should respond with a 200 status code
TypeError: request is not a function
20 |
21 | test("should respond with a 200 status code", async () => {
> 22 | const response = await request(app).post("/collections").send({
| ^
23 | myImage: imgfile
24 | })
25 | expect(response.statusCode).toBe(200)
at Object.request (tests/uploadImages.test.js:22:30)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.448 s
Ran all test suites.
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Successfully connected to MongoDB".
32 | app.use(express.json());
33 | app.use(cors({
> 34 | origin: ["http://localhost:3000"],
| ^
35 | credentials: true,
36 | }));
37 | //app.use(passport.initialize());
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at NativeConnection.<anonymous> (server/server.js:34:11)
at NativeConnection.Object.<anonymous>.Connection.onOpen (node_modules/mongoose/lib/connection.js:647:8)
at _setClient (node_modules/mongoose/lib/connection.js:895:8)
PS C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend> npm test
> team2#1.0.0 test
> jest
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Listening on port 5000".
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at Server.<anonymous> (server/server.js:60:11)
(node:8208) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
FAIL tests/uploadImages.test.js
POST /collections
× should respond with a 200 status code (1 ms)
● POST /collections › should respond with a 200 status code
TypeError: request is not a function
20 |
21 | test("should respond with a 200 status code", async () => {
> 22 | const response = await request(app).post("/collections").send({
| ^
23 | myImage: imgfile
24 | })
25 | expect(response.statusCode).toBe(200)
at Object.request (tests/uploadImages.test.js:22:30)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.348 s, estimated 3 s
Ran all test suites.
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Successfully connected to MongoDB".
32 | app.use(express.json());
33 | app.use(cors({
> 34 | origin: ["http://localhost:3000"],
| ^
35 | credentials: true,
36 | }));
37 | //app.use(passport.initialize());
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at NativeConnection.<anonymous> (server/server.js:34:11)
at NativeConnection.Object.<anonymous>.Connection.onOpen (node_modules/mongoose/lib/connection.js:647:8)
at _setClient (node_modules/mongoose/lib/connection.js:895:8)
at node_modules/mongoose/lib/connection.js:801:7
at node_modules/mongodb/src/utils.ts:624:5
at node_modules/mongodb/src/mongo_client.ts:434:9
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
npm ERR! path C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend
npm ERR! signal SIGINT
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c "jest"
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\tquig\AppData\Local\npm-cache\_logs\2022-05-05T19_22_59_129Z-debug.log
Terminate batch job (Y/N)? y
PS C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend> npm test
> team2#1.0.0 test
> jest
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Listening on port 5000".
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at Server.<anonymous> (server/server.js:60:11)
(node:228) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
FAIL tests/uploadImages.test.js
POST /collections
× should respond with a 200 status code (1 ms)
● POST /collections › should respond with a 200 status code
TypeError: request is not a function
20 |
21 | test("should respond with a 200 status code", async () => {
> 22 | const response = await request(app).post("/collections").send({
| ^
23 | myImage: imgfile
24 | })
25 | expect(true).toBe(true)
at Object.request (tests/uploadImages.test.js:22:30)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.376 s, estimated 3 s
Ran all test suites.
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Successfully connected to MongoDB".
32 | app.use(express.json());
33 | app.use(cors({
> 34 | origin: ["http://localhost:3000"],
| ^
35 | credentials: true,
36 | }));
37 | //app.use(passport.initialize());
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at NativeConnection.<anonymous> (server/server.js:34:11)
at NativeConnection.Object.<anonymous>.Connection.onOpen (node_modules/mongoose/lib/connection.js:647:8)
at _setClient (node_modules/mongoose/lib/connection.js:895:8)
at node_modules/mongoose/lib/connection.js:801:7
at node_modules/mongodb/src/utils.ts:624:5
at node_modules/mongodb/src/mongo_client.ts:434:9
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
npm ERR! command failed
npm ERR! signal SIGINT
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c "jest"
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\tquig\AppData\Local\npm-cache\_logs\2022-05-05T19_23_26_676Z-debug.log
Terminate batch job (Y/N)? y
PS C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend> npm test
> team2#1.0.0 test
> jest
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Listening on port 5000".
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at Server.<anonymous> (server/server.js:60:11)
(node:3644) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
PASS tests/uploadImages.test.js
POST /collections
√ should respond with a 200 status code (1 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.39 s, estimated 3 s
Ran all test suites.
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Successfully connected to MongoDB".
32 | app.use(express.json());
33 | app.use(cors({
> 34 | origin: ["http://localhost:3000"],
| ^
35 | credentials: true,
36 | }));
37 | //app.use(passport.initialize());
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at NativeConnection.<anonymous> (server/server.js:34:11)
at NativeConnection.Object.<anonymous>.Connection.onOpen (node_modules/mongoose/lib/connection.js:647:8)
at _setClient (node_modules/mongoose/lib/connection.js:895:8)
at node_modules/mongoose/lib/connection.js:801:7
at node_modules/mongodb/src/utils.ts:624:5
at node_modules/mongodb/src/mongo_client.ts:434:9
Jest did not exit one second after the test run has completed.
npm ERR! path C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend
npm ERR! command failed
npm ERR! signal SIGINT
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c "jest"
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\tquig\AppData\Local\npm-cache\_logs\2022-05-05T19_24_26_582Z-debug.log
Terminate batch job (Y/N)? y
PS C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend> npm test
> team2#1.0.0 test
> jest
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Listening on port 5000".
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at Server.<anonymous> (server/server.js:60:11)
(node:18276) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
FAIL tests/uploadImages.test.js
POST /collections
× should respond with a 200 status code (1 ms)
● POST /collections › should respond with a 200 status code
TypeError: app.address is not a function
20 |
21 | test("should respond with a 200 status code", async () => {
> 22 | const response = await request(app).post("/collections").send({
| ^
23 | myImage: imgfile
24 | })
25 | expect(response.statusCode).toBe(200)
at Test.serverAddress (node_modules/supertest/lib/test.js:46:22)
at new Test (node_modules/supertest/lib/test.js:34:14)
at Object.obj.<computed> [as post] (node_modules/supertest/index.js:28:14)
at Object.post (tests/uploadImages.test.js:22:43)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.404 s, estimated 3 s
Ran all test suites.
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Successfully connected to MongoDB".
32 | app.use(express.json());
33 | app.use(cors({
> 34 | origin: ["http://localhost:3000"],
| ^
35 | credentials: true,
36 | }));
37 | //app.use(passport.initialize());
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at NativeConnection.<anonymous> (server/server.js:34:11)
PS C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend> npm test
> team2#1.0.0 test
> jest
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Listening on port 5000".
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at Server.<anonymous> (server/server.js:60:11)
(node:19700) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
FAIL tests/uploadImages.test.js
POST /collections
× should respond with a 200 status code (2 ms)
● POST /collections › should respond with a 200 status code
TypeError: app.address is not a function
20 |
21 | test("should respond with a 200 status code", async () => {
> 22 | const response = await request(app).post("/collections").send({
| ^
23 | myImage: imgfile
24 | })
25 | expect(response.statusCode).toBe(200)
at Test.serverAddress (node_modules/supertest/lib/test.js:46:22)
at new Test (node_modules/supertest/lib/test.js:34:14)
at Object.obj.<computed> [as post] (node_modules/supertest/index.js:28:14)
at Object.post (tests/uploadImages.test.js:22:43)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.248 s, estimated 3 s
Ran all test suites.
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Successfully connected to MongoDB".
32 | app.use(express.json());
33 | app.use(cors({
> 34 | origin: ["http://localhost:3000"],
| ^
35 | credentials: true,
36 | }));
37 | //app.use(passport.initialize());
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at NativeConnection.<anonymous> (server/server.js:34:11)
at NativeConnection.Object.<anonymous>.Connection.onOpen (node_modules/mongoose/lib/connection.js:647:8)
at _setClient (node_modules/mongoose/lib/connection.js:895:8)
at node_modules/mongoose/lib/connection.js:801:7
at node_modules/mongodb/src/utils.ts:624:5
at node_modules/mongodb/src/mongo_client.ts:434:9
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
npm ERR! path C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend
npm ERR! command failed
npm ERR! signal SIGINT
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c "jest"
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\tquig\AppData\Local\npm-cache\_logs\2022-05-05T19_30_02_610Z-debug.log
Terminate batch job (Y/N)? y
PS C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend> npm test
> team2#1.0.0 test
> jest
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Listening on port 5000".
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at Server.<anonymous> (server/server.js:60:11)
(node:14128) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
FAIL tests/uploadImages.test.js
POST /collections
× should respond with a 200 status code (2 ms)
● POST /collections › should respond with a 200 status code
TypeError: app.address is not a function
20 |
21 | test("should respond with a 200 status code", async () => {
> 22 | const response = await request(app).post("/collections").send({
| ^
23 | myImage: imgfile
24 | })
25 | expect(response.statusCode).toBe(200)
at Test.serverAddress (node_modules/supertest/lib/test.js:46:22)
at new Test (node_modules/supertest/lib/test.js:34:14)
at Object.obj.<computed> [as post] (node_modules/supertest/index.js:28:14)
at Object.post (tests/uploadImages.test.js:22:43)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.311 s, estimated 3 s
Ran all test suites.
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Successfully connected to MongoDB".
32 | app.use(express.json());
33 | app.use(cors({
> 34 | origin: ["http://localhost:3000"],
| ^
35 | credentials: true,
36 | }));
37 | //app.use(passport.initialize());
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at NativeConnection.<anonymous> (server/server.js:34:11)
at NativeConnection.Object.<anonymous>.Connection.onOpen (node_modules/mongoose/lib/connection.js:647:8)
at _setClient (node_modules/mongoose/lib/connection.js:895:8)
at node_modules/mongoose/lib/connection.js:801:7
at node_modules/mongodb/src/utils.ts:624:5
at node_modules/mongodb/src/mongo_client.ts:434:9
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
npm ERR! path C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend
npm ERR! command failed
npm ERR! signal SIGINT
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c "jest"
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\tquig\AppData\Local\npm-cache\_logs\2022-05-05T19_36_48_633Z-debug.log
Terminate batch job (Y/N)? y
PS C:\Users\tquig\OneDrive\Documents\GitHub\Team2\backend> npm test
> team2#1.0.0 test
> jest
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Listening on port 5000".
at console.log (node_modules/#jest/console/build/CustomConsole.js:172:10)
at Server.<anonymous> (server/server.js:60:11)
(node:5212) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
FAIL tests/uploadImages.test.js
POST /collections
× should Retrieve a Image (2 ms)
● POST /collections › should Retrieve a Image
TypeError: app.address is not a function
29 |
30 | test("should Retrieve a Image", async () => {
> 31 | const response = await (await request(app).post("/retrievImageJson")).send({
| ^
32 | _id: "626702aa313718fb12cc11b6"
33 |
34 | })
at Test.serverAddress (node_modules/supertest/lib/test.js:46:22)
at new Test (node_modules/supertest/lib/test.js:34:14)
at Object.obj.<computed> [as post] (node_modules/supertest/index.js:28:14)
at Object.post (tests/uploadImages.test.js:31:50)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.376 s, estimated 3 s
Ran all test suites.
I am just trying to make sense of this. I am not sure where it failed because some of the failures are on code that is nonexistent. If anyone has an idea on what is going on that would be super helpful.
Related
getting a failed and type error when runing "npm run build" from a webpack 5 file. I pasted the code below
gregmcnally#Gregs-MacBook-Pro CS55.13-todo-app-week-8-main % npm run build todo-app-week08#0.1.0 build /Users/gregmcnally/Downloads/CS55.13-todo-app-week-8-main next build info - Loaded env from /Users/gregmcnally/Downloads/CS55.13-todo-app-week-8-main/.env.local info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5 Failed to compile. ./pages/ssr-no-token.tsx:62:51 Type error: Argument of type 'IncomingMessage & { cookies: NextApiRequestCookies; }' is not assignable to parameter of type 'null | undefined'. Type 'IncomingMessage & { cookies: NextApiRequestCookies; }' is not assignable to type 'null'. 60 | // withAuthUserTokenSSR. 61 | const token = await AuthUser.getIdToken() 62 | const endpoint = getAbsoluteURL('/api/example', req) | ^ 63 | const response = await fetch(endpoint, { 64 | method: 'GET', 65 | headers: { info - Checking validity of types .npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! todo-app-week08#0.1.0 build: next build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the todo-app-week08#0.1.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /Users/gregmcnally/.npm/_logs/2021-12-17T02_08_03_370Z-debug.log gregmcnally#Gregs-MacBook-Pro CS55.13-todo-app-week-8-main %
firebase cloud functions sample code error
Please help: I'm new to firebase cloud functions and face the below problem when I follow the startup guide provided by Google. Below is the startup template index.js file // The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers. const functions = require('firebase-functions'); // The Firebase Admin SDK to access Firestore. const admin = require('firebase-admin'); admin.initializeApp(); // Create and Deploy Your First Cloud Functions // https://firebase.google.com/docs/functions/write-firebase-functions exports.helloWorld = functions.https.onRequest((request, response) => { functions.logger.info("Hello logs!", {structuredData: true}); response.send("Hello from Firebase!"); }); When I type firebase deploy in the terminal. It gives me these error codes: - 1:1 error This line has a length of 85. Maximum allowed is 80 max-len - 2:27 error Strings must use doublequote quotes - 5:23 error Strings must use doublequote quotes - 8:1 error Expected indentation of 0 spaces but found 1 indent - 9:1 error Expected indentation of 0 spaces but found 1 indent - 11:1 error Expected indentation of 0 spaces but found 1 indent - 12:1 error Expected indentation of 2 spaces but found 3 indent - 13:1 error Expected indentation of 2 spaces but found 3 indent - 14:1 error Expected indentation of 0 spaces but found 1 indent ✖ 9 problems (9 errors, 0 warnings) 8 errors and 0 warnings potentially fixable with the `--fix` option. -npm ERR! code ELIFECYCLE -npm ERR! errno 1 -npm ERR! functions# lint: `eslint .` -npm ERR! Exit status 1 -npm ERR! -npm ERR! Failed at the functions# lint script. -npm ERR! This is probably not a problem with npm. There is likely additional logging output above. -npm ERR! A complete log of this run can be found in: -npm ERR! C:\Users\alant\AppData\Roaming\npm-cache\_logs\2021-06-21T13_22_47_971Z-debug.log -events.js:292 throw er; // Unhandled 'error' event ^ -Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT at notFoundError (C:\Users\alant\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26) at verifyENOENT (C:\Users\alant\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16) at ChildProcess.cp.emit (C:\Users\alant\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25) at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) Emitted 'error' event on ChildProcess instance at: at ChildProcess.cp.emit (C:\Users\alant\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37) at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) { code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn npm --prefix "%RESOURCE_DIR%" run lint', path: 'npm --prefix "%RESOURCE_DIR%" run lint', spawnargs: [] } -Error: functions predeploy error: Command terminated with non-zero exit code1
Run this in the terminal: eslint --fix
#Hamada After studying the eslint documentation. I finally do this Add this at start and at the end. `/* eslint-disable */ //My code (all rules will be disable) /* eslint-enable */` Eg. `// The Cloud Functions for Firebase SDK to // create Cloud Functions and setup triggers. /* eslint-disable */ const functions = require('firebase-functions'); // The Firebase Admin SDK to access Firestore. const admin = require('firebase-admin'); admin.initializeApp(); // Create and Deploy Your First Cloud Functions // https://firebase.google.com/docs/functions/write-firebase-functions exports.helloWorld = functions.https.onRequest((request, response) => { functions.logger.info("Hello logs!", {structuredData: true}); response.send("Hello from Firebase!"); /* eslint-enable */ });`
Puppeteer VUE JS problems with HTTPS
I have a problem with executing tests served from NODE net::ERR_CONNECTION_REFUSED at https://localhost:8087 at navigate (node_modules/puppeteer/src/common/FrameManager.ts:190:13) Test Suites: 2 failed, 2 total Tests: 7 failed, 7 total Snapshots: 0 total Time: 5.093s Ran all test suites. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! dsf-frontend#0.1.0 test:e2e: `vue-cli-service test:unit -c jest.e2e.config.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the dsf-frontend#0.1.0 test:e2e script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /home/xxxxxx/.npm/_logs/2021-04-13T10_41_31_417Z-debug.log
This error was solved by updating certificates and after change the node version to v10.24.1. However, I have a problem with timeouts when the test is longer than 5000 ms. : Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: 30 | const testAndScreenshot = function (url: string): ((name: string, func: (page: puppeteer.Page) => void) => Promise<void>) { 31 | return async function (name, func) { > 32 | test(name, async () => { | ^ 33 | // for subsequent tests, we leave the page logged in, unless we need to switch to testing a different app 34 | if (!page || page.isClosed() || !page.url().includes(url)) { 35 | page = await browser.newPage();
ELIFECYCLE error. How to fix it?
I am facing difficulty in deploying the notification function to the firebase. I also used npm run clean but the error showed in it that- npm ERR! missing script: clean The index.js code is as follows- 'use strict' const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.pushNotification = functions.database.ref('/Notifications/{user_id}/{notification_id}').onWrite(event => { const user_id = event.params.user_id; const notification = event.params.notification; console.log('We have a notification to send to : ', user_id); if(event.data.val()){ return console.log('A Notification has been deleted feom the database :', notification_id); } const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken).once('value'); return deviceToken.then(result => { const token_id = result.val(); const payload = { notification: { title : "Friend Request", bosy : "You have received a new Friend Request", icon : "default" } }; return admin.messaging().sendToDevice(/*Token ID*/, payload).then(response => { console.log('This was the notification Feature'); }); }); }); The firebase deploy error in the Command Prompt is- C:\Users\NIHIR\Desktop\MilApp\notificationFunction>firebase deploy === Deploying to 'milapp2-55dfb'... i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint > functions# lint C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions > eslint . C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions\index.js 19:61 error Parsing error: Unterminated template ✖ 1 problem (1 error, 0 warnings) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! functions# lint: `eslint .` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the functions# lint script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\NIHIR\AppData\Roaming\npm-cache\_logs\2018-03-10T22_49_06_402Z-debug.log Error: functions predeploy error: Command terminated with non-zero exit code1 How to fix this error? Using it in Windows 10. Thanks in advance. Even after correcting the mistake, I got the error again in deploying firebase as- C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions\index.js 33:53 error Parsing error: Unexpected token , ✖ 1 problem (1 error, 0 warnings) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! functions# lint: `eslint .` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the functions# lint script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\NIHIR\AppData\Roaming\npm-cache\_logs\2018-03-11T11_27_17_307Z-debug.log Error: functions predeploy error: Command terminated with non-zero exit code1
The error message is this: 19:61 error Parsing error: Unterminated template It's referring to the fact that the template string on this line isn't terminated: const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken).once('value'); You're missing the closing backtick for that reference string. It should be like this: const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken`).once('value');
Jest Unit Tests Fail When Test Directory Search Location Is Changed
I am encountering an odd problem with jest: changing where jest looks for its test files appears to break the tests. I've narrowed it down to a very small reproducable case. This jest configuration, set in our package.json succeeds: "jest": { "testFileExtensions": ["jest"], "testPathDirs": ["Views/Test"], "scriptPreprocessor": "Views/Test/preprocessor.js", "moduleFileExtensions": [ "js", "jsx" ], "unmockedModulePathPatterns": [ "react" ] } Like so: npm info it worked if it ends with ok npm info using npm#2.2.0 npm info using node#v0.10.33 npm info pretest outfits#0.0.0 npm info test outfits#0.0.0 > outfits#0.0.0 test C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits > jest Using Jest CLI v0.2.2 Waiting on 2 tests... PASS Views\Test\__tests__\Components\Outfit\Description\Description.jest (3.164s) Waiting on 1 test... PASS Views\Test\__tests__\Components\Outfit\GetTheLook\GetTheLook.jest (4.475s) 2 tests passed (2 total) Run time: 5.339s npm info posttest outfits#0.0.0 npm info ok This jest configuration causes one of the two tests to fail. The only change is changing the root of where it looks for the __tests__ directory(ies). "jest": { "testFileExtensions": ["jest"], "testPathDirs": ["Views"], "scriptPreprocessor": "Views/Test/preprocessor.js", "moduleFileExtensions": [ "js", "jsx" ], "unmockedModulePathPatterns": [ "react" ] } With an oddball exception that looks like this (elided for brevity and reflowed for readability): Using Jest CLI v0.2.2 Waiting on 2 tests... PASS Views\Test\__tests__\Components\Outfit\Description\Description.jest (3.108s) Waiting on 1 test... FAIL Views\Test\__tests__\Components\Outfit\GetTheLook\GetTheLook.jest (3.233s) ● Get the look to › it encountered a declaration exception - TypeError: C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\nord\flux.js: C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\nord\core\actions.js: C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\nord\util\useGlobal.js: C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\nord\util\object\getDeepProperty.js: C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\nord\util\object\result.js: C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\nord\node_modules\lodash-node\compat\object\result.js: C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\nord\node_modules\lodash-node\compat\lang\isFunction.js: C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\nord\node_modules\lodash-node\compat\lang\isNative.js: Cannot call method 'replace' of undefined at C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\nord\node_modules\lodash-node\compat\lang\isNative.js:27:4 at Object.runContentWithLocalBindings (C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\jest-cli\src\lib\utils.js:357:17) at Loader._execModule (C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\jest-cli\src\HasteModuleLoader\HasteModuleLoader.js:245:9) at Loader.requireModule (C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\jest-cli\src\HasteModuleLoader\HasteModuleLoader.js:900:12) at Loader._generateMock (C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\jest-cli\src\HasteModuleLoader\HasteModuleLoader.js:276:30) at Loader.requireMock (C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\jest-cli\src\HasteModuleLoader\HasteModuleLoader.js:796:43) at Loader.requireModuleOrMock (C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\jest-cli\src\HasteModuleLoader\HasteModuleLoader.js:919:17) at C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\nord\node_modules\lodash-node\compat\lang\isFunction.js:2:16 ... at Suite.<anonymous> (C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\Views\Test\__tests__\Components\Outfit\GetTheLook\GetTheLook.jest:5:13) at env.describe_ (<anonymous>:40:25) at env.describe (<anonymous>:27:19) at describe (C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\node_modules\jest-cli\vendor\jasmine\jasmine-1.3.0.js:604:27) at C:\tfs\Nordstrom.Outfits\Nordstrom.Outfits\Views\Test\__tests__\Components\Outfit\GetTheLook\GetTheLook.jest:4:1 ... at process._tickCallback (node.js:419:13) 1 test failed, 1 test passed (2 total) Run time: 4.108s npm info outfits#0.0.0 Failed to exec test script npm ERR! Test failed. See above for more details. Our source tree (also elided for brevity) looks like this: <rootDir>/ | +- package.json | +-node_modules/ | | | +-gulp/ | +-jest/ | +-react | +-... | +-Views/ | +-Components/ | | | +-Description/Description.jsx | +-GetTheLook/GetTheLook.jsx | +-Test/ | +- preprocessor.js | +- __tests__/ | +-Components/ | +-Outfit/ | +-Description/Description.jest +-GetTheLook/GetTheLook.jest