diff --git a/.gitignore b/.gitignore index 636851962a..0f1ebaedec 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,9 @@ manual_tests/ docs/build docs/Makefile +mo-expansion.sh +utr/ + # xunit test output for CI xunit.xml diff --git a/package.json b/package.json index 7011dbed03..0dd6d9cfb2 100644 --- a/package.json +++ b/package.json @@ -155,6 +155,7 @@ "check:socks5": "mocha --config test/manual/mocharc.json test/manual/socks5.test.ts", "check:csfle": "mocha --config test/mocha_mongodb.json test/integration/client-side-encryption", "check:snappy": "mocha test/unit/assorted/snappy.test.js", + "check:utr": "deno test --allow-all utr_test.ts", "fix:eslint": "npm run check:eslint -- --fix", "prepare": "node etc/prepare.js", "preview:docs": "ts-node etc/docs/preview.ts", diff --git a/src/cmap/handshake/client_metadata.ts b/src/cmap/handshake/client_metadata.ts index fb1ba40b14..72128968bf 100644 --- a/src/cmap/handshake/client_metadata.ts +++ b/src/cmap/handshake/client_metadata.ts @@ -5,8 +5,7 @@ import { BSON, Int32 } from '../../bson'; import { MongoInvalidArgumentError } from '../../error'; import type { MongoOptions } from '../../mongo_client'; -// eslint-disable-next-line @typescript-eslint/no-var-requires -const NODE_DRIVER_VERSION = require('../../../package.json').version; +const NODE_DRIVER_VERSION = 'BROKEN IN DENO'; /** * @public diff --git a/test/tools/unified-spec-runner/runner.ts b/test/tools/unified-spec-runner/runner.ts index a2c02213c6..3dfa5be855 100644 --- a/test/tools/unified-spec-runner/runner.ts +++ b/test/tools/unified-spec-runner/runner.ts @@ -39,7 +39,7 @@ async function terminateOpenTransactions(client: MongoClient) { * @param skipFilter - a function that returns null if the test should be run, * or a skip reason if the test should be skipped */ -async function runUnifiedTest( +export async function runUnifiedTest( ctx: Mocha.Context, unifiedSuite: uni.UnifiedSuite, test: uni.Test, diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 0000000000..ee7981b305 --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,49 @@ +{ + "compilerOptions": { + "allowJs": true, + "checkJs": false, + "strict": false, + "alwaysStrict": true, + "target": "ES2021", + "module": "commonJS", + "moduleResolution": "node", + "skipLibCheck": true, + "lib": [ + "es2021", + "ES2022.Error" + ], + // We don't make use of tslib helpers, all syntax used is supported by target engine + "importHelpers": false, + "noEmitHelpers": false, + // Never emit error filled code + "noEmitOnError": false, + "outDir": "utr", + // We want the sourcemaps in a separate file + "inlineSourceMap": true, + "sourceMap": false, + // API-Extractor uses declaration maps to report problems in source, no need to distribute + "declaration": false, + "declarationMap": false, + // we include sources in the release + "inlineSources": false, + // Prevents web types from being suggested by vscode. + "types": [ + "node", + "mocha" + ], + "forceConsistentCasingInFileNames": true, + "noImplicitOverride": true, + "noImplicitReturns": false, + // TODO(NODE-3659): Enable useUnknownInCatchVariables and add type assertions or remove unnecessary catch blocks + "useUnknownInCatchVariables": false + }, + "ts-node": { + "transpileOnly": true, + "compiler": "typescript-cached-transpile" + }, + "include": [ + "./global.d.ts", + "test/tools/unified-spec-runner/*", + "test/tools/runner/config.ts" + ] +} diff --git a/utr_test.ts b/utr_test.ts new file mode 100644 index 0000000000..fc1bbab758 --- /dev/null +++ b/utr_test.ts @@ -0,0 +1,76 @@ +import fs from 'node:fs'; +import { createRequire } from 'node:module'; +import path from 'node:path'; + +const require = createRequire(import.meta.url); + +const BSON = require('bson'); +const utr = require('./utr/test/tools/unified-spec-runner/runner'); +const { TestConfiguration } = require('./utr/test/tools/runner/config'); +const { MongoClient } = require('./utr/src/index'); + +function load(specPath: string) { + console.log('specPath', specPath); + const suites = fs + .readdirSync(specPath) + .filter(x => x.includes('.json')) + .map(x => ({ + ...BSON.EJSON.parse(fs.readFileSync(path.join(specPath, x)), { relaxed: true }), + name: path.basename(x, '.json') + })); + + return suites; +} +const specTests = [ + ...load(path.join('test', 'spec', 'crud', 'unified')), + ...load(path.join('test', 'spec', 'transactions', 'unified')), + ...load(path.join('test', 'spec', 'retryable-reads', 'unified')), + ...load(path.join('test', 'spec', 'retryable-writes', 'unified')), + ...load(path.join('test', 'spec', 'change-streams', 'unified')), + ...load(path.join('test', 'spec', 'change-streams', 'unified')) +]; + +const context: Record = {}; + +const client = new MongoClient(Deno.env.get('MONGODB_URI')); + +context.parameters = await client + .db() + .admin() + .command({ getParameter: '*' }) + .catch((error: any) => ({ noReply: error })); + +const result = await client.db('admin').command({ buildInfo: true }); +context.version = result.versionArray.slice(0, 3).join('.'); +context.buildInfo = result; + +context.topologyType = client.topology.description.type; + +for (const unifiedSuite of specTests) { + for (const [index, test] of unifiedSuite.tests.entries()) { + Deno.test( + String(test.description === '' ? `Test ${index}` : test.description), + async function () { + await utr + .runUnifiedTest( + { + configuration: new TestConfiguration(Deno.env.get('MONGODB_URI'), context), + test: {}, + currentTest: undefined, + skip: () => { + throw new (class Skip extends Error { + skip = true; + })('skipped'); + } + }, + unifiedSuite, + test + ) + .catch((error: any) => { + if (error.skip) return; + throw error; + }); + } + ); + } +}