diff --git a/.evergreen.yml b/.evergreen.yml index 4cfce45453..68dfb79922 100644 --- a/.evergreen.yml +++ b/.evergreen.yml @@ -4117,7 +4117,7 @@ functions: (cd scripts/docker && docker build --build-arg NODE_JS_VERSION="$NODE_VERSION" -t ubuntu24.04-xvfb -f ubuntu24.04-xvfb.Dockerfile .) docker run \ --rm -v $PWD:/tmp/build ubuntu24.04-xvfb \ - -c 'cd /tmp/build && ./testing/test-vscode.sh' + -c 'cd /tmp/build && ./scripts/test-vscode.sh' } test_connectivity: - command: expansions.write diff --git a/.evergreen/evergreen.yml.in b/.evergreen/evergreen.yml.in index 349318a047..dcb2467763 100644 --- a/.evergreen/evergreen.yml.in +++ b/.evergreen/evergreen.yml.in @@ -336,7 +336,7 @@ functions: (cd scripts/docker && docker build --build-arg NODE_JS_VERSION="$NODE_VERSION" -t ubuntu24.04-xvfb -f ubuntu24.04-xvfb.Dockerfile .) docker run \ --rm -v $PWD:/tmp/build ubuntu24.04-xvfb \ - -c 'cd /tmp/build && ./testing/test-vscode.sh' + -c 'cd /tmp/build && ./scripts/test-vscode.sh' } test_connectivity: - command: expansions.write diff --git a/.evergreen/setup-env.sh b/.evergreen/setup-env.sh index c3c241ba09..1c6cee690a 100755 --- a/.evergreen/setup-env.sh +++ b/.evergreen/setup-env.sh @@ -6,7 +6,7 @@ OS_ARCH="$(uname "-m")" export BASEDIR="$PWD/.evergreen" export PATH="$BASEDIR/npm-10/node_modules/.bin:$BASEDIR/node-v$NODE_JS_VERSION-win-x64:/opt/java/jdk16/bin:$PATH" -export MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING="$BASEDIR/../../testing/tests-globalconfig.conf" +export MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING="$BASEDIR/../../packages/testing/tests-globalconfig.conf" export IS_MONGOSH_EVERGREEN_CI=1 export DEBUG="mongodb*,$DEBUG" diff --git a/.nycrc b/.nycrc index 6eeae76686..204b9ee857 100644 --- a/.nycrc +++ b/.nycrc @@ -1,12 +1,8 @@ { - "include": [ - "packages/*/src/**", - "scripts/*/src/**", - "configs/*/src/**" - ], + "include": ["packages/*/src/**", "scripts/*/src/**", "configs/*/src/**"], "exclude": [ "test", - "testing", + "packages/testing", "config", "**/*.d.ts", "**/*.spec.{ts,js,tsx,jsx,cjs,mjs}", diff --git a/mongosh.code-workspace b/mongosh.code-workspace new file mode 100644 index 0000000000..293d695fd8 --- /dev/null +++ b/mongosh.code-workspace @@ -0,0 +1,127 @@ +{ + "folders": [ + { + "name": "mongosh", + "path": "." + }, + { + "name": "📦 @mongosh/arg-parser", + "path": "packages/arg-parser" + }, + { + "name": "📦 @mongosh/async-rewriter2", + "path": "packages/async-rewriter2" + }, + { + "name": "📦 @mongosh/autocomplete", + "path": "packages/autocomplete" + }, + // { + // "name": "📦 @mongosh/browser-repl", + // "path": "packages/browser-repl" + // }, + { + "name": "📦 @mongosh/browser-runtime-core", + "path": "packages/browser-runtime-core" + }, + { + "name": "📦 @mongosh/browser-runtime-electron", + "path": "packages/browser-runtime-electron" + }, + { + "name": "📦 @mongosh/build", + "path": "packages/build" + }, + { + "name": "📦 @mongosh/cli-repl", + "path": "packages/cli-repl" + }, + { + "name": "📦 @mongosh/connectivity-tests", + "path": "packages/connectivity-tests" + }, + { + "name": "📦 @mongosh/e2e-tests", + "path": "packages/e2e-tests" + }, + { + "name": "📦 @mongosh/editor", + "path": "packages/editor" + }, + { + "name": "📦 @mongosh/errors", + "path": "packages/errors" + }, + { + "name": "📦 @mongosh/history", + "path": "packages/history" + }, + { + "name": "📦 @mongosh/i18n", + "path": "packages/i18n" + }, + { + "name": "📦 @mongosh/java-shell", + "path": "packages/java-shell" + }, + { + "name": "📦 @mongosh/js-multiline-to-singleline", + "path": "packages/js-multiline-to-singleline" + }, + { + "name": "📦 @mongosh/logging", + "path": "packages/logging" + }, + { + "name": "📦 @mongosh/node-runtime-worker-thread", + "path": "packages/node-runtime-worker-thread" + }, + { + "name": "📦 @mongosh/service-provider-core", + "path": "packages/service-provider-core" + }, + { + "name": "📦 @mongosh/service-provider-node-driver", + "path": "packages/service-provider-node-driver" + }, + { + "name": "📦 @mongosh/shell-api", + "path": "packages/shell-api" + }, + { + "name": "📦 @mongosh/shell-bson", + "path": "packages/shell-bson" + }, + { + "name": "📦 @mongosh/shell-evaluator", + "path": "packages/shell-evaluator" + }, + { + "name": "📦 @mongosh/snippet-manager", + "path": "packages/snippet-manager" + }, + { + "name": "📦 @mongosh/testing", + "path": "packages/testing" + }, + { + "name": "📦 @mongosh/types", + "path": "packages/types" + } + ], + "settings": { + "typescript.tsdk": "node_modules/typescript/lib", + "mochaExplorer.files": "./{src,lib}/**/*.spec.ts", + "mochaExplorer.require": [ + "../../scripts/import-expansions.js", + "ts-node/register" + ], + "mochaExplorer.timeout": 60000, + "mochaExplorer.ui": "bdd", + "mochaExplorer.esmLoader": false, + "mochaExplorer.monkeyPatch": true, + "mochaExplorer.autoload": true, + "testExplorer.codeLens": true, + "testExplorer.gutterDecoration": true + } +} diff --git a/package-lock.json b/package-lock.json index c1a943708c..6854d6527e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "packages/i18n", "packages/logging", "packages/shell-bson", + "packages/testing", "packages/arg-parser", "packages/service-provider-core", "packages/service-provider-node-driver", @@ -61,7 +62,7 @@ "husky": "^9.0.11", "mocha": "^10.2.0", "mongodb": "^6.19.0", - "mongodb-runner": "^6.0.0", + "mongodb-runner": "^6.2.0", "node-gyp": "^9.0.0 || ^10.2.0", "nyc": "^15.1.0", "pkg-up": "^3.1.0", @@ -7633,6 +7634,10 @@ "resolved": "packages/snippet-manager", "link": true }, + "node_modules/@mongosh/testing": { + "resolved": "packages/testing", + "link": true + }, "node_modules/@mongosh/types": { "resolved": "packages/types", "link": true @@ -13158,7 +13163,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", - "dev": true, "license": "MIT", "dependencies": { "event-target-shim": "^5.0.0" @@ -17513,7 +17517,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/duplexpair/-/duplexpair-1.0.2.tgz", "integrity": "sha512-6DHuWdEGHNcuSqrn926rWJcRsTDrb+ugw0hx/trAxCH48z9WlFqDtwtbiEMq/KGFYQWzLs1VA0I6KUkuIgCoXw==", - "dev": true, "license": "MIT", "dependencies": { "readable-stream": "^4.5.2" @@ -17523,7 +17526,6 @@ "version": "6.0.3", "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "dev": true, "funding": [ { "type": "github", @@ -17548,7 +17550,6 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.8.x" @@ -17558,7 +17559,6 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "dev": true, "funding": [ { "type": "github", @@ -17579,7 +17579,6 @@ "version": "4.5.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", - "dev": true, "license": "MIT", "dependencies": { "abort-controller": "^3.0.0", @@ -18702,7 +18701,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -26028,13 +26026,13 @@ "optional": true }, "node_modules/mongodb-runner": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/mongodb-runner/-/mongodb-runner-6.0.0.tgz", - "integrity": "sha512-ijhBVCcTWRlauxp4UdIuktfPjEqlt8yOo0u7XyE99HdaITzL0BjS4x/dOyNzddewC6gw5wxH1uYx+Uo7GfeUnw==", - "dev": true, + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/mongodb-runner/-/mongodb-runner-6.2.0.tgz", + "integrity": "sha512-3RCYNGUJIHkwxmhyfQdY7gp6KqbyqEb2lNw3ZV36XaJFU07bYb9b497ba2YuH3evdNonbqXCUf+yxdAUWNPojg==", "license": "Apache-2.0", "dependencies": { "@mongodb-js/mongodb-downloader": "^1.0.0", + "@mongodb-js/oidc-mock-provider": "^0.12.0", "@mongodb-js/saslprep": "^1.3.2", "debug": "^4.4.0", "mongodb": "^6.9.0", @@ -26049,7 +26047,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-downloader/-/mongodb-downloader-1.0.0.tgz", "integrity": "sha512-xz4zr/5RWfAaHp9Kf7XPaLNxKaisl2NJGFEDQRNjB/ru79LdpLQbbSjQazTOl6JLcBvAjNNvauTeTwmgEvSUlA==", - "dev": true, "license": "Apache-2.0", "dependencies": { "debug": "^4.4.0", @@ -26060,11 +26057,22 @@ "tar": "^6.1.15" } }, + "node_modules/mongodb-runner/node_modules/@mongodb-js/oidc-mock-provider": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@mongodb-js/oidc-mock-provider/-/oidc-mock-provider-0.12.0.tgz", + "integrity": "sha512-OBGqTQ25CJpNhvSy5gYNcTSi+cOExeGliAcuObXX6AswhpW7gt62go9md0jYAs10MPKTPFOvK+RrXX4WIkr/nA==", + "license": "Apache-2.0", + "dependencies": { + "yargs": "^17.7.2" + }, + "bin": { + "oidc-mock-provider": "bin/oidc-mock-provider.js" + } + }, "node_modules/mongodb-runner/node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", - "dev": true, "license": "ISC", "dependencies": { "string-width": "^4.2.0", @@ -26079,7 +26087,6 @@ "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", - "dev": true, "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -26097,14 +26104,12 @@ "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true, "license": "MIT" }, "node_modules/mongodb-runner/node_modules/yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", - "dev": true, "license": "MIT", "dependencies": { "cliui": "^8.0.1", @@ -26123,7 +26128,6 @@ "version": "21.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", - "dev": true, "license": "ISC", "engines": { "node": ">=12" @@ -29112,7 +29116,6 @@ "version": "0.11.10", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.6.0" @@ -29245,7 +29248,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/proper-lockfile/-/proper-lockfile-4.1.2.tgz", "integrity": "sha512-TjNPblN4BwAWMXU8s9AEz4JmQxnD1NNL7bNOY/AKUzyamc379FWASUhc/K1pL2noVb+XmZKLL68cjzLsiOAMaA==", - "dev": true, "license": "MIT", "dependencies": { "graceful-fs": "^4.2.4", @@ -35771,6 +35773,7 @@ "@mongodb-js/prettier-config-devtools": "^1.0.1", "@mongodb-js/sbom-tools": "^0.8.1", "@mongodb-js/tsconfig-mongosh": "^1.0.0", + "@mongosh/testing": "0.0.0-dev.0", "@types/ansi-escape-sequences": "^4.0.0", "@types/chai-as-promised": "^7.1.3", "@types/js-yaml": "^4.0.5", @@ -35838,6 +35841,7 @@ "@mongodb-js/oidc-mock-provider": "^0.11.3", "@mongodb-js/prettier-config-devtools": "^1.0.1", "@mongodb-js/tsconfig-mongosh": "^1.0.0", + "@mongosh/testing": "0.0.0-dev.0", "@types/chai-as-promised": "^7.1.3", "@types/node": "^22.15.30", "@types/rimraf": "^3.0.0", @@ -36238,6 +36242,7 @@ "@mongosh/browser-runtime-electron": "^3.26.2", "@mongosh/service-provider-core": "3.6.3", "@mongosh/service-provider-node-driver": "^3.17.5", + "@mongosh/testing": "0.0.0-dev.0", "@mongosh/types": "^3.14.0", "bson": "^6.10.4", "depcheck": "^1.4.7", @@ -36295,6 +36300,7 @@ "@mongodb-js/eslint-config-mongosh": "^1.0.0", "@mongodb-js/prettier-config-devtools": "^1.0.1", "@mongodb-js/tsconfig-mongosh": "^1.0.0", + "@mongosh/testing": "0.0.0-dev.0", "@types/sinon-chai": "^3.2.4", "depcheck": "^1.4.7", "eslint": "^7.25.0", @@ -36330,6 +36336,7 @@ "@mongodb-js/mongodb-ts-autocomplete": "^0.4.7", "@mongodb-js/prettier-config-devtools": "^1.0.1", "@mongodb-js/tsconfig-mongosh": "^1.0.0", + "@mongosh/testing": "0.0.0-dev.0", "@mongosh/types": "^3.14.0", "bson": "^6.10.4", "depcheck": "^1.4.7", @@ -36413,6 +36420,7 @@ "@mongodb-js/eslint-config-mongosh": "^1.0.0", "@mongodb-js/prettier-config-devtools": "^1.0.1", "@mongodb-js/tsconfig-mongosh": "^1.0.0", + "@mongosh/testing": "0.0.0-dev.0", "@types/cross-spawn": "^6.0.6", "@types/tar": "^4.0.4", "depcheck": "^1.4.7", @@ -36434,6 +36442,33 @@ "@types/node": "*" } }, + "packages/testing": { + "name": "@mongosh/testing", + "version": "0.0.0-dev.0", + "license": "Apache-2.0", + "dependencies": { + "@mongosh/build": "3.7.8", + "duplexpair": "^1.0.2", + "mongodb": "^6.19.0", + "mongodb-connection-string-url": "^3.0.1", + "mongodb-runner": "^6.2.0", + "semver": "^7.3.4", + "which": "^2.0.2" + }, + "devDependencies": { + "@mongodb-js/eslint-config-mongosh": "^1.0.0", + "@mongodb-js/prettier-config-devtools": "^1.0.1", + "@mongodb-js/tsconfig-mongosh": "^1.0.0", + "@types/semver": "^7.3.4", + "@types/which": "^1.3.2", + "eslint": "^7.25.0", + "prettier": "^2.8.8", + "typescript": "^5.3.3" + }, + "engines": { + "node": ">=14.15.1" + } + }, "packages/types": { "name": "@mongosh/types", "version": "3.14.0", @@ -36464,6 +36499,34 @@ "engines": { "node": ">=12.4.0" } + }, + "testing": { + "name": "@mongosh/testing", + "version": "0.0.0-dev.0", + "extraneous": true, + "license": "Apache-2.0", + "dependencies": { + "@mongosh/build": "3.7.8", + "duplexpair": "^1.0.2", + "mongodb": "^6.19.0", + "mongodb-connection-string-url": "^3.0.1", + "mongodb-runner": "^6.0.0", + "semver": "^7.3.4", + "which": "^2.0.2" + }, + "devDependencies": { + "@mongodb-js/eslint-config-mongosh": "^1.0.0", + "@mongodb-js/prettier-config-devtools": "^1.0.1", + "@mongodb-js/tsconfig-mongosh": "^1.0.0", + "@types/semver": "^7.3.4", + "@types/which": "^1.3.2", + "eslint": "^7.25.0", + "prettier": "^2.8.8", + "typescript": "^5.3.3" + }, + "engines": { + "node": ">=14.15.1" + } } } } diff --git a/package.json b/package.json index a7b666ea7d..0d9c315e9a 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,7 @@ "husky": "^9.0.11", "mocha": "^10.2.0", "mongodb": "^6.19.0", - "mongodb-runner": "^6.0.0", + "mongodb-runner": "^6.2.0", "node-gyp": "^9.0.0 || ^10.2.0", "nyc": "^15.1.0", "pkg-up": "^3.1.0", @@ -153,6 +153,7 @@ "packages/i18n", "packages/logging", "packages/shell-bson", + "packages/testing", "packages/arg-parser", "packages/service-provider-core", "packages/service-provider-node-driver", diff --git a/packages/cli-repl/package.json b/packages/cli-repl/package.json index 2bad45ae67..55e8b220f4 100644 --- a/packages/cli-repl/package.json +++ b/packages/cli-repl/package.json @@ -113,7 +113,8 @@ "eslint": "^7.25.0", "mongodb-crypt-library-dummy": "^1.0.2", "prettier": "^2.8.8", - "webpack-merge": "^5.8.0" + "webpack-merge": "^5.8.0", + "@mongosh/testing": "0.0.0-dev.0" }, "optionalDependencies": { "get-console-process-list": "^1.0.5", diff --git a/packages/cli-repl/src/cli-repl.spec.ts b/packages/cli-repl/src/cli-repl.spec.ts index 71321df7b9..0076fb0d00 100644 --- a/packages/cli-repl/src/cli-repl.spec.ts +++ b/packages/cli-repl/src/cli-repl.spec.ts @@ -8,13 +8,13 @@ import path from 'path'; import type { Duplex } from 'stream'; import { PassThrough } from 'stream'; import { promisify } from 'util'; -import { eventually } from '../../../testing/eventually'; -import type { MongodSetup } from '../../../testing/integration-testing-hooks'; import { + eventually, + type MongodSetup, skipIfServerVersion, startSharedTestServer, startTestServer, -} from '../../../testing/integration-testing-hooks'; +} from '@mongosh/testing'; import { expect, fakeTTYProps, diff --git a/packages/cli-repl/src/smoke-tests.spec.ts b/packages/cli-repl/src/smoke-tests.spec.ts index 68402b6251..08bc619b30 100644 --- a/packages/cli-repl/src/smoke-tests.spec.ts +++ b/packages/cli-repl/src/smoke-tests.spec.ts @@ -3,7 +3,7 @@ import path from 'path'; import { downloadCurrentCryptSharedLibrary, startSharedTestServer, -} from '../../../testing/integration-testing-hooks'; +} from '@mongosh/testing'; describe('smoke tests', function () { const testServer = startSharedTestServer(); diff --git a/testing/disable-dns-srv.js b/packages/connectivity-tests/scripts/disable-dns-srv.js similarity index 100% rename from testing/disable-dns-srv.js rename to packages/connectivity-tests/scripts/disable-dns-srv.js diff --git a/packages/connectivity-tests/test/atlas.sh b/packages/connectivity-tests/test/atlas.sh index 9a5387cfcc..d4f33ca1c4 100755 --- a/packages/connectivity-tests/test/atlas.sh +++ b/packages/connectivity-tests/test/atlas.sh @@ -136,7 +136,7 @@ function test_srv_without_nodejs_dns() { CONNECTION_STRING="mongodb+srv://${ATLAS_USERNAME}:${ATLAS_PASSWORD}@${ATLAS_HOSTNAME}/admin" - echo "${CONNECTION_STATUS_COMMAND}" | NODE_OPTIONS="-r ${MONGOSH_ROOT_DIR}/testing/disable-dns-srv.js" "${MONGOSH}" "${CONNECTION_STRING}" | + echo "${CONNECTION_STATUS_COMMAND}" | NODE_OPTIONS="-r ${MONGOSH_ROOT_DIR}/packages/connectivity-tests/scripts/disable-dns-srv.js" "${MONGOSH}" "${CONNECTION_STRING}" | grep -Fq "${CONNECTION_STATUS_CHECK_STRING}" || FAILED="Can't connect to Atlas using connection string without Node.js SRV/TXT DNS support" diff --git a/packages/e2e-tests/package.json b/packages/e2e-tests/package.json index 3ed31ae17c..b3b31d8719 100644 --- a/packages/e2e-tests/package.json +++ b/packages/e2e-tests/package.json @@ -50,6 +50,7 @@ "mongodb": "^6.19.0", "node-fetch": "^3.3.2", "prettier": "^2.8.8", - "rimraf": "^3.0.2" + "rimraf": "^3.0.2", + "@mongosh/testing": "0.0.0-dev.0" } } diff --git a/packages/e2e-tests/test/e2e-analytics.spec.ts b/packages/e2e-tests/test/e2e-analytics.spec.ts index e32bf15117..9ec901793b 100644 --- a/packages/e2e-tests/test/e2e-analytics.spec.ts +++ b/packages/e2e-tests/test/e2e-analytics.spec.ts @@ -1,6 +1,5 @@ import { expect } from 'chai'; -import { startTestCluster } from '../../../testing/integration-testing-hooks'; -import { eventually } from '../../../testing/eventually'; +import { startTestCluster, eventually } from '@mongosh/testing'; describe('e2e Analytics Node', function () { const replSetName = 'replicaSet'; diff --git a/packages/e2e-tests/test/e2e-auth.spec.ts b/packages/e2e-tests/test/e2e-auth.spec.ts index 12773ed134..1394c1849c 100644 --- a/packages/e2e-tests/test/e2e-auth.spec.ts +++ b/packages/e2e-tests/test/e2e-auth.spec.ts @@ -1,12 +1,12 @@ import { expect } from 'chai'; import type { Db, Document, MongoClientOptions } from 'mongodb'; import { MongoClient } from 'mongodb'; -import { eventually } from '../../../testing/eventually'; -import type { TestShell } from './test-shell'; import { + eventually, skipIfApiStrict, startSharedTestServer, -} from '../../../testing/integration-testing-hooks'; +} from '@mongosh/testing'; +import type { TestShell } from './test-shell'; type AssertUserExists = (opts?: Document, username?: string) => Promise; function createAssertUserExists(db: Db, dbName: string): AssertUserExists { diff --git a/packages/e2e-tests/test/e2e-banners.spec.ts b/packages/e2e-tests/test/e2e-banners.spec.ts index 14929f1bff..c9f6412e7c 100644 --- a/packages/e2e-tests/test/e2e-banners.spec.ts +++ b/packages/e2e-tests/test/e2e-banners.spec.ts @@ -1,7 +1,4 @@ -import { - skipIfApiStrict, - startSharedTestServer, -} from '../../../testing/integration-testing-hooks'; +import { skipIfApiStrict, startSharedTestServer } from '@mongosh/testing'; import type { TestShell } from './test-shell'; describe('e2e startup banners', function () { diff --git a/packages/e2e-tests/test/e2e-bson.spec.ts b/packages/e2e-tests/test/e2e-bson.spec.ts index 2299bc4683..822b638c98 100644 --- a/packages/e2e-tests/test/e2e-bson.spec.ts +++ b/packages/e2e-tests/test/e2e-bson.spec.ts @@ -3,7 +3,7 @@ import type { Db } from 'mongodb'; import { MongoClient } from 'mongodb'; import * as bson from 'bson'; import type { TestShell } from './test-shell'; -import { startSharedTestServer } from '../../../testing/integration-testing-hooks'; +import { startSharedTestServer } from '@mongosh/testing'; describe('BSON e2e', function () { const testServer = startSharedTestServer(); diff --git a/packages/e2e-tests/test/e2e-direct.spec.ts b/packages/e2e-tests/test/e2e-direct.spec.ts index 46a0306607..c7d652dbf3 100644 --- a/packages/e2e-tests/test/e2e-direct.spec.ts +++ b/packages/e2e-tests/test/e2e-direct.spec.ts @@ -2,8 +2,8 @@ import { startTestCluster, skipIfServerVersion, skipIfApiStrict, -} from '../../../testing/integration-testing-hooks'; -import { eventually } from '../../../testing/eventually'; + eventually, +} from '@mongosh/testing'; import { expect } from 'chai'; import type { TestShell } from './test-shell'; diff --git a/packages/e2e-tests/test/e2e-editor.spec.ts b/packages/e2e-tests/test/e2e-editor.spec.ts index ac6abb2fb9..a11239bb7f 100644 --- a/packages/e2e-tests/test/e2e-editor.spec.ts +++ b/packages/e2e-tests/test/e2e-editor.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import path from 'path'; import { promises as fs } from 'fs'; -import { eventually } from '../../../testing/eventually'; +import { eventually } from '@mongosh/testing'; import { TestShell } from './test-shell'; import { ensureTestShellAfterHook } from './test-shell-context'; import { diff --git a/packages/e2e-tests/test/e2e-fle.spec.ts b/packages/e2e-tests/test/e2e-fle.spec.ts index ae86e55d3f..6666b7014d 100644 --- a/packages/e2e-tests/test/e2e-fle.spec.ts +++ b/packages/e2e-tests/test/e2e-fle.spec.ts @@ -1,16 +1,17 @@ import { expect } from 'chai'; import { MongoClient } from 'mongodb'; import type { TestShell } from './test-shell'; -import { eventually } from '../../../testing/eventually'; import { + eventually, startTestServer, skipIfApiStrict, skipIfServerVersion, skipIfCommunityServer, downloadCurrentCryptSharedLibrary, sortObjectArray, -} from '../../../testing/integration-testing-hooks'; -import { makeFakeHTTPServer, fakeAWSHandlers } from '../../../testing/fake-kms'; + makeFakeHTTPServer, + fakeAWSHandlers, +} from '@mongosh/testing'; import { once } from 'events'; import { serialize } from 'v8'; import { inspect } from 'util'; diff --git a/packages/e2e-tests/test/e2e-oidc.spec.ts b/packages/e2e-tests/test/e2e-oidc.spec.ts index 08935926ca..69b847abfd 100644 --- a/packages/e2e-tests/test/e2e-oidc.spec.ts +++ b/packages/e2e-tests/test/e2e-oidc.spec.ts @@ -2,7 +2,8 @@ import { MongoRunnerSetup, skipIfApiStrict, skipIfEnvServerVersion, -} from '../../../testing/integration-testing-hooks'; + getTestCertificatePath, +} from '@mongosh/testing'; import { promises as fs } from 'fs'; import type { OIDCMockProviderConfig } from '@mongodb-js/oidc-mock-provider'; import { OIDCMockProvider } from '@mongodb-js/oidc-mock-provider'; @@ -10,7 +11,7 @@ import type { TestShell } from './test-shell'; import path from 'path'; import { expect } from 'chai'; import { createServer as createHTTPSServer } from 'https'; -import { getCertPath, readReplLogFile, useTmpdir } from './repl-helpers'; +import { readReplLogFile, useTmpdir } from './repl-helpers'; import { baseOidcServerConfig, commonOidcServerArgs, @@ -67,7 +68,7 @@ describe('OIDC auth e2e', function () { }, }; const httpsServerKeyCertBundle = await fs.readFile( - getCertPath('server.bundle.pem') + getTestCertificatePath('server.bundle.pem') ); [oidcMockProvider, oidcMockProviderHttps] = await Promise.all([ OIDCMockProvider.create(oidcMockProviderConfig), @@ -411,7 +412,7 @@ describe('OIDC auth e2e', function () { it('can specify --tlsUseSystemCA as a no-op', async function () { await fs.mkdir(path.join(tmpdir.path, 'certs'), { recursive: true }); await fs.copyFile( - getCertPath('ca.crt'), + getTestCertificatePath('ca.crt'), path.join(tmpdir.path, 'certs', 'somefilename.crt') ); @@ -441,7 +442,7 @@ describe('OIDC auth e2e', function () { it('uses system ca by default when calling the IdP https endpoint', async function () { await fs.mkdir(path.join(tmpdir.path, 'certs'), { recursive: true }); await fs.copyFile( - getCertPath('ca.crt'), + getTestCertificatePath('ca.crt'), path.join(tmpdir.path, 'certs', 'somefilename.crt') ); diff --git a/packages/e2e-tests/test/e2e-proxy.spec.ts b/packages/e2e-tests/test/e2e-proxy.spec.ts index b9afc836d7..23910ca60f 100644 --- a/packages/e2e-tests/test/e2e-proxy.spec.ts +++ b/packages/e2e-tests/test/e2e-proxy.spec.ts @@ -10,14 +10,11 @@ import { skipIfEnvServerVersion, startSharedTestServer, startTestServer, -} from '../../../testing/integration-testing-hooks'; + getTestCertificatePath, +} from '@mongosh/testing'; import type { Server as HTTPSServer } from 'https'; import { createServer as createHTTPSServer } from 'https'; -import { - connectionStringWithLocalhost, - getCertPath, - useTmpdir, -} from './repl-helpers'; +import { connectionStringWithLocalhost, useTmpdir } from './repl-helpers'; import { once } from 'events'; import { connect } from 'net'; import type { AddressInfo, Socket } from 'net'; @@ -32,8 +29,8 @@ import { skipOIDCTestsDueToPlatformOrServerVersion, } from './oidc-helpers'; -const CA_CERT = getCertPath('ca.crt'); -const SERVER_BUNDLE = getCertPath('server.bundle.pem'); +const CA_CERT = getTestCertificatePath('ca.crt'); +const SERVER_BUNDLE = getTestCertificatePath('server.bundle.pem'); describe('e2e proxy support', function () { skipIfApiStrict(); diff --git a/packages/e2e-tests/test/e2e-snapshot.spec.ts b/packages/e2e-tests/test/e2e-snapshot.spec.ts index fb57cc798c..201fa26a97 100644 --- a/packages/e2e-tests/test/e2e-snapshot.spec.ts +++ b/packages/e2e-tests/test/e2e-snapshot.spec.ts @@ -1,7 +1,4 @@ -import { - skipIfApiStrict, - startSharedTestServer, -} from '../../../testing/integration-testing-hooks'; +import { skipIfApiStrict, startSharedTestServer } from '@mongosh/testing'; import { expect } from 'chai'; const setDifference = (a: T[], b: T[]) => a.filter((e) => !b.includes(e)); diff --git a/packages/e2e-tests/test/e2e-snippet.spec.ts b/packages/e2e-tests/test/e2e-snippet.spec.ts index bf4a843073..58a7427568 100644 --- a/packages/e2e-tests/test/e2e-snippet.spec.ts +++ b/packages/e2e-tests/test/e2e-snippet.spec.ts @@ -3,7 +3,7 @@ import path from 'path'; import { expect } from 'chai'; import type { TestShell } from './test-shell'; import { useTmpdir } from './repl-helpers'; -import { eventually } from '../../../testing/eventually'; +import { eventually } from '@mongosh/testing'; describe('snippet integration tests', function () { this.timeout(120_000); diff --git a/packages/e2e-tests/test/e2e-streams.spec.ts b/packages/e2e-tests/test/e2e-streams.spec.ts index 9f6efd8dbb..1ec70cb269 100644 --- a/packages/e2e-tests/test/e2e-streams.spec.ts +++ b/packages/e2e-tests/test/e2e-streams.spec.ts @@ -4,7 +4,7 @@ import { MongoClient } from 'mongodb'; import { expect } from 'chai'; import type { TestShell } from './test-shell'; import { sleep } from './util-helpers'; -import { eventually } from '../../../testing/eventually'; +import { eventually } from '@mongosh/testing'; const { STREAMS_E2E_SPI_CONNECTION_STRING = '', diff --git a/packages/e2e-tests/test/e2e-tls.spec.ts b/packages/e2e-tests/test/e2e-tls.spec.ts index da68f80cc0..6d763f3b4f 100644 --- a/packages/e2e-tests/test/e2e-tls.spec.ts +++ b/packages/e2e-tests/test/e2e-tls.spec.ts @@ -1,27 +1,32 @@ import { expect } from 'chai'; import { promises as fs } from 'fs'; import path from 'path'; -import { startTestServer } from '../../../testing/integration-testing-hooks'; +import { startTestServer, getTestCertificatePath } from '@mongosh/testing'; import { useTmpdir, setTemporaryHomeDirectory, readReplLogFile, - getCertPath, connectionStringWithLocalhost, } from './repl-helpers'; -const CA_CERT = getCertPath('ca.crt'); -const NON_CA_CERT = getCertPath('non-ca.crt'); -const CLIENT_CERT = getCertPath('client.bundle.pem'); -const CLIENT_CERT_PFX = getCertPath('client.bundle.pfx'); -const CLIENT_CERT_ENCRYPTED = getCertPath('client.bundle.encrypted.pem'); +const CA_CERT = getTestCertificatePath('ca.crt'); +const NON_CA_CERT = getTestCertificatePath('non-ca.crt'); +const CLIENT_CERT = getTestCertificatePath('client.bundle.pem'); +const CLIENT_CERT_PFX = getTestCertificatePath('client.bundle.pfx'); +const CLIENT_CERT_ENCRYPTED = getTestCertificatePath( + 'client.bundle.encrypted.pem' +); const CLIENT_CERT_PASSWORD = 'p4ssw0rd'; -const INVALID_CLIENT_CERT = getCertPath('invalid-client.bundle.pem'); -const SERVER_KEY = getCertPath('server.bundle.pem'); -const SERVER_INVALIDHOST_KEY = getCertPath('server-invalidhost.bundle.pem'); -const CRL_INCLUDING_SERVER = getCertPath('ca-server.crl'); -const PARTIAL_TRUST_CHAIN_CA = getCertPath('partial-trust-chain/ca.pem'); -const PARTIAL_TRUST_CHAIN_KEY_AND_CERT = getCertPath( +const INVALID_CLIENT_CERT = getTestCertificatePath('invalid-client.bundle.pem'); +const SERVER_KEY = getTestCertificatePath('server.bundle.pem'); +const SERVER_INVALIDHOST_KEY = getTestCertificatePath( + 'server-invalidhost.bundle.pem' +); +const CRL_INCLUDING_SERVER = getTestCertificatePath('ca-server.crl'); +const PARTIAL_TRUST_CHAIN_CA = getTestCertificatePath( + 'partial-trust-chain/ca.pem' +); +const PARTIAL_TRUST_CHAIN_KEY_AND_CERT = getTestCertificatePath( 'partial-trust-chain/key-and-cert.pem' ); diff --git a/packages/e2e-tests/test/e2e.spec.ts b/packages/e2e-tests/test/e2e.spec.ts index c6029f2480..b83bb0a70b 100644 --- a/packages/e2e-tests/test/e2e.spec.ts +++ b/packages/e2e-tests/test/e2e.spec.ts @@ -3,13 +3,13 @@ import { expect } from 'chai'; import type { Db } from 'mongodb'; import { MongoClient, ObjectId } from 'mongodb'; -import { eventually } from '../../../testing/eventually'; -import { TestShell } from './test-shell'; -import { ensureTestShellAfterHook } from './test-shell-context'; import { + eventually, skipIfServerVersion, startSharedTestServer, -} from '../../../testing/integration-testing-hooks'; +} from '@mongosh/testing'; +import { TestShell } from './test-shell'; +import { ensureTestShellAfterHook } from './test-shell-context'; import { promises as fs, createReadStream } from 'fs'; import { promisify } from 'util'; import path from 'path'; diff --git a/packages/e2e-tests/test/repl-helpers.ts b/packages/e2e-tests/test/repl-helpers.ts index 46c67371d7..8c80cd9970 100644 --- a/packages/e2e-tests/test/repl-helpers.ts +++ b/packages/e2e-tests/test/repl-helpers.ts @@ -5,7 +5,7 @@ import rimraf from 'rimraf'; import chai from 'chai'; import sinonChai from 'sinon-chai'; import chaiAsPromised from 'chai-as-promised'; -import type { MongodSetup } from '../../../testing/integration-testing-hooks'; +import type { MongodSetup } from '@mongosh/testing'; import type { MongoLogEntry } from 'mongodb-log-writer'; chai.use(sinonChai); @@ -140,18 +140,6 @@ const setTemporaryHomeDirectory = () => { return { homedir, env }; }; -function getCertPath(filename: string): string { - return path.join( - __dirname, - '..', - '..', - '..', - 'testing', - 'certificates', - filename - ); -} - // TLS requires matching hostnames, so here we need to explicitly // specify `localhost` + IPv4 instead of `127.0.0.1` async function connectionStringWithLocalhost( @@ -174,7 +162,6 @@ export { readReplLogFile, fakeExternalEditor, setTemporaryHomeDirectory, - getCertPath, connectionStringWithLocalhost, MongoLogEntryFromFile, }; diff --git a/packages/e2e-tests/test/test-shell.ts b/packages/e2e-tests/test/test-shell.ts index f3a310ae2e..7613c5d713 100644 --- a/packages/e2e-tests/test/test-shell.ts +++ b/packages/e2e-tests/test/test-shell.ts @@ -9,7 +9,7 @@ import { inspect } from 'util'; import path from 'path'; import stripAnsi from 'strip-ansi'; import { EJSON } from 'bson'; -import { eventually } from '../../../testing/eventually'; +import { eventually } from '@mongosh/testing'; /* eslint-disable mocha/no-exports -- This file export hooks wrapping Mocha's Hooks APIs */ diff --git a/packages/java-shell/src/test/js/run-tests.ts b/packages/java-shell/src/test/js/run-tests.ts index ccbfa02a03..6de0f39278 100644 --- a/packages/java-shell/src/test/js/run-tests.ts +++ b/packages/java-shell/src/test/js/run-tests.ts @@ -1,7 +1,7 @@ import { spawn } from 'child_process'; import path from 'path'; import { once } from 'events'; -import { startSharedTestServer } from '../../../../../testing/integration-testing-hooks'; +import { startSharedTestServer } from '@mongosh/testing'; describe('java-shell tests', function() { this.timeout(1_000_000); diff --git a/packages/node-runtime-worker-thread/package.json b/packages/node-runtime-worker-thread/package.json index 35991756f5..8533f051e6 100644 --- a/packages/node-runtime-worker-thread/package.json +++ b/packages/node-runtime-worker-thread/package.json @@ -39,6 +39,7 @@ "@mongodb-js/eslint-config-mongosh": "^1.0.0", "@mongodb-js/prettier-config-devtools": "^1.0.1", "@mongodb-js/sbom-tools": "^0.8.1", + "@mongosh/testing": "0.0.0-dev.0", "@mongodb-js/tsconfig-mongosh": "^1.0.0", "@mongosh/browser-runtime-core": "^3.26.2", "@mongosh/browser-runtime-electron": "^3.26.2", diff --git a/packages/node-runtime-worker-thread/src/index.spec.ts b/packages/node-runtime-worker-thread/src/index.spec.ts index 88b626c03f..d4593f3e7f 100644 --- a/packages/node-runtime-worker-thread/src/index.spec.ts +++ b/packages/node-runtime-worker-thread/src/index.spec.ts @@ -2,7 +2,7 @@ import chai, { expect } from 'chai'; import sinon from 'sinon'; import sinonChai from 'sinon-chai'; import type { MongoshBus } from '@mongosh/types'; -import { startSharedTestServer } from '../../../testing/integration-testing-hooks'; +import { startSharedTestServer } from '@mongosh/testing'; import { WorkerRuntime } from '../dist/index'; import type { DevtoolsConnectOptions } from '@mongosh/service-provider-node-driver'; diff --git a/packages/node-runtime-worker-thread/src/worker-runtime.spec.ts b/packages/node-runtime-worker-thread/src/worker-runtime.spec.ts index 261a4fcff1..24df3a596e 100644 --- a/packages/node-runtime-worker-thread/src/worker-runtime.spec.ts +++ b/packages/node-runtime-worker-thread/src/worker-runtime.spec.ts @@ -5,7 +5,7 @@ import chai, { expect } from 'chai'; import sinonChai from 'sinon-chai'; import sinon from 'sinon'; import { EJSON, ObjectId } from 'bson'; -import { startSharedTestServer } from '../../../testing/integration-testing-hooks'; +import { startSharedTestServer } from '@mongosh/testing'; import type { Caller, Exposed } from './rpc'; import { cancel, close, createCaller, exposeAll } from './rpc'; import { deserializeEvaluationResult } from './serializer'; diff --git a/packages/service-provider-node-driver/package.json b/packages/service-provider-node-driver/package.json index 04d16118fd..63c3f29947 100644 --- a/packages/service-provider-node-driver/package.json +++ b/packages/service-provider-node-driver/package.json @@ -71,6 +71,7 @@ "@types/sinon-chai": "^3.2.4", "depcheck": "^1.4.7", "eslint": "^7.25.0", - "prettier": "^2.8.8" + "prettier": "^2.8.8", + "@mongosh/testing": "0.0.0-dev.0" } } diff --git a/packages/service-provider-node-driver/src/node-driver-provider.integration.spec.ts b/packages/service-provider-node-driver/src/node-driver-provider.integration.spec.ts index 327f776ef7..27925ec4b8 100644 --- a/packages/service-provider-node-driver/src/node-driver-provider.integration.spec.ts +++ b/packages/service-provider-node-driver/src/node-driver-provider.integration.spec.ts @@ -15,10 +15,7 @@ import type { InsertOneResult, UpdateResult, } from 'mongodb'; -import { - skipIfServerVersion, - startSharedTestServer, -} from '../../../testing/integration-testing-hooks'; +import { skipIfServerVersion, startSharedTestServer } from '@mongosh/testing'; import type { DbOptions, MongoClientOptions, diff --git a/packages/shell-api/package.json b/packages/shell-api/package.json index 87c787e028..56c2830a55 100644 --- a/packages/shell-api/package.json +++ b/packages/shell-api/package.json @@ -64,6 +64,7 @@ }, "devDependencies": { "@microsoft/api-extractor": "^7.39.3", + "@mongosh/testing": "0.0.0-dev.0", "@mongodb-js/eslint-config-mongosh": "^1.0.0", "@mongodb-js/mongodb-ts-autocomplete": "^0.4.7", "@mongodb-js/prettier-config-devtools": "^1.0.1", diff --git a/packages/shell-api/src/change-stream-cursor.spec.ts b/packages/shell-api/src/change-stream-cursor.spec.ts index 329ff9ec78..0a992da1eb 100644 --- a/packages/shell-api/src/change-stream-cursor.spec.ts +++ b/packages/shell-api/src/change-stream-cursor.spec.ts @@ -12,7 +12,7 @@ import { ALL_API_VERSIONS, } from './enums'; import type { ChangeStream, Document } from '@mongosh/service-provider-core'; -import { startTestCluster } from '../../../testing/integration-testing-hooks'; +import { startTestCluster } from '@mongosh/testing'; import { NodeDriverServiceProvider } from '../../service-provider-node-driver'; import ShellInstanceState from './shell-instance-state'; import Mongo from './mongo'; diff --git a/packages/shell-api/src/field-level-encryption.spec.ts b/packages/shell-api/src/field-level-encryption.spec.ts index f892dee6fd..33dee8d67b 100644 --- a/packages/shell-api/src/field-level-encryption.spec.ts +++ b/packages/shell-api/src/field-level-encryption.spec.ts @@ -11,7 +11,6 @@ import * as bson from 'bson'; import { expect } from 'chai'; import { EventEmitter } from 'events'; import { promises as fs } from 'fs'; -import path from 'path'; import { Duplex } from 'stream'; import sinon from 'sinon'; import type { StubbedInstance } from 'ts-sinon'; @@ -29,11 +28,12 @@ import { ClientEncryption, KeyVault } from './field-level-encryption'; import Mongo from './mongo'; import ShellInstanceState from './shell-instance-state'; import { NodeDriverServiceProvider } from '../../service-provider-node-driver'; -import { startSharedTestServer } from '../../../testing/integration-testing-hooks'; import { + startSharedTestServer, makeFakeHTTPConnection, fakeAWSHandlers, -} from '../../../testing/fake-kms'; + getTestCertificatePath, +} from '@mongosh/testing'; import { Collection } from './collection'; import { dummyOptions } from './helpers.spec'; import type { IncomingMessage } from 'http'; @@ -84,18 +84,6 @@ const exampleUUID = new bson.Binary( 4 ).toUUID(); -function getCertPath(filename: string): string { - return path.join( - __dirname, - '..', - '..', - '..', - 'testing', - 'certificates', - filename - ); -} - describe('Field Level Encryption', function () { let sp: StubbedInstance; let mongo: Mongo; @@ -879,9 +867,11 @@ srDVjIT3LsvTqw==`, { endpoint: 'kmip.example.com:123', tlsOptions: { - tlsCertificateKeyFile: getCertPath('client.bundle.encrypted.pem'), + tlsCertificateKeyFile: getTestCertificatePath( + 'client.bundle.encrypted.pem' + ), tlsCertificateKeyFilePassword: 'p4ssw0rd', - tlsCAFile: getCertPath('ca.crt'), + tlsCAFile: getTestCertificatePath('ca.crt'), }, }, ], @@ -949,12 +939,12 @@ srDVjIT3LsvTqw==`, servername: 'kmip.example.com', port: 123, passphrase: 'p4ssw0rd', - ca: await fs.readFile(getCertPath('ca.crt')), + ca: await fs.readFile(getTestCertificatePath('ca.crt')), cert: await fs.readFile( - getCertPath('client.bundle.encrypted.pem') + getTestCertificatePath('client.bundle.encrypted.pem') ), key: await fs.readFile( - getCertPath('client.bundle.encrypted.pem') + getTestCertificatePath('client.bundle.encrypted.pem') ), }, }, diff --git a/packages/shell-api/src/helpers.spec.ts b/packages/shell-api/src/helpers.spec.ts index 533056e125..eecb36b76c 100644 --- a/packages/shell-api/src/helpers.spec.ts +++ b/packages/shell-api/src/helpers.spec.ts @@ -14,7 +14,7 @@ import type { ServiceProvider } from '@mongosh/service-provider-core'; import * as bson from 'bson'; import type { DevtoolsConnectOptions } from '../../service-provider-node-driver'; import { NodeDriverServiceProvider } from '../../service-provider-node-driver'; // avoid cyclic dep just for test -import { startSharedTestServer } from '../../../testing/integration-testing-hooks'; +import { startSharedTestServer } from '@mongosh/testing'; import { makeFakeConfigDatabase } from '../test/shard-test-fake-data'; import sinon from 'ts-sinon'; import chai, { expect } from 'chai'; diff --git a/packages/shell-api/src/integration.spec.ts b/packages/shell-api/src/integration.spec.ts index 2b6e50a1bf..6ef995c8e7 100644 --- a/packages/shell-api/src/integration.spec.ts +++ b/packages/shell-api/src/integration.spec.ts @@ -9,7 +9,7 @@ import { skipIfServerVersion, skipIfApiStrict, startSharedTestServer, -} from '../../../testing/integration-testing-hooks'; +} from '@mongosh/testing'; import type { ShellApi, Mongo } from './index'; import { toShellResult, Topologies } from './index'; import type { diff --git a/packages/shell-api/src/mongo.spec.ts b/packages/shell-api/src/mongo.spec.ts index 01cbb9fd8e..26bfa75e8b 100644 --- a/packages/shell-api/src/mongo.spec.ts +++ b/packages/shell-api/src/mongo.spec.ts @@ -30,10 +30,7 @@ import { MongoshUnimplementedError, } from '@mongosh/errors'; import { NodeDriverServiceProvider } from '../../service-provider-node-driver'; -import { - skipIfServerVersion, - startSharedTestServer, -} from '../../../testing/integration-testing-hooks'; +import { skipIfServerVersion, startSharedTestServer } from '@mongosh/testing'; import { dummyOptions } from './helpers.spec'; import { ClientBulkWriteResult } from './result'; diff --git a/packages/shell-api/src/replica-set.spec.ts b/packages/shell-api/src/replica-set.spec.ts index c50a98f462..99603add48 100644 --- a/packages/shell-api/src/replica-set.spec.ts +++ b/packages/shell-api/src/replica-set.spec.ts @@ -16,12 +16,13 @@ import sinonChai from 'sinon-chai'; import type { StubbedInstance } from 'ts-sinon'; import { stubInterface } from 'ts-sinon'; import { createRetriableMethod, ensureMaster } from '../test/helpers'; -import type { MongodSetup } from '../../../testing/integration-testing-hooks'; import { + type MongodSetup, skipIfServerVersion, startTestCluster, skipIfApiStrict, -} from '../../../testing/integration-testing-hooks'; + eventually, +} from '@mongosh/testing'; import { NodeDriverServiceProvider } from '../../service-provider-node-driver'; import { Database } from './database'; import { @@ -38,7 +39,6 @@ import type { ReplSetConfig, ReplSetMemberConfig } from './replica-set'; import ReplicaSet from './replica-set'; import type { EvaluationListener } from './shell-instance-state'; import ShellInstanceState from './shell-instance-state'; -import { eventually } from '../../../testing/eventually'; chai.use(sinonChai); function deepClone(value: T): T { diff --git a/packages/shell-api/src/session.spec.ts b/packages/shell-api/src/session.spec.ts index d1846dc237..68c4478c8f 100644 --- a/packages/shell-api/src/session.spec.ts +++ b/packages/shell-api/src/session.spec.ts @@ -23,7 +23,7 @@ import { startTestCluster, skipIfServerVersion, skipIfApiStrict, -} from '../../../testing/integration-testing-hooks'; +} from '@mongosh/testing'; import { ensureMaster, ensureSessionExists } from '../test/helpers'; import { Database } from './database'; import { CommonErrors, MongoshInvalidInputError } from '@mongosh/errors'; diff --git a/packages/shell-api/src/shard.spec.ts b/packages/shell-api/src/shard.spec.ts index c52edc91df..b63a03797d 100644 --- a/packages/shell-api/src/shard.spec.ts +++ b/packages/shell-api/src/shard.spec.ts @@ -28,7 +28,7 @@ import { startTestCluster, skipIfServerVersion, skipIfApiStrict, -} from '../../../testing/integration-testing-hooks'; +} from '@mongosh/testing'; import type { DatabaseWithSchema } from './database'; import { Database } from './database'; import { inspect } from 'util'; diff --git a/packages/snippet-manager/package.json b/packages/snippet-manager/package.json index 616438af34..bc57e60ed5 100644 --- a/packages/snippet-manager/package.json +++ b/packages/snippet-manager/package.json @@ -54,6 +54,7 @@ "depcheck": "^1.4.7", "eslint": "^7.25.0", "nanobus": "^4.5.0", - "prettier": "^2.8.8" + "prettier": "^2.8.8", + "@mongosh/testing": "0.0.0-dev.0" } } diff --git a/packages/snippet-manager/src/snippet-manager.spec.ts b/packages/snippet-manager/src/snippet-manager.spec.ts index 03a8d85a42..53e69b518c 100644 --- a/packages/snippet-manager/src/snippet-manager.spec.ts +++ b/packages/snippet-manager/src/snippet-manager.spec.ts @@ -13,7 +13,7 @@ import bson from 'bson'; import path from 'path'; import { promises as fs, createReadStream } from 'fs'; import Nanobus from 'nanobus'; -import { eventually } from '../../../testing/eventually'; +import { eventually } from '@mongosh/testing'; chai.use(sinonChai); describe('SnippetManager', function () { diff --git a/testing/.eslintrc.js b/packages/testing/.eslintrc.js similarity index 100% rename from testing/.eslintrc.js rename to packages/testing/.eslintrc.js diff --git a/packages/testing/.eslintrc.json b/packages/testing/.eslintrc.json new file mode 100644 index 0000000000..e548c12df1 --- /dev/null +++ b/packages/testing/.eslintrc.json @@ -0,0 +1,9 @@ +{ + "extends": "@mongodb-js/eslint-config-mongosh", + "parserOptions": { + "project": ["./tsconfig-lint.json"] + }, + "rules": { + "mocha/no-exports": "off" + } +} diff --git a/packages/testing/.gitignore b/packages/testing/.gitignore new file mode 100644 index 0000000000..59a1892526 --- /dev/null +++ b/packages/testing/.gitignore @@ -0,0 +1,2 @@ +lib/ + diff --git a/testing/.prettierrc.json b/packages/testing/.prettierrc similarity index 100% rename from testing/.prettierrc.json rename to packages/testing/.prettierrc diff --git a/packages/testing/.prettierrc.json b/packages/testing/.prettierrc.json new file mode 100644 index 0000000000..dfae21d047 --- /dev/null +++ b/packages/testing/.prettierrc.json @@ -0,0 +1 @@ +"@mongodb-js/prettier-config-devtools" diff --git a/packages/testing/README.md b/packages/testing/README.md new file mode 100644 index 0000000000..ff1366bc02 --- /dev/null +++ b/packages/testing/README.md @@ -0,0 +1,20 @@ +# @mongosh/testing + +Internal testing utilities for mongosh packages. This package is private and only used for testing purposes within the mongosh monorepo. + +## Contents + +- **integration-testing-hooks.ts** - Test server setup and helpers for integration tests +- **eventually.ts** - Retry helper for asynchronous tests +- **fake-kms.ts** - Mock KMS server for field-level encryption tests + +## Usage + +```typescript +import { + startSharedTestServer, + startTestServer, + eventually, + makeFakeHTTPServer, +} from '@mongosh/testing'; +``` diff --git a/testing/certificates/README.md b/packages/testing/certificates/README.md similarity index 100% rename from testing/certificates/README.md rename to packages/testing/certificates/README.md diff --git a/testing/certificates/ca-server.crl b/packages/testing/certificates/ca-server.crl similarity index 100% rename from testing/certificates/ca-server.crl rename to packages/testing/certificates/ca-server.crl diff --git a/testing/certificates/ca.cnf b/packages/testing/certificates/ca.cnf similarity index 100% rename from testing/certificates/ca.cnf rename to packages/testing/certificates/ca.cnf diff --git a/testing/certificates/ca.crt b/packages/testing/certificates/ca.crt similarity index 100% rename from testing/certificates/ca.crt rename to packages/testing/certificates/ca.crt diff --git a/testing/certificates/ca.db b/packages/testing/certificates/ca.db similarity index 100% rename from testing/certificates/ca.db rename to packages/testing/certificates/ca.db diff --git a/testing/certificates/ca.db.attr b/packages/testing/certificates/ca.db.attr similarity index 100% rename from testing/certificates/ca.db.attr rename to packages/testing/certificates/ca.db.attr diff --git a/testing/certificates/ca.key b/packages/testing/certificates/ca.key similarity index 100% rename from testing/certificates/ca.key rename to packages/testing/certificates/ca.key diff --git a/testing/certificates/ca.serial b/packages/testing/certificates/ca.serial similarity index 100% rename from testing/certificates/ca.serial rename to packages/testing/certificates/ca.serial diff --git a/testing/certificates/client.bundle.encrypted.pem b/packages/testing/certificates/client.bundle.encrypted.pem similarity index 100% rename from testing/certificates/client.bundle.encrypted.pem rename to packages/testing/certificates/client.bundle.encrypted.pem diff --git a/testing/certificates/client.bundle.pem b/packages/testing/certificates/client.bundle.pem similarity index 100% rename from testing/certificates/client.bundle.pem rename to packages/testing/certificates/client.bundle.pem diff --git a/testing/certificates/client.bundle.pfx b/packages/testing/certificates/client.bundle.pfx similarity index 100% rename from testing/certificates/client.bundle.pfx rename to packages/testing/certificates/client.bundle.pfx diff --git a/testing/certificates/client.encrypted.key b/packages/testing/certificates/client.encrypted.key similarity index 100% rename from testing/certificates/client.encrypted.key rename to packages/testing/certificates/client.encrypted.key diff --git a/testing/certificates/client.key b/packages/testing/certificates/client.key similarity index 100% rename from testing/certificates/client.key rename to packages/testing/certificates/client.key diff --git a/testing/certificates/client.pem b/packages/testing/certificates/client.pem similarity index 100% rename from testing/certificates/client.pem rename to packages/testing/certificates/client.pem diff --git a/testing/certificates/invalid-client.bundle.pem b/packages/testing/certificates/invalid-client.bundle.pem similarity index 100% rename from testing/certificates/invalid-client.bundle.pem rename to packages/testing/certificates/invalid-client.bundle.pem diff --git a/testing/certificates/invalid-client.key b/packages/testing/certificates/invalid-client.key similarity index 100% rename from testing/certificates/invalid-client.key rename to packages/testing/certificates/invalid-client.key diff --git a/testing/certificates/non-ca.crt b/packages/testing/certificates/non-ca.crt similarity index 100% rename from testing/certificates/non-ca.crt rename to packages/testing/certificates/non-ca.crt diff --git a/testing/certificates/non-ca.key b/packages/testing/certificates/non-ca.key similarity index 100% rename from testing/certificates/non-ca.key rename to packages/testing/certificates/non-ca.key diff --git a/testing/certificates/partial-trust-chain/ca.pem b/packages/testing/certificates/partial-trust-chain/ca.pem similarity index 100% rename from testing/certificates/partial-trust-chain/ca.pem rename to packages/testing/certificates/partial-trust-chain/ca.pem diff --git a/testing/certificates/partial-trust-chain/cert.pem b/packages/testing/certificates/partial-trust-chain/cert.pem similarity index 100% rename from testing/certificates/partial-trust-chain/cert.pem rename to packages/testing/certificates/partial-trust-chain/cert.pem diff --git a/testing/certificates/partial-trust-chain/key-and-cert.pem b/packages/testing/certificates/partial-trust-chain/key-and-cert.pem similarity index 100% rename from testing/certificates/partial-trust-chain/key-and-cert.pem rename to packages/testing/certificates/partial-trust-chain/key-and-cert.pem diff --git a/testing/certificates/partial-trust-chain/key.pem b/packages/testing/certificates/partial-trust-chain/key.pem similarity index 100% rename from testing/certificates/partial-trust-chain/key.pem rename to packages/testing/certificates/partial-trust-chain/key.pem diff --git a/testing/certificates/server-invalidhost.bundle.pem b/packages/testing/certificates/server-invalidhost.bundle.pem similarity index 100% rename from testing/certificates/server-invalidhost.bundle.pem rename to packages/testing/certificates/server-invalidhost.bundle.pem diff --git a/testing/certificates/server-invalidhost.key b/packages/testing/certificates/server-invalidhost.key similarity index 100% rename from testing/certificates/server-invalidhost.key rename to packages/testing/certificates/server-invalidhost.key diff --git a/testing/certificates/server.bundle.pem b/packages/testing/certificates/server.bundle.pem similarity index 100% rename from testing/certificates/server.bundle.pem rename to packages/testing/certificates/server.bundle.pem diff --git a/testing/certificates/server.key b/packages/testing/certificates/server.key similarity index 100% rename from testing/certificates/server.key rename to packages/testing/certificates/server.key diff --git a/packages/testing/package.json b/packages/testing/package.json new file mode 100644 index 0000000000..e8e1baafff --- /dev/null +++ b/packages/testing/package.json @@ -0,0 +1,42 @@ +{ + "name": "@mongosh/testing", + "version": "0.0.0-dev.0", + "description": "MongoDB Shell Testing Utilities", + "homepage": "https://github.com/mongodb-js/mongosh", + "license": "Apache-2.0", + "main": "src/index.ts", + "types": "src/index.ts", + "private": true, + "repository": { + "type": "git", + "url": "https://github.com/mongodb-js/mongosh" + }, + "engines": { + "node": ">=14.15.1" + }, + "scripts": { + "eslint": "eslint", + "lint": "npm run eslint . && npm run prettier -- --check .", + "prettier": "prettier", + "reformat": "npm run prettier -- --write . && npm run eslint -- --fix" + }, + "dependencies": { + "@mongosh/build": "3.7.8", + "duplexpair": "^1.0.2", + "mongodb": "^6.19.0", + "mongodb-connection-string-url": "^3.0.1", + "mongodb-runner": "^6.2.0", + "semver": "^7.3.4", + "which": "^2.0.2" + }, + "devDependencies": { + "@mongodb-js/eslint-config-mongosh": "^1.0.0", + "@mongodb-js/prettier-config-devtools": "^1.0.1", + "@mongodb-js/tsconfig-mongosh": "^1.0.0", + "@types/semver": "^7.3.4", + "@types/which": "^1.3.2", + "eslint": "^7.25.0", + "prettier": "^2.8.8", + "typescript": "^5.3.3" + } +} diff --git a/testing/eventually.ts b/packages/testing/src/eventually.ts similarity index 100% rename from testing/eventually.ts rename to packages/testing/src/eventually.ts diff --git a/testing/fake-kms.ts b/packages/testing/src/fake-kms.ts similarity index 100% rename from testing/fake-kms.ts rename to packages/testing/src/fake-kms.ts diff --git a/packages/testing/src/index.ts b/packages/testing/src/index.ts new file mode 100644 index 0000000000..bc8f9b58a2 --- /dev/null +++ b/packages/testing/src/index.ts @@ -0,0 +1,15 @@ +import path from 'path'; + +export * from './integration-testing-hooks'; +export * from './eventually'; +export * from './fake-kms'; + +/** + * Path to the certificates directory containing test certificates + */ +const TEST_CERTIFICATES_DIR = path.resolve(__dirname, '..', 'certificates'); + +/** Get the path to a test certificate */ +export function getTestCertificatePath(filename: string): string { + return path.join(TEST_CERTIFICATES_DIR, filename); +} diff --git a/testing/integration-testing-hooks.ts b/packages/testing/src/integration-testing-hooks.ts similarity index 99% rename from testing/integration-testing-hooks.ts rename to packages/testing/src/integration-testing-hooks.ts index 7f229cdf18..b28925a47b 100644 --- a/testing/integration-testing-hooks.ts +++ b/packages/testing/src/integration-testing-hooks.ts @@ -14,7 +14,7 @@ const execFile = promisify(child_process.execFile); // Return the path to the temporary directory and ensure that it exists. async function getTmpdir(): Promise { - const tmpdir = path.resolve(__dirname, '..', 'tmp'); + const tmpdir = path.resolve(__dirname, '..', '..', '..', 'tmp'); await fs.mkdir(tmpdir, { recursive: true }); return tmpdir; } diff --git a/testing/tests-globalconfig.conf b/packages/testing/tests-globalconfig.conf similarity index 100% rename from testing/tests-globalconfig.conf rename to packages/testing/tests-globalconfig.conf diff --git a/packages/testing/tsconfig-lint.json b/packages/testing/tsconfig-lint.json new file mode 100644 index 0000000000..49467c9152 --- /dev/null +++ b/packages/testing/tsconfig-lint.json @@ -0,0 +1,4 @@ +{ + "extends": "@mongodb-js/tsconfig-mongosh/tsconfig.lint.json", + "include": ["src/**/*"] +} diff --git a/packages/testing/tsconfig.json b/packages/testing/tsconfig.json new file mode 100644 index 0000000000..8c8bebecf8 --- /dev/null +++ b/packages/testing/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "@mongodb-js/tsconfig-mongosh/tsconfig.common.json", + "compilerOptions": { + "allowJs": true, + "outDir": "./lib", + "declaration": true, + "declarationMap": true + }, + "include": ["src/**/*", "src/certificates/**/*"], + "exclude": ["lib"] +} diff --git a/testing/test-vscode.sh b/scripts/test-vscode.sh similarity index 100% rename from testing/test-vscode.sh rename to scripts/test-vscode.sh diff --git a/testing/package.json b/testing/package.json deleted file mode 100644 index bf20e826b5..0000000000 --- a/testing/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "scripts": { - "lint": "prettier --check .", - "reformat": "prettier --write ." - } -} diff --git a/testing/tsconfig.json b/testing/tsconfig.json deleted file mode 100644 index c76dbd55aa..0000000000 --- a/testing/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "@mongodb-js/tsconfig-mongosh/tsconfig.common.json", - "compilerOptions": { - "allowJs": true, - "outDir": "./dist" - }, - "include": ["**/*"], - "exclude": ["certificates"] -}