Skip to content

Commit a4cba4c

Browse files
feat(NODE-7335): Create dedicated mocha runner with isolated vm context (#4876)
1 parent 4c89408 commit a4cba4c

38 files changed

+1710
-228
lines changed

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"root": true,
33
"parser": "@typescript-eslint/parser",
4+
"ignorePatterns": [
5+
"test/tools/runner/bundle/**"
6+
],
47
"parserOptions": {
58
"ecmaVersion": 2023
69
},

.evergreen/config.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,3 +4027,55 @@ buildvariants:
40274027
run_on: rhel80-large
40284028
tasks:
40294029
- .ssl
4030+
- name: rhel8-nodeless
4031+
display_name: Nodeless
4032+
run_on: rhel80-large
4033+
tasks:
4034+
- test-latest-server
4035+
- test-latest-replica_set
4036+
- test-latest-sharded_cluster
4037+
- test-rapid-server
4038+
- test-rapid-replica_set
4039+
- test-rapid-sharded_cluster
4040+
- test-latest-server-v1-api
4041+
- test-x509-authentication
4042+
- test-atlas-connectivity
4043+
- test-rapid-load-balanced
4044+
- test-latest-load-balanced
4045+
- test-auth-kerberos
4046+
- test-auth-ldap
4047+
- test-socks5-csfle
4048+
- test-socks5-tls
4049+
- test-snappy-compression
4050+
- test-zstd-compression
4051+
- test-tls-support-latest
4052+
expansions:
4053+
NODE_LTS_VERSION: 24
4054+
CLIENT_ENCRYPTION: true
4055+
MONGODB_BUNDLED: true
4056+
- name: windows-nodeless
4057+
display_name: Windows Nodeless
4058+
run_on: windows-2022-latest-large
4059+
tasks:
4060+
- test-latest-server
4061+
- test-latest-replica_set
4062+
- test-latest-sharded_cluster
4063+
- test-rapid-server
4064+
- test-rapid-replica_set
4065+
- test-rapid-sharded_cluster
4066+
- test-latest-server-v1-api
4067+
- test-x509-authentication
4068+
- test-atlas-connectivity
4069+
- test-rapid-load-balanced
4070+
- test-latest-load-balanced
4071+
- test-auth-kerberos
4072+
- test-auth-ldap
4073+
- test-socks5-csfle
4074+
- test-socks5-tls
4075+
- test-snappy-compression
4076+
- test-zstd-compression
4077+
- test-tls-support-latest
4078+
expansions:
4079+
NODE_LTS_VERSION: 24
4080+
CLIENT_ENCRYPTION: true
4081+
MONGODB_BUNDLED: true

.evergreen/generate_evergreen_tasks.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,47 @@ BUILD_VARIANTS.push({
812812
tasks: ['.ssl']
813813
});
814814

815+
// small subset of tests to run on nodeless environments
816+
const nodelessTasks = [
817+
'test-latest-server',
818+
'test-latest-replica_set',
819+
'test-latest-sharded_cluster',
820+
'test-rapid-server',
821+
'test-rapid-replica_set',
822+
'test-rapid-sharded_cluster',
823+
'test-latest-server-v1-api',
824+
'test-x509-authentication',
825+
'test-atlas-connectivity',
826+
'test-rapid-load-balanced',
827+
'test-latest-load-balanced',
828+
'test-auth-kerberos',
829+
'test-auth-ldap',
830+
'test-socks5-csfle',
831+
'test-socks5-tls',
832+
'test-snappy-compression',
833+
'test-zstd-compression',
834+
'test-tls-support-latest'
835+
];
836+
const nodelessExpansions = {
837+
NODE_LTS_VERSION: LATEST_LTS,
838+
CLIENT_ENCRYPTION: true,
839+
MONGODB_BUNDLED: true
840+
};
841+
BUILD_VARIANTS.push({
842+
name: 'rhel8-nodeless',
843+
display_name: 'Nodeless',
844+
run_on: DEFAULT_OS,
845+
tasks: nodelessTasks,
846+
expansions: nodelessExpansions
847+
});
848+
BUILD_VARIANTS.push({
849+
name: 'windows-nodeless',
850+
display_name: 'Windows Nodeless',
851+
run_on: WINDOWS_OS,
852+
tasks: nodelessTasks,
853+
expansions: nodelessExpansions
854+
});
855+
815856
// TODO(NODE-4897): Debug socks5 tests on node latest
816857
for (const variant of BUILD_VARIANTS.filter(
817858
variant => variant.expansions && ['latest'].includes(variant.expansions.NODE_LTS_VERSION)

.evergreen/run-azure-kms-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ export MONGODB_URI="mongodb://localhost:27017"
1818
export EXPECTED_AZUREKMS_OUTCOME=${EXPECTED_AZUREKMS_OUTCOME:-omitted}
1919
export TEST_CSFLE=true
2020

21+
npm run build:bundle
22+
2123
npx mocha --config test/mocha_mongodb.js test/integration/client-side-encryption/client_side_encryption.prose.19.on_demand_azure.test.ts

.evergreen/run-gcp-kms-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ export MONGODB_URI="mongodb://localhost:27017"
2020
export EXPECTED_GCPKMS_OUTCOME=${EXPECTED_GCPKMS_OUTCOME:-omitted}
2121
export TEST_CSFLE=true
2222

23+
npm run build:bundle
24+
2325
npx mocha --config test/mocha_mongodb.js test/integration/client-side-encryption/client_side_encryption.prose.17.on_demand_gcp.test.ts

.evergreen/run-mongosh-scope-test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ export SCOPES=$(./node_modules/lerna/cli.js ls --all --json)
1313

1414
cd -
1515

16+
npm run build:bundle
17+
1618
npx mocha --config test/manual/mocharc.json test/manual/mongosh_scopes.test.ts

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,5 @@ uri.txt
108108
crypt_shared.sh
109109

110110
*keytab
111+
driver.bundle.js
112+
test/tools/runner/bundle/

etc/build-runtime-barrel.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import fs from 'node:fs/promises';
2+
import path from 'node:path';
3+
4+
// eslint-disable-next-line no-restricted-globals
5+
const useBundled = process.env.MONGODB_BUNDLED === 'true';
6+
7+
const rootDir = path.join(import.meta.dirname, '..');
8+
const outputBarrelFile = path.join(rootDir, 'test/mongodb.ts');
9+
const source = useBundled ? './mongodb_bundled' : './mongodb_all';
10+
11+
const contents =
12+
`// This file is auto-generated. Do not edit.\n` +
13+
`// Run 'npm run build:runtime-barrel' to regenerate.\n` +
14+
`export const runNodelessTests = ${useBundled};\n` +
15+
`export * from '${source}';\n`;
16+
await fs.writeFile(outputBarrelFile, contents);
17+
18+
// eslint-disable-next-line no-console
19+
console.log(`✓ ${outputBarrelFile} now re-exports from ${source}`);

etc/bundle-driver.mjs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env node
2+
import fs from 'node:fs/promises';
3+
import { isBuiltin } from 'node:module';
4+
import path from 'node:path';
5+
import { fileURLToPath } from 'node:url';
6+
7+
import * as esbuild from 'esbuild';
8+
9+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
10+
const rootDir = path.join(__dirname, '..');
11+
12+
const outdir = path.join(rootDir, 'test/tools/runner/bundle/');
13+
await fs.rm(outdir, { recursive: true, force: true });
14+
15+
const outputBundleFile = path.join(outdir, 'driver-bundle.js');
16+
await esbuild.build({
17+
entryPoints: [path.join(rootDir, 'test/mongodb_all.ts')],
18+
bundle: true,
19+
outfile: outputBundleFile,
20+
platform: 'node',
21+
format: 'cjs',
22+
target: 'node20',
23+
external: [
24+
'@aws-sdk/credential-providers',
25+
'@mongodb-js/saslprep',
26+
'@mongodb-js/zstd',
27+
'@napi-rs/snappy*',
28+
'bson',
29+
'gcp-metadata',
30+
'kerberos',
31+
'mongodb-client-encryption',
32+
'mongodb-connection-string-url',
33+
'snappy',
34+
'socks'
35+
],
36+
plugins: [
37+
{
38+
name: 'externalize-node-builtins',
39+
setup(build) {
40+
build.onResolve({ filter: /.*/ }, args => {
41+
if (isBuiltin(args.path)) {
42+
return { path: args.path, external: true };
43+
}
44+
});
45+
}
46+
}
47+
],
48+
sourcemap: 'inline',
49+
logLevel: 'info'
50+
});
51+
52+
// eslint-disable-next-line no-console
53+
console.log(`✓ Driver bundle created at ${outputBundleFile}`);

0 commit comments

Comments
 (0)