'Class constructor NodeEnvironment cannot be invoked without ‘new’
At first I encountered this error:
PS E:\MongoDB-University\MongoDB-JavaScript-Developer\mflix-js> npm test -t db-connection
> [email protected] test
> jest --passWithNoTests "db-connection"
Determining test suites to run...Setup Mongo Connection
FAIL test/db-connection.test.js
● Test suite failed to run
TypeError: Class constructor NodeEnvironment cannot be invoked without 'new'
at new MongoEnvironment (test/config/mongoEnvironment.js:30:113)
at async TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
at async runJest (node_modules/@jest/core/build/runJest.js:404:19)
at async _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
at async runCLI (node_modules/@jest/core/build/cli/index.js:173:3)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.279 s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection
(node:17468) Warning: Accessing non-existent property 'count' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:17468) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
(node:17468) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
(node:17468) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
PS E:\MongoDB-University\MongoDB-JavaScript-Developer\mflix-js>
And then I fixed it with this solution:
https://github.com/vercel/next.js/issues/8973
{
"presets": [
[
"next/babel",
{
"preset-env": { "targets": { "node": true } }
}
]
],
"plugins": []
}
But now, I have this error:
[user@top mflix-js]$ node -v
v14.17.1
[user@op mflix-js]$ npm test -t db-connection
> [email protected] test
> jest --passWithNoTests "db-connection"
Determining test suites to run...Setup Mongo Connection
Test environment found at "/home/usr/Desktop/mflix-js/test/config/mongoEnvironment.js" does not export a "getVmContext" method, which is mandatory from Jest 27. This method is a replacement for "runScript".
Not sure where to go from here.
EDITED:
package.json:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon -L ./index.js",
"test": "jest --passWithNoTests",
"test:watch": "jest --passWithNoTests --watch",
"changestream:update": "node test/lessons/change-updates.js",
"changestream:insert": "node test/lessons/change-insert.js"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"linters": {
"*.js": [
"prettier --write",
"eslint --fix",
"npm test",
"git add"
]
},
"ignore": [
"**/build/**",
"**/data/**"
]
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-eslint": "^9.0.0",
"bcryptjs": "^2.4.3",
"bluebird": "^3.5.1",
"body-parser": "^1.18.3",
"chai": "^4.1.2",
"cors": "^2.8.4",
"dotenv": "^6.0.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^3.1.0",
"eslint-config-react-app": "^2.1.0",
"eslint-plugin-flowtype": "^2.47.1",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.8.2",
"express": "^4.16.3",
"faker": "^4.1.0",
"jest-runner": "^24.9.0",
"jsonwebtoken": "^8.3.0",
"mocha": "^9.2.2",
"mongodb": "^3.1.6",
"morgan": "^1.9.1",
"npm-check-updates": "^3.1.21",
"prettier": "^1.14.3",
"sinon": "^5.0.10"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-do-expressions": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.5.5",
"@babel/runtime": "^7.5.5",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^27.5.1",
"concurrently": "^3.5.1",
"husky": "^1.0.0",
"jest": "^27.5.1",
"jest-cli": "^27.5.1",
"jest-express": "^1.6.0",
"lint-staged": "^7.3.0",
"nodemon": "^2.0.15"
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|