title: Class constructor NodeEnvironment cannot be invoked without ‘new’
body: <p>At first I encountered this error:</p>
  <p><a href="https://www.mongodb.com/community/forums/t/typeerror-class-constructor-nodeenvironment-cannot-be-invoked-without-new/151980" rel="nofollow noreferrer">https://www.mongodb.com/community/forums/t/typeerror-class-constructor-nodeenvironment-cannot-be-invoked-without-new/151980</a></p>
  <pre><code>PS E:\MongoDB-University\MongoDB-JavaScript-Developer\mflix-js&gt; npm test -t db-connection
  
  &gt; server@1.0.0 test
  &gt; jest --passWithNoTests &quot;db-connection&quot;
  
  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&gt;
  </code></pre>
  <p>And then I fixed it with this solution:</p>
  <p><a href="https://github.com/vercel/next.js/issues/8973" rel="nofollow noreferrer">https://github.com/vercel/next.js/issues/8973</a></p>
  <pre><code>{
    &quot;presets&quot;: [
      [
        &quot;next/babel&quot;,
        {
          &quot;preset-env&quot;: { &quot;targets&quot;: { &quot;node&quot;: true } }
        }
      ]
    ],
    &quot;plugins&quot;: []
  }
  </code></pre>
  <p>But now, I have this error:</p>
  <pre><code>[user@top mflix-js]$ node -v
  v14.17.1
  [user@op mflix-js]$ npm test -t db-connection
  
  &gt; server@1.0.0 test
  &gt; jest --passWithNoTests &quot;db-connection&quot;
  
  Determining test suites to run...Setup Mongo Connection
  Test environment found at &quot;/home/usr/Desktop/mflix-js/test/config/mongoEnvironment.js&quot; does not export a &quot;getVmContext&quot; method, which is mandatory from Jest 27. This method is a replacement for &quot;runScript&quot;.
  </code></pre>
  <p>Not sure where to go from here.</p>
  <p>EDITED:</p>
  <p>package.json:</p>
  <pre class="lang-js prettyprint-override"><code>{
    &quot;name&quot;: &quot;server&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;description&quot;: &quot;&quot;,
    &quot;main&quot;: &quot;index.js&quot;,
    &quot;scripts&quot;: {
      &quot;start&quot;: &quot;nodemon -L ./index.js&quot;,
      &quot;test&quot;: &quot;jest --passWithNoTests&quot;,
      &quot;test:watch&quot;: &quot;jest --passWithNoTests --watch&quot;,
      &quot;changestream:update&quot;: &quot;node test/lessons/change-updates.js&quot;,
      &quot;changestream:insert&quot;: &quot;node test/lessons/change-insert.js&quot;
    },
    &quot;husky&quot;: {
      &quot;hooks&quot;: {
        &quot;pre-commit&quot;: &quot;lint-staged&quot;
      }
    },
    &quot;lint-staged&quot;: {
      &quot;linters&quot;: {
        &quot;*.js&quot;: [
          &quot;prettier --write&quot;,
          &quot;eslint --fix&quot;,
          &quot;npm test&quot;,
          &quot;git add&quot;
        ]
      },
      &quot;ignore&quot;: [
        &quot;**/build/**&quot;,
        &quot;**/data/**&quot;
      ]
    },
    &quot;keywords&quot;: [],
    &quot;author&quot;: &quot;&quot;,
    &quot;license&quot;: &quot;ISC&quot;,
    &quot;dependencies&quot;: {
      &quot;babel-eslint&quot;: &quot;^9.0.0&quot;,
      &quot;bcryptjs&quot;: &quot;^2.4.3&quot;,
      &quot;bluebird&quot;: &quot;^3.5.1&quot;,
      &quot;body-parser&quot;: &quot;^1.18.3&quot;,
      &quot;chai&quot;: &quot;^4.1.2&quot;,
      &quot;cors&quot;: &quot;^2.8.4&quot;,
      &quot;dotenv&quot;: &quot;^6.0.0&quot;,
      &quot;eslint&quot;: &quot;^8.14.0&quot;,
      &quot;eslint-config-prettier&quot;: &quot;^3.1.0&quot;,
      &quot;eslint-config-react-app&quot;: &quot;^2.1.0&quot;,
      &quot;eslint-plugin-flowtype&quot;: &quot;^2.47.1&quot;,
      &quot;eslint-plugin-import&quot;: &quot;^2.12.0&quot;,
      &quot;eslint-plugin-jsx-a11y&quot;: &quot;^6.2.3&quot;,
      &quot;eslint-plugin-prettier&quot;: &quot;^2.6.0&quot;,
      &quot;eslint-plugin-react&quot;: &quot;^7.8.2&quot;,
      &quot;express&quot;: &quot;^4.16.3&quot;,
      &quot;faker&quot;: &quot;^4.1.0&quot;,
      &quot;jest-runner&quot;: &quot;^24.9.0&quot;,
      &quot;jsonwebtoken&quot;: &quot;^8.3.0&quot;,
      &quot;mocha&quot;: &quot;^9.2.2&quot;,
      &quot;mongodb&quot;: &quot;^3.1.6&quot;,
      &quot;morgan&quot;: &quot;^1.9.1&quot;,
      &quot;npm-check-updates&quot;: &quot;^3.1.21&quot;,
      &quot;prettier&quot;: &quot;^1.14.3&quot;,
      &quot;sinon&quot;: &quot;^5.0.10&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;@babel/core&quot;: &quot;^7.5.5&quot;,
      &quot;@babel/plugin-proposal-class-properties&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-decorators&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-do-expressions&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-export-default-from&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-export-namespace-from&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-function-sent&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-json-strings&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-logical-assignment-operators&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-nullish-coalescing-operator&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-numeric-separator&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-optional-chaining&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-pipeline-operator&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-proposal-throw-expressions&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-syntax-dynamic-import&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-syntax-import-meta&quot;: &quot;^7.0.0&quot;,
      &quot;@babel/plugin-transform-runtime&quot;: &quot;^7.5.5&quot;,
      &quot;@babel/preset-env&quot;: &quot;^7.5.5&quot;,
      &quot;@babel/register&quot;: &quot;^7.5.5&quot;,
      &quot;@babel/runtime&quot;: &quot;^7.5.5&quot;,
      &quot;babel-core&quot;: &quot;^7.0.0-bridge.0&quot;,
      &quot;babel-jest&quot;: &quot;^27.5.1&quot;,
      &quot;concurrently&quot;: &quot;^3.5.1&quot;,
      &quot;husky&quot;: &quot;^1.0.0&quot;,
      &quot;jest&quot;: &quot;^27.5.1&quot;,
      &quot;jest-cli&quot;: &quot;^27.5.1&quot;,
      &quot;jest-express&quot;: &quot;^1.6.0&quot;,
      &quot;lint-staged&quot;: &quot;^7.3.0&quot;,
      &quot;nodemon&quot;: &quot;^2.0.15&quot;
    }
  }
  </code></pre>