diff --git a/.evergreen/config.in.yml b/.evergreen/config.in.yml index e49bbe31b3d..aef9e96f78b 100644 --- a/.evergreen/config.in.yml +++ b/.evergreen/config.in.yml @@ -28,81 +28,44 @@ functions: params: directory: "src" shallow_clone: true # speed things up by limiting clone depth to 100 + # Make an evergreen expansion file with dynamic values - - command: shell.exec + - command: subprocess.exec params: working_dir: "src" - script: | - # Get the current unique version of this checkout - if [ "${is_patch}" = "true" ]; then - CURRENT_VERSION=$(git describe)-patch-${version_id} - else - CURRENT_VERSION=latest - fi - - export DRIVERS_TOOLS="$(pwd)/../drivers-tools" - - export PROJECT_DIRECTORY="$(pwd)" - export MONGO_ORCHESTRATION_HOME="$DRIVERS_TOOLS/.evergreen/orchestration" - export MONGODB_BINARIES="$DRIVERS_TOOLS/mongodb/bin" - export UPLOAD_BUCKET="${project}" - - # fix paths on windows - if [ "Windows_NT" = "$OS" ]; then - export DRIVERS_TOOLS=$(cygpath -m -a $DRIVERS_TOOLS) - export MONGO_ORCHESTRATION_HOME=$(cygpath -m -a $MONGO_ORCHESTRATION_HOME) - export MONGODB_BINARIES=$(cygpath -m -a $MONGODB_BINARIES) - export PROJECT_DIRECTORY=$(cygpath -m -a $PROJECT_DIRECTORY) - fi - - cat < expansion.yml - CURRENT_VERSION: "$CURRENT_VERSION" - DRIVERS_TOOLS: "$DRIVERS_TOOLS" - MONGO_ORCHESTRATION_HOME: "$MONGO_ORCHESTRATION_HOME" - MONGODB_BINARIES: "$MONGODB_BINARIES" - UPLOAD_BUCKET: "$UPLOAD_BUCKET" - PROJECT_DIRECTORY: "$PROJECT_DIRECTORY" - PREPARE_SHELL: | - set -o errexit - set -o xtrace - export DRIVERS_TOOLS="$DRIVERS_TOOLS" - export MONGO_ORCHESTRATION_HOME="$MONGO_ORCHESTRATION_HOME" - export MONGODB_BINARIES="$MONGODB_BINARIES" - export UPLOAD_BUCKET="$UPLOAD_BUCKET" - export PROJECT_DIRECTORY="$PROJECT_DIRECTORY" - - export TMPDIR="$MONGO_ORCHESTRATION_HOME/db" - export PATH="$MONGODB_BINARIES:$PATH" - export PROJECT="${project}" - EOT - # See what we've done - cat expansion.yml + binary: bash + env: + is_patch: ${is_patch} + project: ${project} + args: + - .evergreen/prepare-shell.sh # Load the expansion file to make an evergreen variable with the current unique version - command: expansions.update params: file: src/expansion.yml - "prepare resources": - - command: shell.exec - params: - script: | - ${PREPARE_SHELL} - git clone --depth 1 https://github.com/mongodb-labs/drivers-evergreen-tools.git $DRIVERS_TOOLS - echo "{ \"releases\": { \"default\": \"$MONGODB_BINARIES\" }}" > $MONGO_ORCHESTRATION_HOME/orchestration.config - "bootstrap mongo-orchestration": - - command: shell.exec + - command: subprocess.exec params: - script: | - ${PREPARE_SHELL} - MONGODB_VERSION=${VERSION} TOPOLOGY=${TOPOLOGY} \ - AUTH=${AUTH} SSL=${SSL} \ - ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \ - REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \ - LOAD_BALANCER=${LOAD_BALANCER} \ - COMPRESSOR=${COMPRESSOR} \ - bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh + binary: bash + add_expansions_to_env: true + env: + # The following is the settings for how we want to launch mongodb + MONGODB_VERSION: ${VERSION} + TOPOLOGY: ${TOPOLOGY} + AUTH: ${AUTH} + SSL: ${SSL} + ORCHESTRATION_FILE: ${ORCHESTRATION_FILE} + REQUIRE_API_VERSION: ${REQUIRE_API_VERSION} + LOAD_BALANCER: ${LOAD_BALANCER} + COMPRESSOR: ${COMPRESSOR} + # These are paths necessary for launching mongodb + DRIVERS_TOOLS: ${DRIVERS_TOOLS} + MONGODB_BINARIES: ${MONGODB_BINARIES} + args: + - src/.evergreen/run-orchestration.sh + # run-orchestration generates expansion file with the MONGODB_URI for the cluster - command: expansions.update params: @@ -175,7 +138,7 @@ functions: MONGODB_URI="${MONGODB_URI}" \ AUTH=${AUTH} SSL=${SSL} TEST_CSFLE=true \ MONGODB_API_VERSION="${MONGODB_API_VERSION}" \ - NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} NO_EXIT=${NO_EXIT|1} \ + NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} \ bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh "run serverless tests": @@ -244,7 +207,6 @@ functions: MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}" \ TOPOLOGY="${TOPOLOGY}" \ SKIP_DEPS=${SKIP_DEPS|1} \ - NO_EXIT=${NO_EXIT|1} \ LOAD_BALANCER="${LOAD_BALANCER}" \ bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh @@ -265,7 +227,6 @@ functions: TOPOLOGY="${TOPOLOGY}" \ COMPRESSOR="${COMPRESSOR}" \ SKIP_DEPS=${SKIP_DEPS|1} \ - NO_EXIT=${NO_EXIT|1} \ bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh "run lint checks": @@ -959,7 +920,6 @@ task_groups: setup_group_timeout_secs: 1800 # 30 minutes setup_group: - func: "fetch source" - - func: "prepare resources" - command: shell.exec params: shell: "bash" @@ -991,7 +951,6 @@ task_groups: pre: - func: "fetch source" - - func: "prepare resources" - func: "windows fix" - func: "fix absolute paths" - func: "make files executable" diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 94f7416fa90..c1ec7116520 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -13,79 +13,36 @@ functions: params: directory: src shallow_clone: true - - command: shell.exec + - command: subprocess.exec params: working_dir: src - script: | - # Get the current unique version of this checkout - if [ "${is_patch}" = "true" ]; then - CURRENT_VERSION=$(git describe)-patch-${version_id} - else - CURRENT_VERSION=latest - fi - - export DRIVERS_TOOLS="$(pwd)/../drivers-tools" - - export PROJECT_DIRECTORY="$(pwd)" - export MONGO_ORCHESTRATION_HOME="$DRIVERS_TOOLS/.evergreen/orchestration" - export MONGODB_BINARIES="$DRIVERS_TOOLS/mongodb/bin" - export UPLOAD_BUCKET="${project}" - - # fix paths on windows - if [ "Windows_NT" = "$OS" ]; then - export DRIVERS_TOOLS=$(cygpath -m -a $DRIVERS_TOOLS) - export MONGO_ORCHESTRATION_HOME=$(cygpath -m -a $MONGO_ORCHESTRATION_HOME) - export MONGODB_BINARIES=$(cygpath -m -a $MONGODB_BINARIES) - export PROJECT_DIRECTORY=$(cygpath -m -a $PROJECT_DIRECTORY) - fi - - cat < expansion.yml - CURRENT_VERSION: "$CURRENT_VERSION" - DRIVERS_TOOLS: "$DRIVERS_TOOLS" - MONGO_ORCHESTRATION_HOME: "$MONGO_ORCHESTRATION_HOME" - MONGODB_BINARIES: "$MONGODB_BINARIES" - UPLOAD_BUCKET: "$UPLOAD_BUCKET" - PROJECT_DIRECTORY: "$PROJECT_DIRECTORY" - PREPARE_SHELL: | - set -o errexit - set -o xtrace - export DRIVERS_TOOLS="$DRIVERS_TOOLS" - export MONGO_ORCHESTRATION_HOME="$MONGO_ORCHESTRATION_HOME" - export MONGODB_BINARIES="$MONGODB_BINARIES" - export UPLOAD_BUCKET="$UPLOAD_BUCKET" - export PROJECT_DIRECTORY="$PROJECT_DIRECTORY" - - export TMPDIR="$MONGO_ORCHESTRATION_HOME/db" - export PATH="$MONGODB_BINARIES:$PATH" - export PROJECT="${project}" - EOT - # See what we've done - cat expansion.yml + binary: bash + env: + is_patch: ${is_patch} + project: ${project} + args: + - .evergreen/prepare-shell.sh - command: expansions.update params: file: src/expansion.yml - prepare resources: - - command: shell.exec - params: - script: > - ${PREPARE_SHELL} - - git clone --depth 1 https://github.com/mongodb-labs/drivers-evergreen-tools.git $DRIVERS_TOOLS - - echo "{ \"releases\": { \"default\": \"$MONGODB_BINARIES\" }}" > - $MONGO_ORCHESTRATION_HOME/orchestration.config bootstrap mongo-orchestration: - - command: shell.exec + - command: subprocess.exec params: - script: | - ${PREPARE_SHELL} - MONGODB_VERSION=${VERSION} TOPOLOGY=${TOPOLOGY} \ - AUTH=${AUTH} SSL=${SSL} \ - ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \ - REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \ - LOAD_BALANCER=${LOAD_BALANCER} \ - COMPRESSOR=${COMPRESSOR} \ - bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh + binary: bash + add_expansions_to_env: true + env: + MONGODB_VERSION: ${VERSION} + TOPOLOGY: ${TOPOLOGY} + AUTH: ${AUTH} + SSL: ${SSL} + ORCHESTRATION_FILE: ${ORCHESTRATION_FILE} + REQUIRE_API_VERSION: ${REQUIRE_API_VERSION} + LOAD_BALANCER: ${LOAD_BALANCER} + COMPRESSOR: ${COMPRESSOR} + DRIVERS_TOOLS: ${DRIVERS_TOOLS} + MONGODB_BINARIES: ${MONGODB_BINARIES} + args: + - src/.evergreen/run-orchestration.sh - command: expansions.update params: file: mo-expansion.yml @@ -155,7 +112,7 @@ functions: MONGODB_URI="${MONGODB_URI}" \ AUTH=${AUTH} SSL=${SSL} TEST_CSFLE=true \ MONGODB_API_VERSION="${MONGODB_API_VERSION}" \ - NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} NO_EXIT=${NO_EXIT|1} \ + NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} \ bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh run serverless tests: - command: timeout.update @@ -220,7 +177,6 @@ functions: MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}" \ TOPOLOGY="${TOPOLOGY}" \ SKIP_DEPS=${SKIP_DEPS|1} \ - NO_EXIT=${NO_EXIT|1} \ LOAD_BALANCER="${LOAD_BALANCER}" \ bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh run-compression-tests: @@ -240,7 +196,6 @@ functions: TOPOLOGY="${TOPOLOGY}" \ COMPRESSOR="${COMPRESSOR}" \ SKIP_DEPS=${SKIP_DEPS|1} \ - NO_EXIT=${NO_EXIT|1} \ bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh run lint checks: - command: subprocess.exec @@ -1230,10 +1185,6 @@ tasks: REQUIRE_API_VERSION: '1' AUTH: auth - func: bootstrap kms servers - - func: run tests - vars: - MONGODB_API_VERSION: '1' - NO_EXIT: '' - name: test-atlas-connectivity tags: - atlas-connect @@ -2253,7 +2204,6 @@ task_groups: setup_group_timeout_secs: 1800 setup_group: - func: fetch source - - func: prepare resources - command: shell.exec params: shell: bash @@ -2284,7 +2234,6 @@ task_groups: - .serverless pre: - func: fetch source - - func: prepare resources - func: windows fix - func: fix absolute paths - func: make files executable diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index 94db50a0149..0db51968a1c 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -91,13 +91,13 @@ BASE_TASKS.push({ } }, { func: 'bootstrap kms servers' }, - { - func: 'run tests', - vars: { - MONGODB_API_VERSION: '1', - NO_EXIT: '' - } - } + // TODO(NODE-4642): Fix versioned API tests + // { + // func: 'run tests', + // vars: { + // MONGODB_API_VERSION: '1' + // } + // } ] }); diff --git a/.evergreen/prepare-shell.sh b/.evergreen/prepare-shell.sh new file mode 100644 index 00000000000..c566a8615ab --- /dev/null +++ b/.evergreen/prepare-shell.sh @@ -0,0 +1,64 @@ +#! /usr/bin/env bash + +set -o xtrace +set -o errexit + +# This script prepares a shell to run the remaining scripts in this folder +# It MUST be kept idempotent! It will overwrite the orchestration config and expansion.yml file upon every run +# and it will only clone drivers-tools if they do not exist one directory above our driver src + +PROJECT_DIRECTORY="$(pwd)" +DRIVERS_TOOLS=$(cd .. && echo "$(pwd)/drivers-tools") +MONGO_ORCHESTRATION_HOME="$DRIVERS_TOOLS/.evergreen/orchestration" +MONGODB_BINARIES="$DRIVERS_TOOLS/mongodb/bin" +UPLOAD_BUCKET="$PROJECT" + +if [ "Windows_NT" = "${OS:-notWindows}" ]; then + # fix paths on windows + DRIVERS_TOOLS=$(cygpath -m -a "$DRIVERS_TOOLS") + MONGO_ORCHESTRATION_HOME=$(cygpath -m -a "$MONGO_ORCHESTRATION_HOME") + MONGODB_BINARIES=$(cygpath -m -a "$MONGODB_BINARIES") + PROJECT_DIRECTORY=$(cygpath -m -a "$PROJECT_DIRECTORY") +fi + +export PROJECT_DIRECTORY +export DRIVERS_TOOLS +export MONGO_ORCHESTRATION_HOME +export MONGODB_BINARIES + +export TMPDIR="$MONGO_ORCHESTRATION_HOME/db" +export PATH="$MONGODB_BINARIES:$PATH" + +if [ ! -d "$DRIVERS_TOOLS" ]; then + # Only clone driver tools if it does not exist + git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git" "${DRIVERS_TOOLS}" +fi + +cat < "$MONGO_ORCHESTRATION_HOME/orchestration.config" +{ + "releases": { + "default": "$MONGODB_BINARIES" + } +} +EOT + +cat < expansion.yml +DRIVERS_TOOLS: "$DRIVERS_TOOLS" +MONGO_ORCHESTRATION_HOME: "$MONGO_ORCHESTRATION_HOME" +MONGODB_BINARIES: "$MONGODB_BINARIES" +UPLOAD_BUCKET: "$UPLOAD_BUCKET" +PROJECT_DIRECTORY: "$PROJECT_DIRECTORY" +PREPARE_SHELL: | + set -o errexit + set -o xtrace + export DRIVERS_TOOLS="$DRIVERS_TOOLS" + export MONGO_ORCHESTRATION_HOME="$MONGO_ORCHESTRATION_HOME" + export MONGODB_BINARIES="$MONGODB_BINARIES" + export UPLOAD_BUCKET="$UPLOAD_BUCKET" + export PROJECT_DIRECTORY="$PROJECT_DIRECTORY" + export TMPDIR="$MONGO_ORCHESTRATION_HOME/db" + export PATH="$MONGODB_BINARIES:$PATH" + export PROJECT="${PROJECT}" +EOT +# See what we've done +cat expansion.yml diff --git a/.evergreen/run-orchestration.sh b/.evergreen/run-orchestration.sh new file mode 100644 index 00000000000..74cea23b0cb --- /dev/null +++ b/.evergreen/run-orchestration.sh @@ -0,0 +1,33 @@ +#! /usr/bin/env bash + +# This is a thin wrapper around drivers-tools run orchestration meant to print each of the configuration settings we make use of +# Additionally it ensures the downloaded binaries are in the PATH for the script to find (namely, the legacy shell for server set up) + +export MONGODB_VERSION=${VERSION} +echo "MONGODB_VERSION=${VERSION}" + +export TOPOLOGY=${TOPOLOGY} +echo "TOPOLOGY=${TOPOLOGY}" + +export AUTH=${AUTH} +echo "AUTH=${AUTH}" + +export SSL=${SSL} +echo "SSL=${SSL}" + +export ORCHESTRATION_FILE=${ORCHESTRATION_FILE} +echo "ORCHESTRATION_FILE=${ORCHESTRATION_FILE}" + +export REQUIRE_API_VERSION=${REQUIRE_API_VERSION} +echo "REQUIRE_API_VERSION=${REQUIRE_API_VERSION}" + +export LOAD_BALANCER=${LOAD_BALANCER} +echo "LOAD_BALANCER=${LOAD_BALANCER}" + +export COMPRESSOR=${COMPRESSOR} +echo "COMPRESSOR=${COMPRESSOR}" + +export PATH="$MONGODB_BINARIES:$PATH" +echo "MONGODB_BINARIES=${MONGODB_BINARIES}" + +bash "${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh" diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 8054ea3c3d1..39f55b6da1d 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -9,16 +9,12 @@ set -o errexit # Exit the script with error if any of the commands fail # MARCH Machine Architecture. Defaults to lowercase uname -m # TEST_NPM_SCRIPT Script to npm run. Defaults to "integration-coverage" # SKIP_DEPS Skip installing dependencies -# NO_EXIT Don't exit early from tests that leak resources # TEST_CSFLE Set to enforce running csfle tests AUTH=${AUTH:-noauth} MONGODB_URI=${MONGODB_URI:-} TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-check:integration-coverage} COMPRESSOR=${COMPRESSOR:-} -if [[ -z "${NO_EXIT}" ]]; then - TEST_NPM_SCRIPT="$TEST_NPM_SCRIPT -- --exit" -fi # ssl setup SSL=${SSL:-nossl} @@ -68,5 +64,4 @@ export MONGODB_URI=${MONGODB_URI} export LOAD_BALANCER=${LOAD_BALANCER} export TEST_CSFLE=${TEST_CSFLE} export COMPRESSOR=${COMPRESSOR} -# Do not add quotes, due to the way NO_EXIT is handled -npm run ${TEST_NPM_SCRIPT} +npm run "${TEST_NPM_SCRIPT}" diff --git a/.gitignore b/.gitignore index a09f6b91902..43e6877bad0 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ pids *.heapsnapshot *.cpuprofile *.heapprofile +*.dylib +*.so test*.* output etc/docs/template/.hugo_build.lock @@ -29,6 +31,7 @@ public/ .idea/ test_boot/ t.js +tmp.json .DS_Store test/benchmarks/performance-data .nyc_output/ @@ -69,6 +72,8 @@ output serverless-expansion.yml serverless.env +expansion.yml +mo-expansion.yml lb-expansion.yml lb.env diff --git a/test/integration/node-specific/examples/transactions.test.js b/test/integration/node-specific/examples/transactions.test.js index 7f331c7c48c..af774ddeabd 100644 --- a/test/integration/node-specific/examples/transactions.test.js +++ b/test/integration/node-specific/examples/transactions.test.js @@ -1,22 +1,13 @@ 'use strict'; -const setupDatabase = require('../../shared').setupDatabase; -const MongoClient = require('../../../../src').MongoClient; +const { MongoClient } = require('../../../../src'); + +// Yes, we are shadowing a global here but we are not actually ever printing anything in this file +// This just so the examples can use console.log to make for nice copy pasting +const console = { log() {} }; describe('examples(transactions):', function () { let client; - let log; - - before(async function () { - await setupDatabase(this.configuration); - log = console.log; - console.log = () => {}; - }); - - after(function () { - console.log = log; - log = undefined; - }); beforeEach(async function () { client = await this.configuration.newClient().connect(); diff --git a/test/integration/retryable-reads/retryable_reads.spec.prose.test.ts b/test/integration/retryable-reads/retryable_reads.spec.prose.test.ts index af6f9cbed4e..98c96a399f6 100644 --- a/test/integration/retryable-reads/retryable_reads.spec.prose.test.ts +++ b/test/integration/retryable-reads/retryable_reads.spec.prose.test.ts @@ -34,8 +34,6 @@ describe('Retryable Reads Spec Prose', () => { { maxPoolSize: 1, retryReads: true, monitorCommands: true } ); - console.log(client.options); - testCollection = client.db('retryable-reads-prose').collection('pool-clear-retry'); await testCollection.drop().catch(() => null); await testCollection.insertMany([{ test: 1 }, { test: 2 }]); diff --git a/test/tools/reporter/mongodb_reporter.js b/test/tools/reporter/mongodb_reporter.js index bddb4dd56b6..0fef35bf8e3 100644 --- a/test/tools/reporter/mongodb_reporter.js +++ b/test/tools/reporter/mongodb_reporter.js @@ -20,6 +20,23 @@ const { const fs = require('fs'); const os = require('os'); +const print = message => fs.writeSync(2, Buffer.from(`${message}\n`, 'utf8')); + +const catchErr = fn => { + return (...args) => { + try { + fn(...args); + } catch (reporterError) { + print('\n'); + print('FATAL: Mongodb Mocha Reporter encountered an error\n'); + print(`name: ${reporterError.name}`); + print(`stack: ${reporterError.stack}`); + print('\n'); + process.exit(1); + } + }; +}; + /** * @typedef {object} MongoMochaSuiteExtension * @property {Date} timestamp - suite start date @@ -39,25 +56,6 @@ const os = require('os'); // Turn this on if you have to debug this custom reporter! let REPORT_TO_STDIO = false; -function captureStream(stream) { - var oldWrite = stream.write; - var buf = ''; - stream.write = function (chunk) { - buf += chunk.toString(); // chunk is a String or Buffer - oldWrite.apply(stream, arguments); - }; - - return { - unhook: function unhook() { - stream.write = oldWrite; - return buf; - }, - captured: function () { - return buf; - } - }; -} - /** * @param {Mocha.Runner} runner * @this {any} @@ -68,23 +66,52 @@ class MongoDBMochaReporter extends mocha.reporters.Spec { /** @type {Map} */ this.suites = new Map(); this.xunitWritten = false; - runner.on(EVENT_RUN_BEGIN, () => this.start()); - runner.on(EVENT_RUN_END, () => this.end()); - runner.on(EVENT_SUITE_BEGIN, suite => this.onSuite(suite)); - runner.on(EVENT_TEST_BEGIN, test => this.onTest(test)); - runner.on(EVENT_TEST_PASS, test => this.pass(test)); - runner.on(EVENT_TEST_FAIL, (test, error) => this.fail(test, error)); - runner.on(EVENT_TEST_PENDING, test => this.pending(test)); - runner.on(EVENT_SUITE_END, suite => this.suiteEnd(suite)); - runner.on(EVENT_TEST_END, test => this.testEnd(test)); + runner.on( + EVENT_RUN_BEGIN, + catchErr(() => this.start()) + ); + runner.on( + EVENT_RUN_END, + catchErr(() => this.end()) + ); + runner.on( + EVENT_SUITE_BEGIN, + catchErr(suite => this.onSuite(suite)) + ); + runner.on( + EVENT_TEST_BEGIN, + catchErr(test => this.onTest(test)) + ); + runner.on( + EVENT_TEST_PASS, + catchErr(test => this.pass(test)) + ); + runner.on( + EVENT_TEST_FAIL, + catchErr((test, error) => this.fail(test, error)) + ); + runner.on( + EVENT_TEST_PENDING, + catchErr(test => this.pending(test)) + ); + runner.on( + EVENT_SUITE_END, + catchErr(suite => this.suiteEnd(suite)) + ); + runner.on( + EVENT_TEST_END, + catchErr(test => this.testEnd(test)) + ); process.on('SIGINT', () => this.end(true)); } + start() {} end(ctrlC) { try { if (ctrlC) console.log('emergency exit!'); + /** @type {{ testSuites: any[] }}*/ const output = { testSuites: [] }; for (const [id, [className, { suite }]] of [...this.suites.entries()].entries()) { @@ -135,7 +162,7 @@ class MongoDBMochaReporter extends mocha.reporters.Spec { timestamp = timestamp ? timestamp.toISOString().split('.')[0] : ''; output.testSuites.push({ - package: suite.file.includes('integration') ? 'Integration' : 'Unit', + package: suite.file && suite.file.includes('integration') ? 'Integration' : 'Unit', id, name: className, timestamp, @@ -144,9 +171,7 @@ class MongoDBMochaReporter extends mocha.reporters.Spec { failures: failureCount, errors: '0', time: totalSuiteTime, - testCases, - stdout: suite.stdout, - stderr: suite.stderr + testCases }); } @@ -169,11 +194,7 @@ class MongoDBMochaReporter extends mocha.reporters.Spec { if (suite.root) return; if (!this.suites.has(suite.fullTitle())) { suite.timestamp = new Date(); - this.suites.set(suite.fullTitle(), { - suite, - stdout: captureStream(process.stdout), - stderr: captureStream(process.stderr) - }); + this.suites.set(suite.fullTitle(), { suite }); } else { throw new Error(`${suite.fullTitle()} started twice`); } @@ -316,8 +337,8 @@ function outputToXML(output) { s += `\t\n`; } } - s += '\t' + makeTag('system-out', {}, false, cdata(suite.stdout)) + '\n'; - s += '\t' + makeTag('system-err', {}, false, cdata(suite.stderr)) + '\n'; + s += '\t' + makeTag('system-out', {}, false, 'none') + '\n'; + s += '\t' + makeTag('system-err', {}, false, 'none') + '\n'; s += `\n`; }