How to resolve Mongod instance closed with code null - node.js

I am working on an application running on Ubuntu 20.04.4 and Node.js v14.19.3. It connects to MongoDB v3.6 on Docker.
While executing a jest test, it fails with the following error log:
FAIL src/user/user.service.spec.ts (8.555 s)
● Console
console.warn
Starting the instance failed, please enable debug for more infomation
at ../../../node_modules/mongodb-memory-server-core/src/MongoMemoryServer.ts:111:19
console.log
error closing connection to mongo: "Mongod instance closed with code \"null\""
at Object.<anonymous>.exports.closeInMongodConnection (utils/test-database.ts:24:15)
● UserService › should be defined
Failed: "Mongod instance closed with code \"null\""
15 | let connection: Connection
16 |
> 17 | beforeEach(async () => {
| ^
18 | const module: TestingModule = await Test.createTestingModule({
19 | imports: [
20 | rootMongooseTestModule(),
at Env.beforeEach (../../../node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:46:24)
at Suite.<anonymous> (user/user.service.spec.ts:17:3)
at Object.<anonymous> (user/user.service.spec.ts:13:1)
● UserService › should be defined
expect(received).toBeDefined()
Received: undefined
29 |
30 | it('should be defined', () => {
> 31 | expect(service).toBeDefined()
| ^
32 | })
33 |
34 | afterAll(async () => {
at Object.<anonymous> (user/user.service.spec.ts:31:21)
Any clue on 'Mongod instance closed with code "null"' is highly appreciated.

Related

TS2322: Type 'Redis' is not assignable to type 'RedisClient'. issue on Docker

I try to build an node.js app but I have an error like ;
=> ERROR [build 7/7] RUN npx nx build driver-api --prod 53.9s
------
> [build 7/7] RUN npx nx build driver-api --prod:
nx run driver-api:build:production
chunk (runtime: main) main.js (main) 348 KiB [entry] [rendered]
ERROR in /app/libs/database/src/lib/redis-pub-sub.provider.ts
./libs/database/src/lib/redis-pub-sub.provider.ts 16:10-19
[tsl] ERROR in /app/libs/database/src/lib/redis-pub-sub.provider.ts(16,11)
TS2322: Type 'Redis' is not assignable to type 'RedisClient'.
Type 'Redis' is missing the following properties from type 'Redis': stream, isCluster, connector, reconnectTimeout, and 140 more.
ERROR in /app/libs/database/src/lib/redis-pub-sub.provider.ts
./libs/database/src/lib/redis-pub-sub.provider.ts 17:10-20
[tsl] ERROR in /app/libs/database/src/lib/redis-pub-sub.provider.ts(17,11)
TS2322: Type 'Redis' is not assignable to type 'RedisClient'.
ERROR in libs/database/src/lib/redis-pub-sub.provider.ts:16:11
TS2322: Type 'Redis' is not assignable to type 'RedisClient'.
Type 'Redis' is missing the following properties from type 'Redis': stream, isCluster, connector, reconnectTimeout, and 140 more.
#12 53.66 14 | };
#12 53.66 15 | return new RedisPubSub({
#12 53.66 > 16 | publisher: new Redis(options),
#12 53.66 | ^^^^^^^^^
#12 53.66 17 | subscriber: new Redis(options),
#12 53.66 18 | })
#12 53.66 19 | } ,
#12 53.66
#12 53.66 ERROR in libs/database/src/lib/redis-pub-sub.provider.ts:17:11
#12 53.66 TS2322: Type 'Redis' is not assignable to type 'RedisClient'.
#12 53.66 15 | return new RedisPubSub({
#12 53.66 16 | publisher: new Redis(options),
#12 53.66 > 17 | subscriber: new Redis(options),
#12 53.66 | ^^^^^^^^^^
#12 53.66 18 | })
#12 53.66 19 | } ,
#12 53.66 20 | };
#12 53.66
#12 53.66 webpack compiled with 4 errors (b984ccb820b8363c)
my redis-pub-sub.provider.ts file like ;
import { pubSubToken } from '#nestjs-query/query-graphql';
import { RedisPubSub } from 'graphql-redis-subscriptions';
import Redis from 'ioredis';
import { Provider } from '#nestjs/common';
export class RedisPubSubProvider {
static provider(): Provider {
return {
provide: pubSubToken(),
useFactory: () => {
const options = {
host: process.env.REDIS_HOST || 'localhost',
port: 6379
};
return new RedisPubSub({
publisher: new Redis(options),
subscriber: new Redis(options),
})
} ,
};
}
}
how can I solve the issue ? can some one help me ?
when I try to build an node.js app I get an error like "TS2322: Type 'Redis' is not assignable to type 'RedisClient'. issue"

TypeError: (0 , _reactTestRenderer.act) is not a function

I am getting this error while using renderHook in my test case. Not sure what is the issue.
TypeError: (0 , _reactTestRenderer.act) is not a function
13 |
14 | it('allows to upload photos through the mutation', async () => {
> 15 | const { result, nextUpdate } = renderHook(() =>
| ^
16 | usePhotosUpload({
17 | photosUploadMutation,
18 | }),
at renderHook (../../../node_modules/react-hooks-testing-library/lib/index.js:151:30)
at Object._callee$ (__test__/hooks/usePhotosUpload.test.js:15:36)
at tryCatch (../../../node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (../../../node_modules/regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as next] (../../../node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (__test__/hooks/usePhotosUpload.test.js:13:103)
at _next (__test__/hooks/usePhotosUpload.test.js:15:194)
at __test__/hooks/usePhotosUpload.test.js:15:364
at Object.<anonymous> (__test__/hooks/usePhotosUpload.test.js:15:97)
For resolving this issue please make version same of react-test-renderer as of react in your package.json file.

Unit testing with jest multiple fails but one pass?

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.

Jest - I have a nested error when more than one file

I have two test files, when I rename and comment one of them, the test will pass successfuly, otherwise will always throw this error:
FAIL src/features/user/auth/register.resolver.test.ts (10.045 s)
● Register › a new user with a valid form › call register resolver and return the registered user
Tests cannot be nested. Test "encountered a declaration exception" cannot run because it is nested within "call register resolver and return the registered user".
28 | `
29 |
> 30 | describe('Login', () => {
| ^
31 | let dbConnection: Connection;
32 | let userRepository: UserRepository;
33 |
at Env.it (node_modules/jest-jasmine2/build/jasmine/Env.js:566:17)
at Object.<anonymous> (src/features/user/auth/login.resolver.test.ts:30:1)
● Register › a new user with a valid form › the new user is persisted in database
expect(received).toMatchObject(expected)
Matcher error: received value must be a non-null object
Received has value: undefined
81 | });
82 |
> 83 | expect(user).toMatchObject({
| ^
84 | id: expect.any(String),
85 | username: registerInput.username,
86 | email: registerInput.email,
at Object.<anonymous> (src/features/user/auth/register.resolver.test.ts:83:20)
● Register › a new user with an invalid form › returns the errors
Tests cannot be nested. Test "encountered a declaration exception" cannot run because it is nested within "returns the errors".
28 | `
29 |
> 30 | describe('Login', () => {
| ^
31 | let dbConnection: Connection;
32 | let userRepository: UserRepository;
33 |
at Env.it (node_modules/jest-jasmine2/build/jasmine/Env.js:566:17)
at Object.<anonymous> (src/features/user/auth/login.resolver.test.ts:30:1)
FAIL src/features/user/auth/login.resolver.test.ts (10.298 s)
● Login › with a valid form › call login resolver and return the logged in user
Tests cannot be nested. Test "encountered a declaration exception" cannot run because it is nested within "call login resolver and return the logged in user".
27 | `
28 |
> 29 | describe("Register", () => {
| ^
30 | let dbConnection: Connection;
31 | let userRepository: UserRepository;
32 |
at Env.it (node_modules/jest-jasmine2/build/jasmine/Env.js:566:17)
at Object.<anonymous> (src/features/user/auth/register.resolver.test.ts:29:1)
● Login › with an invalid form › returns an error [login]
Tests cannot be nested. Test "encountered a declaration exception" cannot run because it is nested within "returns an error [login]".
27 | `
28 |
> 29 | describe("Register", () => {
| ^
30 | let dbConnection: Connection;
31 | let userRepository: UserRepository;
32 |
at Env.it (node_modules/jest-jasmine2/build/jasmine/Env.js:566:17)
at Object.<anonymous> (src/features/user/auth/register.resolver.test.ts:29:1)
Test Suites: 2 failed, 2 total
Tests: 5 failed, 1 passed, 6 total
Snapshots: 0 total
Time: 11.143 s
Ran all test suites.
And here the test files: https://gist.github.com/srgrcp/01fbbd4df391a90c25c8c60622bc2514
If I'm not wrong, the error says: "the is nested within ", but these tests are in different files.

TypeError: chatManager.connect(...) is undefined

I am trying to use chatkit api in my react js project but I am getting the following error:
TypeError: chatManager.connect(...) is undefined
componentDidMount
C:/Users/admin/chat-app/src/App.js:33
30 |
31 |
32 |
33 | chatManager.connect().then(currentUser=> {
| ^ 34 | currentUser.subscribeToRoom({
35 | roomId:19436903,
36 | hooks:{
import React from 'react';
import Chatkit from 'pusher-chatkit-client';
import connect from 'pusher-chatkit-server';
//import Chatkit from 'pusher/chatkit';
import './App.css';
import RoomList from './RoomList';
import MessageList from './MessageList';
import SendMessageForm from './SendMessageForm';
import NewRoomForm from './CreateRoomForm';
//import {tokenUrl , instanceLocator} from './config.js';
class App extends React.Component
{
componentDidMount()
{
const chatManager=new Chatkit.ChatManager
({
instanceLocator:'v1:us1:a34c45b2-2af9-4f63-a532-fe189495f655',
userId:'manju',
tokenProvider:new Chatkit.TokenProvider
({
url:'https://us1.pusherplatform.io/services/chatkit_token_provider/v1/a34c45b2-2af9-4f63-a532-fe189495f655/token'
})
});
chatManager.connect().then(currentUser=> {
currentUser.subscribeToRoom({
roomId:19436903,
hooks:{
onNewMessage:message=>{
console.log('message.text :',message.text);
}
}
})
})
}
TypeError: chatManager.connect(...) is undefined
componentDidMount
C:/Users/admin/chat-app/src/App.js:33
30 |
31 |
32 |
33 | chatManager.connect().then(currentUser=> {
| ^ 34 | currentUser.subscribeToRoom({
35 | roomId:19436903,
36 | hooks:{

Resources