Skip to content

Comments

feat(NODE-7335): Create dedicated mocha runner with isolated vm context#4876

Draft
PavelSafronov wants to merge 15 commits intomongodb:mainfrom
PavelSafronov:NODE-7335-bundle-and-barrel-approach-poc
Draft

feat(NODE-7335): Create dedicated mocha runner with isolated vm context#4876
PavelSafronov wants to merge 15 commits intomongodb:mainfrom
PavelSafronov:NODE-7335-bundle-and-barrel-approach-poc

Conversation

@PavelSafronov
Copy link
Contributor

Description

Summary of Changes

Adds a way to run unit and integration tests against a special version of Node Driver where we block specific require calls. This is so we can be confident that our updates don't accidentally re-introduce a dependence on Node.

Notes for Reviewers

Below are steps for testing this out locally with timeout unit tests and CRUD API integ tests, the only tests we have migrated so far to support this new testing approach.

Steps to test unit tests
  1. add the following lines to src/timeout.ts around line 62, in the private constructor
    // eslint-disable-next-line no-console, @typescript-eslint/no-require-imports
    console.log(`os platform is ${require('os').platform()}`);
  1. npm run check:unit
  2. note that all unit tests pass, though now they are logging stuff to the console
  3. npm run check:unit-bundled
  4. note that timeout tests failed with something like:
 Error: Access to core module 'os' (from new _Timeout (/Users/pavel.safronov/code/node-mongodb-native/srctimeout.ts:64:35)) is restricted in this context
Steps to test unit tests
  1. add the following lines to src/mongo_client.ts, around line 430, in the constructor
    // eslint-disable-next-line no-console, @typescript-eslint/no-require-imports
    console.log(`os platform is ${require('os').platform()}`);
  1. run "CRUD API" integ tests with npm run check:test
  2. note that all unit tests pass, though now they are logging stuff to the console
  3. run "CRUD API" integ tests with npm run check:test-bundled
  4. note that integ tests fail with something like:
  1) CRUD API
       "before each" hook for "should correctly execute findOne method using crud api":
     Error: Access to core module 'os' (from new MongoClient (/Users/pavel.safronov/code/node-mongodb-native/src/mongo_client.ts:431:35)) is restricted in this context
      at restrictedRequire (test/tools/runner/vm_context_helper.ts:19:13)
      at new MongoClient (src/mongo_client.ts:431:35)
      at TestConfiguration.newClient (test/tools/runner/config.ts:333:12)
      at Context.<anonymous> (test/integration/crud/crud_api.test.ts:28:33)
      at processImmediate (node:internal/timers:505:21)

What is the motivation for this change?

To fail our tests if our code starts to use a prohibited import, so we can guarantee that the driver will work in a non-Node runtime.

Release Highlight

Release notes highlight

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants