-1
I am studying jest and stuck in a part in the course where it is made the configuration of the project to run the jest
next to the mongodb
.
I’m using the dependency @Shelf/jest-mongodb.
jest-mongodb-config.js
module.exports = {
mongodbMemoryServerOptions: {
binary: {
version: '4.0.3',
skipMD5: true
},
instance: {
dbName: 'jest'
},
autoStart: false
}
}
jest-config.js
module.exports = {
roots: ['<rootDir>/src'],
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
coverageDirectory: 'coverage',
testEnvironment: 'node',
preset: '@shelf/jest-mongodb',
transform: {
'.+\\.ts$': 'ts-jest'
}
}
Mongo-helper.ts
import { MongoClient } from 'mongodb'
export const MongoHelper = {
client: null as MongoClient,
async connect (uri: string): Promise<void> {
this.client = await MongoClient.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true
})
},
async disconnect (): Promise<void> {
await this.client.close()
}
}
excerpt from Account.spec.ts file that makes the connection
beforeAll(async () => {
await MongoHelper.connect(process.env.MONGO_URL)
})
afterAll(async () => {
await MongoHelper.disconnect()
})
But while running the test, I’m getting the error:
Determining test suites to run...Starting the instance failed, please enable debug for more infomation
● Test suite failed to run
Status Code is 403 (MongoDB's 404)
This means that the requested version-platform combination doesn't exist
at ClientRequest.<anonymous> (node_modules/mongodb-memory-server-core/lib/util/MongoBinaryDownload.js:378:44)
I tried something I saw in some posts to include in my package.json the section below, but the result is the same.
"config": {
"mongodbMemoryServer": {
"version": "latest"
}
}
Thanks for the reply, I tried but the result was the same.
Status Code is 403 (MongoDB's 404)
– Colasanto
When running the test, it should have created a file at the root, called "globalConfig.json", with a "mongoUri" property that points to the database in memory. Check that he created the file. If he did not create it, try adding the "config" property with another version of the database and apply it with Yarn or npm install.
– Jonathan Nascimento