diff --git a/.evergreen/ci_matrix_constants.js b/.evergreen/ci_matrix_constants.js new file mode 100644 index 00000000000..cb8c2c59294 --- /dev/null +++ b/.evergreen/ci_matrix_constants.js @@ -0,0 +1,29 @@ +const MONGODB_VERSIONS = ['latest', 'rapid', '6.0', '5.0', '4.4', '4.2', '4.0', '3.6']; +const versions = [ + { codeName: 'erbium', versionNumber: 12 }, + { codeName: 'fermium', versionNumber: 14 }, + { codeName: 'gallium', versionNumber: 16 }, + { codeName: 'hydrogen', versionNumber: 18 } +]; +const NODE_VERSIONS = versions.map(({ codeName }) => codeName); +NODE_VERSIONS.sort(); +const LOWEST_LTS = NODE_VERSIONS[0]; +const LATEST_LTS = NODE_VERSIONS[NODE_VERSIONS.length - 1]; + +const TOPOLOGIES = ['server', 'replica_set', 'sharded_cluster']; +const AWS_AUTH_VERSIONS = ['latest', '6.0', '5.0', '4.4']; +const TLS_VERSIONS = ['latest', '6.0', '5.0', '4.4', '4.2']; + +const DEFAULT_OS = 'rhel80-large'; + +module.exports = { + MONGODB_VERSIONS, + versions, + NODE_VERSIONS, + LOWEST_LTS, + LATEST_LTS, + TOPOLOGIES, + AWS_AUTH_VERSIONS, + TLS_VERSIONS, + DEFAULT_OS +}; diff --git a/.evergreen/config.in.yml b/.evergreen/config.in.yml index 2f17d0934c4..916f8555112 100644 --- a/.evergreen/config.in.yml +++ b/.evergreen/config.in.yml @@ -317,15 +317,42 @@ functions: args: - "${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh" - "run mongosh integration tests": - - command: shell.exec - type: test + ########################################### + # mongosh functions + ########################################### + "compile mongosh": + - command: subprocess.exec params: - working_dir: "src" - script: | - ${PREPARE_SHELL} - export DISTRO_ID=${distro_id} - bash ${PROJECT_DIRECTORY}/.evergreen/run-mongosh-integration-tests.sh + working_dir: src + env: + PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} + TASK_ID: ${task_id} + binary: bash + args: + - "${PROJECT_DIRECTORY}/.evergreen/run-mongosh-integration-tests.sh" + + "run mongosh tests for package": + - command: subprocess.exec + params: + working_dir: src + env: + PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} + TASK_ID: ${task_id} + MONGOSH_RUN_ONLY_IN_PACKAGE: ${mongosh_package} + binary: bash + args: + - "${PROJECT_DIRECTORY}/.evergreen/run-mongosh-integration-tests.sh" + + "run mongosh package scope test": + - command: subprocess.exec + params: + working_dir: src + env: + PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} + TASK_ID: ${task_id} + binary: bash + args: + - "${PROJECT_DIRECTORY}/.evergreen/run-mongosh-scope-test.sh" "cleanup": - command: shell.exec @@ -375,7 +402,7 @@ functions: working_dir: "src" script: | ${PREPARE_SHELL} - NODE_LTS_NAME=${NODE_LTS_NAME} MSVS_VERSION=${MSVS_VERSION} NPM_OPTIONS=${NPM_OPTIONS}\ + NODE_LTS_NAME=${NODE_LTS_NAME} NPM_OPTIONS=${NPM_OPTIONS}\ bash ${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh - command: expansions.update params: diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 1204adad369..fba0d9ed359 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -281,15 +281,37 @@ functions: binary: bash args: - ${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh - run mongosh integration tests: - - command: shell.exec - type: test + compile mongosh: + - command: subprocess.exec params: working_dir: src - script: | - ${PREPARE_SHELL} - export DISTRO_ID=${distro_id} - bash ${PROJECT_DIRECTORY}/.evergreen/run-mongosh-integration-tests.sh + env: + PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} + TASK_ID: ${task_id} + binary: bash + args: + - ${PROJECT_DIRECTORY}/.evergreen/run-mongosh-integration-tests.sh + run mongosh tests for package: + - command: subprocess.exec + params: + working_dir: src + env: + PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} + TASK_ID: ${task_id} + MONGOSH_RUN_ONLY_IN_PACKAGE: ${mongosh_package} + binary: bash + args: + - ${PROJECT_DIRECTORY}/.evergreen/run-mongosh-integration-tests.sh + run mongosh package scope test: + - command: subprocess.exec + params: + working_dir: src + env: + PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} + TASK_ID: ${task_id} + binary: bash + args: + - ${PROJECT_DIRECTORY}/.evergreen/run-mongosh-scope-test.sh cleanup: - command: shell.exec params: @@ -334,7 +356,7 @@ functions: working_dir: src script: | ${PREPARE_SHELL} - NODE_LTS_NAME=${NODE_LTS_NAME} MSVS_VERSION=${MSVS_VERSION} NPM_OPTIONS=${NPM_OPTIONS}\ + NODE_LTS_NAME=${NODE_LTS_NAME} NPM_OPTIONS=${NPM_OPTIONS}\ bash ${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh - command: expansions.update params: @@ -2124,15 +2146,6 @@ tasks: - func: check types vars: TS_VERSION: 4.1.6 - - name: run-mongosh-integration-tests - tags: - - run-mongosh-integration-tests - exec_timeout_secs: 3600 - commands: - - func: install dependencies - vars: - NODE_LTS_NAME: gallium - - func: run mongosh integration tests - name: download-and-merge-coverage tags: [] commands: @@ -2642,6 +2655,99 @@ tasks: - func: add aws auth variables to file - func: setup aws env - func: run lambda handler example tests with aws auth + - name: run-mongosh-browser-repl + tags: + - run-mongosh-integration-tests + depends_on: compile-mongosh + commands: + - func: install dependencies + vars: + NODE_LTS_NAME: gallium + - func: run mongosh tests for package + vars: + mongosh_package: browser-repl + - name: run-mongosh-browser-runtime-electron + tags: + - run-mongosh-integration-tests + depends_on: compile-mongosh + commands: + - func: install dependencies + vars: + NODE_LTS_NAME: gallium + - func: run mongosh tests for package + vars: + mongosh_package: browser-runtime-electron + - name: run-mongosh-cli-repl + tags: + - run-mongosh-integration-tests + depends_on: compile-mongosh + commands: + - func: install dependencies + vars: + NODE_LTS_NAME: gallium + - func: run mongosh tests for package + vars: + mongosh_package: cli-repl + - name: run-mongosh-connectivity-tests + tags: + - run-mongosh-integration-tests + depends_on: compile-mongosh + commands: + - func: install dependencies + vars: + NODE_LTS_NAME: gallium + - func: run mongosh tests for package + vars: + mongosh_package: connectivity-tests + - name: run-mongosh-mongosh + tags: + - run-mongosh-integration-tests + depends_on: compile-mongosh + commands: + - func: install dependencies + vars: + NODE_LTS_NAME: gallium + - func: run mongosh tests for package + vars: + mongosh_package: mongosh + - name: run-mongosh-node-runtime-worker-thread + tags: + - run-mongosh-integration-tests + depends_on: compile-mongosh + commands: + - func: install dependencies + vars: + NODE_LTS_NAME: gallium + - func: run mongosh tests for package + vars: + mongosh_package: node-runtime-worker-thread + - name: run-mongosh-service-provider-server + tags: + - run-mongosh-integration-tests + depends_on: compile-mongosh + commands: + - func: install dependencies + vars: + NODE_LTS_NAME: gallium + - func: run mongosh tests for package + vars: + mongosh_package: service-provider-server + - name: compile-mongosh + tags: + - run-mongosh-integration-tests + commands: + - func: install dependencies + vars: + NODE_LTS_NAME: gallium + - func: compile mongosh + - name: verify-mongosh-scopes + tags: + - run-mongosh-integration-tests + commands: + - func: install dependencies + vars: + NODE_LTS_NAME: gallium + - func: run mongosh package scope test task_groups: - name: serverless_task_group setup_group_can_fail_task: true @@ -2929,7 +3035,6 @@ buildvariants: run_on: windows-64-vs2019-large expansions: NODE_LTS_NAME: erbium - MSVS_VERSION: 2019 tasks: - test-latest-server - test-latest-replica_set @@ -2971,7 +3076,6 @@ buildvariants: run_on: windows-64-vs2019-large expansions: NODE_LTS_NAME: fermium - MSVS_VERSION: 2019 tasks: - test-latest-server - test-latest-replica_set @@ -3013,7 +3117,6 @@ buildvariants: run_on: windows-64-vs2019-large expansions: NODE_LTS_NAME: gallium - MSVS_VERSION: 2019 tasks: - test-latest-server - test-latest-replica_set @@ -3053,7 +3156,6 @@ buildvariants: run_on: windows-64-vs2019-large expansions: NODE_LTS_NAME: hydrogen - MSVS_VERSION: 2019 tasks: - test-latest-server - test-latest-replica_set @@ -3115,7 +3217,15 @@ buildvariants: display_name: mongosh integration tests run_on: ubuntu1804-large tasks: - - run-mongosh-integration-tests + - run-mongosh-browser-repl + - run-mongosh-browser-runtime-electron + - run-mongosh-cli-repl + - run-mongosh-connectivity-tests + - run-mongosh-mongosh + - run-mongosh-node-runtime-worker-thread + - run-mongosh-service-provider-server + - compile-mongosh + - verify-mongosh-scopes - name: ubuntu1804-test-mongodb-aws display_name: MONGODB-AWS Auth test run_on: ubuntu1804-large diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index 596c31a0f48..8b3e2d8fa21 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -1,23 +1,18 @@ const fs = require('fs'); const yaml = require('js-yaml'); - -const MONGODB_VERSIONS = ['latest', 'rapid', '6.0', '5.0', '4.4', '4.2', '4.0', '3.6']; -const versions = [ - { codeName: 'erbium', versionNumber: 12 }, - { codeName: 'fermium', versionNumber: 14 }, - { codeName: 'gallium', versionNumber: 16 }, - { codeName: 'hydrogen', versionNumber: 18 } -]; -const NODE_VERSIONS = versions.map(({ codeName }) => codeName) -NODE_VERSIONS.sort(); -const LOWEST_LTS = NODE_VERSIONS[0]; -const LATEST_LTS = NODE_VERSIONS[NODE_VERSIONS.length - 1]; - -const TOPOLOGIES = ['server', 'replica_set', 'sharded_cluster']; -const AWS_AUTH_VERSIONS = ['latest', '6.0', '5.0', '4.4']; -const TLS_VERSIONS = ['latest', '6.0', '5.0', '4.4', '4.2']; - -const DEFAULT_OS = 'rhel80-large'; +const { mongoshTasks } = require('./generate_mongosh_tasks'); + +const { + MONGODB_VERSIONS, + versions, + NODE_VERSIONS, + LOWEST_LTS, + LATEST_LTS, + TOPOLOGIES, + AWS_AUTH_VERSIONS, + TLS_VERSIONS, + DEFAULT_OS +} = require('./ci_matrix_constants'); const OPERATING_SYSTEMS = [ { @@ -29,7 +24,6 @@ const OPERATING_SYSTEMS = [ name: 'windows-64-vs2019', display_name: 'Windows (VS2019)', run_on: 'windows-64-vs2019-large', - msvsVersion: 2019, clientEncryption: false // TODO(NODE-3401): Unskip when Windows no longer fails to launch mongocryptd occasionally } ].map(osConfig => ({ @@ -368,28 +362,31 @@ for (const VERSION of AWS_AUTH_VERSIONS) { const BUILD_VARIANTS = []; -for (const - { - name: osName, - display_name: osDisplayName, - run_on, - nodeVersions = NODE_VERSIONS, - clientEncryption, - msvsVersion - } of OPERATING_SYSTEMS) { +for (const { + name: osName, + display_name: osDisplayName, + run_on, + nodeVersions = NODE_VERSIONS, + clientEncryption +} of OPERATING_SYSTEMS) { const testedNodeVersions = NODE_VERSIONS.filter(version => nodeVersions.includes(version)); const os = osName.split('-')[0]; - const tasks = BASE_TASKS.concat(TASKS) - .filter(task => { - const isAWSTask = task.name.match(/^aws/); - const isSkippedTaskOnWindows = task.tags && os.match(/^windows/) && task.tags.filter(tag => WINDOWS_SKIP_TAGS.has(tag)).length - - return !isAWSTask && !isSkippedTaskOnWindows; - }); + const tasks = BASE_TASKS.concat(TASKS).filter(task => { + const isAWSTask = task.name.match(/^aws/); + const isSkippedTaskOnWindows = + task.tags && + os.match(/^windows/) && + task.tags.filter(tag => WINDOWS_SKIP_TAGS.has(tag)).length; + + return !isAWSTask && !isSkippedTaskOnWindows; + }); for (const NODE_LTS_NAME of testedNodeVersions) { - const nodeVersionNumber = versions.find(({ codeName }) => codeName === NODE_LTS_NAME).versionNumber; - const nodeLtsDisplayName = nodeVersionNumber === undefined ? `Node Latest` : `Node${nodeVersionNumber}`; + const nodeVersionNumber = versions.find( + ({ codeName }) => codeName === NODE_LTS_NAME + ).versionNumber; + const nodeLtsDisplayName = + nodeVersionNumber === undefined ? `Node Latest` : `Node${nodeVersionNumber}`; const name = `${osName}-${NODE_LTS_NAME}`; const display_name = `${osDisplayName} ${nodeLtsDisplayName}`; const expansions = { NODE_LTS_NAME }; @@ -398,12 +395,9 @@ for (const if (clientEncryption) { expansions.CLIENT_ENCRYPTION = true; } - if (msvsVersion) { - expansions.MSVS_VERSION = msvsVersion; - } BUILD_VARIANTS.push({ name, display_name, run_on, expansions, tasks: taskNames }); - }; + } const configureLatestNodeSmokeTest = os.match(/^rhel/); if (configureLatestNodeSmokeTest) { @@ -413,18 +407,20 @@ for (const run_on, expansions: { NODE_LTS_NAME: 'latest' }, tasks: tasks.map(({ name }) => name) - } + }; if (clientEncryption) { buildVariantData.expansions.CLIENT_ENCRYPTION = true; } - BUILD_VARIANTS.push(buildVariantData) + BUILD_VARIANTS.push(buildVariantData); } } BUILD_VARIANTS.push({ name: 'macos-1100', - display_name: `MacOS 11 Node${versions.find(version => version.codeName === LATEST_LTS).versionNumber}`, + display_name: `MacOS 11 Node${ + versions.find(version => version.codeName === LATEST_LTS).versionNumber + }`, run_on: 'macos-1100', expansions: { NODE_LTS_NAME: LATEST_LTS, @@ -467,28 +463,27 @@ SINGLETON_TASKS.push( ); function* makeTypescriptTasks() { - for (const TS_VERSION of ["next", "current", "4.1.6"]) { + for (const TS_VERSION of ['next', 'current', '4.1.6']) { // 4.1.6 can consume the public API but not compile the driver - if (TS_VERSION !== '4.1.6' - && TS_VERSION !== 'next') { + if (TS_VERSION !== '4.1.6' && TS_VERSION !== 'next') { yield { - name: `compile-driver-typescript-${TS_VERSION}`, - tags: [`compile-driver-typescript-${TS_VERSION}`], - commands: [ - { - func: 'install dependencies', - vars: { - NODE_LTS_NAME: LOWEST_LTS - } - }, - { - func: 'compile driver', - vars: { - TS_VERSION - } + name: `compile-driver-typescript-${TS_VERSION}`, + tags: [`compile-driver-typescript-${TS_VERSION}`], + commands: [ + { + func: 'install dependencies', + vars: { + NODE_LTS_NAME: LOWEST_LTS } - ] - } + }, + { + func: 'compile driver', + vars: { + TS_VERSION + } + } + ] + }; } yield { @@ -508,7 +503,7 @@ function* makeTypescriptTasks() { } } ] - } + }; } return { name: 'run-typescript-next', @@ -522,7 +517,7 @@ function* makeTypescriptTasks() { }, { func: 'run typescript next' } ] - } + }; } BUILD_VARIANTS.push({ @@ -543,27 +538,11 @@ BUILD_VARIANTS.push({ tasks: ['download-and-merge-coverage'] }); -// singleton build variant for mongosh integration tests -SINGLETON_TASKS.push({ - name: 'run-mongosh-integration-tests', - tags: ['run-mongosh-integration-tests'], - exec_timeout_secs: 3600, - commands: [ - { - func: 'install dependencies', - vars: { - NODE_LTS_NAME: 'gallium' - } - }, - { func: 'run mongosh integration tests' } - ] -}); - BUILD_VARIANTS.push({ name: 'mongosh_integration_tests', display_name: 'mongosh integration tests', run_on: 'ubuntu1804-large', - tasks: ['run-mongosh-integration-tests'] + tasks: mongoshTasks.map(({ name }) => name) }); // special case for MONGODB-AWS authentication @@ -706,7 +685,9 @@ BUILD_VARIANTS.push({ // TODO(NODE-4575): unskip zstd and snappy on node 16 for (const variant of BUILD_VARIANTS.filter( - variant => variant.expansions && ['gallium', 'hydrogen', 'latest'].includes(variant.expansions.NODE_LTS_NAME) + variant => + variant.expansions && + ['gallium', 'hydrogen', 'latest'].includes(variant.expansions.NODE_LTS_NAME) )) { variant.tasks = variant.tasks.filter( name => !['test-zstd-compression', 'test-snappy-compression'].includes(name) @@ -717,18 +698,14 @@ for (const variant of BUILD_VARIANTS.filter( for (const variant of BUILD_VARIANTS.filter( variant => variant.expansions && ['hydrogen', 'latest'].includes(variant.expansions.NODE_LTS_NAME) )) { - variant.tasks = variant.tasks.filter( - name => !['test-auth-kerberos'].includes(name) - ); + variant.tasks = variant.tasks.filter(name => !['test-auth-kerberos'].includes(name)); } // TODO(NODE-4897): Debug socks5 tests on node latest for (const variant of BUILD_VARIANTS.filter( variant => variant.expansions && ['latest'].includes(variant.expansions.NODE_LTS_NAME) )) { - variant.tasks = variant.tasks.filter( - name => !['test-socks5'].includes(name) - ); + variant.tasks = variant.tasks.filter(name => !['test-socks5'].includes(name)); } const fileData = yaml.load(fs.readFileSync(`${__dirname}/config.in.yml`, 'utf8')); @@ -737,7 +714,9 @@ fileData.tasks = (fileData.tasks || []) .concat(TASKS) .concat(SINGLETON_TASKS) .concat(AUTH_DISABLED_TASKS) - .concat(AWS_LAMBDA_HANDLER_TASKS); + .concat(AWS_LAMBDA_HANDLER_TASKS) + .concat(mongoshTasks); + fileData.buildvariants = (fileData.buildvariants || []).concat(BUILD_VARIANTS); fs.writeFileSync(`${__dirname}/config.yml`, yaml.dump(fileData, { lineWidth: 120 }), 'utf8'); diff --git a/.evergreen/generate_mongosh_tasks.js b/.evergreen/generate_mongosh_tasks.js new file mode 100644 index 00000000000..6d129058269 --- /dev/null +++ b/.evergreen/generate_mongosh_tasks.js @@ -0,0 +1,65 @@ +const scopes = [ + 'browser-repl', + 'browser-runtime-electron', + 'cli-repl', + 'connectivity-tests', + 'mongosh', + 'node-runtime-worker-thread', + 'service-provider-server' +]; + +const mongoshTestTasks = scopes.map(packageName => { + return { + name: `run-mongosh-${packageName}`, + tags: ['run-mongosh-integration-tests'], + depends_on: 'compile-mongosh', + commands: [ + { + func: 'install dependencies', + vars: { + NODE_LTS_NAME: 'gallium' + } + }, + { + func: 'run mongosh tests for package', + vars: { + mongosh_package: packageName + } + } + ] + }; +}); + +const compileTask = { + name: `compile-mongosh`, + tags: ['run-mongosh-integration-tests'], + commands: [ + { + func: 'install dependencies', + vars: { + NODE_LTS_NAME: 'gallium' + } + }, + { func: 'compile mongosh' } + ] +}; + +const scopeVerificationTask = { + name: `verify-mongosh-scopes`, + tags: ['run-mongosh-integration-tests'], + commands: [ + { + func: 'install dependencies', + vars: { + NODE_LTS_NAME: 'gallium' + } + }, + { func: 'run mongosh package scope test' } + ] +}; + +const tasks = [...mongoshTestTasks, compileTask, scopeVerificationTask]; + +module.exports = { + mongoshTasks: tasks +}; diff --git a/.evergreen/install-dependencies.sh b/.evergreen/install-dependencies.sh index ac9ffbd51c1..3dd3b8b708d 100644 --- a/.evergreen/install-dependencies.sh +++ b/.evergreen/install-dependencies.sh @@ -4,20 +4,15 @@ set -o errexit # Exit the script with error if any of the commands fail NVM_WINDOWS_URL="https://github.com/coreybutler/nvm-windows/releases/download/1.1.9/nvm-noinstall.zip" NVM_URL="https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh" -NODE_LTS_NAME=${NODE_LTS_NAME:-erbium} -MSVS_VERSION=${MSVS_VERSION:-2019} +NODE_LTS_NAME=${NODE_LTS_NAME:-fermium} NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts" -NPM_CACHE_DIR="${NODE_ARTIFACTS_PATH}/npm" -NPM_TMP_DIR="${NODE_ARTIFACTS_PATH}/tmp" # this needs to be explicitly exported for the nvm install below export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm" export XDG_CONFIG_HOME=${NODE_ARTIFACTS_PATH} # create node artifacts path if needed -mkdir -p ${NODE_ARTIFACTS_PATH} -mkdir -p ${NPM_CACHE_DIR} -mkdir -p "${NPM_TMP_DIR}" +mkdir -p "${NODE_ARTIFACTS_PATH}" function node_lts_to_version() { case $1 in @@ -102,22 +97,12 @@ EOT which node || echo "node not found, PATH=$PATH" which npm || echo "npm not found, PATH=$PATH" npm cache clear --force # Fixes: Cannot read properties of null (reading 'pickAlgorithm') error on windows - npm config set msvs_version ${MSVS_VERSION} - npm config set scripts-prepend-node-path true # install Node.js on Linux/MacOS else curl -o- $NVM_URL | bash [ -s "${NVM_DIR}/nvm.sh" ] && source "${NVM_DIR}/nvm.sh" nvm install --no-progress "$NODE_VERSION" - - # setup npm cache in a local directory - cat < .npmrc -devdir=${NPM_CACHE_DIR}/.node-gyp -init-module=${NPM_CACHE_DIR}/.npm-init.js -cache=${NPM_CACHE_DIR} -tmp=${NPM_TMP_DIR} -EOT fi npm install ${NPM_OPTIONS} diff --git a/.evergreen/run-mongosh-integration-tests.sh b/.evergreen/run-mongosh-integration-tests.sh index ec766a5c7ba..40ee5d08324 100644 --- a/.evergreen/run-mongosh-integration-tests.sh +++ b/.evergreen/run-mongosh-integration-tests.sh @@ -1,7 +1,21 @@ #!/bin/bash + +## Runs mongosh tests against the latest a particular build of the Node driver. +## +## Params: +## PROJECT_DIRECTORY - the directory containing the node driver source +## PROJECT_DIRECTORY - a unique identifier for the task (used in CI) +## MONGOSH_RUN_ONLY_IN_PACKAGE (optional) - a mongosh package name, without the `@mongosh` prefix. if set, +## only the tests for the provided mognosh package are run. + set -o errexit # Exit the script with error if any of the commands fail set -o xtrace # Write all commands first to stderr +if [ -z ${PROJECT_DIRECTORY+omitted} ]; then echo "PROJECT_DIRECTORY is unset" && exit 1; fi +if [ -z ${TASK_ID+omitted} ]; then echo "TASK_ID is unset" && exit 1; fi + +MONGOSH_RUN_ONLY_IN_PACKAGE=${MONGOSH_RUN_ONLY_IN_PACKAGE:-""} + source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" npm cache clear --force || true @@ -12,9 +26,13 @@ npm pack | tee npm-pack.log npm cache clear --force || true npm i -g npm@8.x || true -export TARBALL_FILENAME="$(tail -n1 npm-pack.log)" -cd /tmp -git clone --depth=10 https://github.com/mongodb-js/mongosh.git -cd mongosh -export REPLACE_PACKAGE="mongodb:${PROJECT_DIRECTORY}/${TARBALL_FILENAME}" +TARBALL_FILENAME="$(tail -n1 npm-pack.log)" + +MONGOSH_DIRECTORY="/tmp/$TASK_ID" +git clone --depth=10 https://github.com/mongodb-js/mongosh.git $MONGOSH_DIRECTORY + +cd $MONGOSH_DIRECTORY + +export DRIVER_TARBALL_PATH="${PROJECT_DIRECTORY}/${TARBALL_FILENAME}" +export MONGOSH_RUN_ONLY_IN_PACKAGE="$MONGOSH_RUN_ONLY_IN_PACKAGE" npm run test-nodedriver diff --git a/.evergreen/run-mongosh-scope-test.sh b/.evergreen/run-mongosh-scope-test.sh new file mode 100644 index 00000000000..64886f608d1 --- /dev/null +++ b/.evergreen/run-mongosh-scope-test.sh @@ -0,0 +1,16 @@ +#! /bin/bash + +if [ -z ${TASK_ID+omitted} ]; then echo "TASK_ID is unset" && exit 1; fi + +source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" + +MONGOSH_DIRECTORY="/tmp/$TASK_ID" +git clone --depth=10 https://github.com/mongodb-js/mongosh.git $MONGOSH_DIRECTORY + +cd $MONGOSH_DIRECTORY +npm i lerna +export SCOPES=$(./node_modules/lerna/cli.js ls --all --json) + +cd - + +npx mocha --config test/manual/mocharc.json test/manual/mongosh_scopes.test.ts diff --git a/.evergreen/run-serverless-tests.sh b/.evergreen/run-serverless-tests.sh index eaaacf33801..e1363fcfcaf 100755 --- a/.evergreen/run-serverless-tests.sh +++ b/.evergreen/run-serverless-tests.sh @@ -10,7 +10,7 @@ if [ -z ${MONGODB_URI+omitted} ]; then echo "MONGODB_URI is unset" && exit 1; fi if [ -z ${SERVERLESS_ATLAS_USER+omitted} ]; then echo "SERVERLESS_ATLAS_USER is unset" && exit 1; fi if [ -z ${SERVERLESS_ATLAS_PASSWORD+omitted} ]; then echo "SERVERLESS_ATLAS_PASSWORD is unset" && exit 1; fi -npm install mongodb-client-encryption@"2.4.0-alpha.2" +npm install mongodb-client-encryption@"2.4.0" npx mocha \ --config test/mocha_mongodb.json \ diff --git a/test/manual/mongosh_scopes.test.ts b/test/manual/mongosh_scopes.test.ts new file mode 100644 index 00000000000..70f9e24f104 --- /dev/null +++ b/test/manual/mongosh_scopes.test.ts @@ -0,0 +1,44 @@ +import { expect } from 'chai'; + +const expectedMongoshScopes = [ + '@mongosh/arg-parser', + '@mongosh/async-rewriter2', + '@mongosh/autocomplete', + '@mongosh/browser-repl', + '@mongosh/browser-runtime-core', + '@mongosh/browser-runtime-electron', + '@mongosh/build', + '@mongosh/cli-repl', + 'connectivity-tests', + '@mongosh/editor', + '@mongosh/errors', + '@mongosh/history', + '@mongosh/i18n', + '@mongosh/java-shell', + '@mongosh/js-multiline-to-singleline', + '@mongosh/logging', + 'mongosh', + '@mongosh/node-runtime-worker-thread', + '@mongosh/service-provider-core', + '@mongosh/service-provider-server', + '@mongosh/shell-api', + '@mongosh/shell-evaluator', + '@mongosh/snippet-manager', + '@mongosh/types', + '@mongosh/docker-build-scripts' +]; + +describe('mongosh scopes', function () { + let scopes: Array; + + before(async function () { + if (typeof process.env.SCOPES !== 'string') { + throw new Error('mongosh scopes must be set in the SCOPES environment variable'); + } + scopes = JSON.parse(process.env.SCOPES).map(({ name }) => name); + }); + + it('there are no new mongosh scopes', function () { + expect(expectedMongoshScopes).to.deep.equal(scopes); + }); +}); diff --git a/test/readme.md b/test/readme.md index 45524039b58..b92f04491db 100644 --- a/test/readme.md +++ b/test/readme.md @@ -419,6 +419,41 @@ The following steps will walk you through how to run the tests for CSFLE. To run the functional tests using the crypt shared library instead of mongocryptd, download the appropriate version of the crypt shared library for the enterprise server version [here](https://www.mongodb.com/download-center/enterprise/releases) and then set the location of it in the environment variable `CRYPT_SHARED_LIB_PATH`. +#### Testing driver changes with mongosh + +These steps require mongosh to be available locally. Clone it from Github. + +Mongosh uses a lerna monorepo. As a result, mongosh contains multiple references to the `mongodb` package +in their `package.json`s. + +Set up mongosh by following the steps in the mongosh readme. + +##### Point mongosh to the driver + +mongosh contains a script that does this. To use the script, create an environment + variable `REPLACE_PACKAGE` that contains a string in the form +`mongodb:`. The package replacement script will replace +all occurrences of `mongodb` with the local path of your driver. + +An alternative, which can be useful for +testing a release, is to first run `npm pack` on the driver. This generates a tarball containing all the code +that would be uploaded to npm if it were released. Then set the environment variable `REPLACE_PACKAGE` +with the pull path to the file. + +Once the environment variable is set, run replace package in mongosh with `npm run replace:package`. + +##### Run specific package tests + +mongosh's readme documents how to run its tests. Most likely, it isn't necessary to run all of mongosh's +tests. The mongosh readme also documents how to run tests for a particular scope. The scopes are +listed in the `generate_mongosh_tasks.js` evergreen generation script. + +For example, to run the `service-provider-server` package, run the following command in mongosh: + +```shell +lerna run test --scope @mongosh/service-provider-server +``` + #### KMIP FLE support tests 1. Install virtualenv: `pip install virtualenv`