Skip to content

Commit d23ee71

Browse files
committed
added readme info about the current approach
1 parent b17b665 commit d23ee71

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
"check:snappy": "nyc mocha test/unit/assorted/snappy.test.js",
158158
"check:x509": "nyc mocha test/manual/x509_auth.test.ts",
159159
"check:runtime-independence": "ts-node test/tools/runner/vm_context_helper.ts test/integration/change-streams/change_stream.test.ts",
160-
"check:test-bundled": "npm run build:bundle && npm run switch:to-bundled&& npm run check:test ; npm run switch:to-unbundled",
160+
"check:test-bundled": "npm run build:bundle && npm run switch:to-bundled && npm run check:test ; npm run switch:to-unbundled",
161161
"build:bundle": "npm run bundle:driver && npm run bundle:types",
162162
"build:runtime-barrel": "node etc/build-runtime-barrel.mjs",
163163
"bundle:driver": "node etc/bundle-driver.mjs",

test/readme.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ about the types of tests and how to run them.
4343
- [AWS Authentication tests](#aws-authentication-tests)
4444
- [Running AWS tests](#running-aws-tests)
4545
- [Container Tests](#container-tests)
46+
- [Node-less Runtime Testing](#node-less-runtime-testing)
47+
- [Design](#design)
48+
- [Adding tests to be tested with Node-less Runtime](#adding-tests-to-be-tested-with-node-less-runtime)
49+
- [Running tests in Node-less Runtime](#running-tests-in-node-less-runtime)
50+
- [Running tests manually in Node-less Runtime](#running-tests-manually-in-node-less-runtime)
4651
- [GCP](#gcp)
4752
- [Azure](#azure)
4853
- [AWS](#aws)
54+
- [Running tests with TLS](#running-tests-with-tls)
4955
- [TODO Special Env Sections](#todo-special-env-sections)
5056
- [Testing driver changes with mongosh](#testing-driver-changes-with-mongosh)
5157
- [Point mongosh to the driver](#point-mongosh-to-the-driver)
@@ -715,6 +721,64 @@ our existing integration test suite and run Evergreen patches against a single i
715721
_Note that in cases where the tests need to run longer than one hour to ensure that tokens expire
716722
that the mocha timeout must be increased in order for the test not to timeout._
717723

724+
### Node-less Runtime Testing
725+
726+
We are starting to remove explicit Node requirements, and are making it possible for users to provide us with the required functionality.
727+
728+
To that end, need to run our tests in a Node-less environment. These tests need to fail if our code erroneously uses Node.
729+
730+
#### Design
731+
732+
The approach we are taking is to modify our unit and integration tests to run against a patched version of the driver, where any illegal `require` calls are blocked.
733+
734+
Here are a few of the relevant components of this system:
735+
736+
1. [test/mongodb.ts](test/mongodb.ts)
737+
- Test entrypoint that exports Driver and all internal types.
738+
2. [etc/bundle-driver.mjs](etc/bundle-driver.mjs)
739+
- Creates a CommonJS bundle (Driver and all internal types) from `test/mongodb.ts`.
740+
3. [test/tools/runner/vm_context_helper.ts](./tools/runner/vm_context_helper.ts)
741+
- Special VM that blocks specific `require` calls.
742+
4. [test/mongodb_bundled.ts](./mongodb_bundled.ts)
743+
- Exports MongoDB from CommonJS bundle created by `etc/bundle-driver.mjs`, using `vm_context_helper.ts` to detect usages of blocked `require` calls.
744+
- This file is currently maintained by hand and needs to export types explicitly. We may want to generate this file as well.
745+
5. [test/mongodb_runtime-testing.ts](./mongodb_runtime-testing.ts)
746+
- Generated "barrel file". It exports either `test/mongodb.ts` (Driver + all internal types) or `test/mongodb_bundled.ts` (Driver + all internal types, loaded from bundle, and using `vm_context_helper.ts` to block `require` calls.)
747+
6. [etc/build-runtime-barrel.mjs](./etc/build-runtime-barrel.mjs)
748+
- Generates the barrel file `test/mongodb_runtime-testing.ts` based on `MONGODB_BUNDLED` env var.
749+
750+
#### Adding tests to be tested with Node-less Runtime
751+
752+
Change the test's import from
753+
`} from '../../mongodb';`
754+
to
755+
`} from '../../mongodb_runtime-testing';`
756+
757+
#### Running tests in Node-less Runtime
758+
759+
To run opted-in unit or integration tests in a Node-less runtime, run:
760+
761+
`npm run check:unit-bundled`
762+
or
763+
`npm run check:test-bundled`
764+
765+
Either command will:
766+
767+
1. Create a bundle from `test/mongodb.ts`
768+
2. Regenerate the barrel file to export from the generated bundle
769+
3. Run unit or integ tests
770+
4. Regenerate the barrel file to export from the test entry point
771+
772+
#### Running tests manually in Node-less Runtime
773+
774+
Call the following command to regenerate the barrel file to import from the bundle:
775+
`npm run switch:to-bundled`
776+
777+
Call the following command to rebuild the bundle:
778+
`npm run build:bundle`
779+
780+
You can now run the unit or integ tests locally and they will be importing from the patched bundle.
781+
718782
## GCP
719783
720784
1. Add a new GCP prose test to `test/integration/auth/mongodb_oidc_gcp.prose.06.test.ts` that mimics the behaviour that
@@ -748,7 +812,7 @@ We tests TLS in two suites in CI:
748812
749813
Setting up a local environment is the same for both suites.
750814
751-
First, configure a server with TLS enabled by following the steps in [Runing the Tests Locally](#Running-the-Tests-Locally) with the environment
815+
First, configure a server with TLS enabled by following the steps in [Runing the Tests Locally](#Running-the-Tests-Locally) with the environment
752816
variable `SSL=SSL` set.
753817
754818
Then, in addition to setting the `MONGODB_URI` environment varialbe, set the following environment variables:

0 commit comments

Comments
 (0)