From da5d215a43340551bd6db523f4682c2a8fcdb74a Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 13 Nov 2024 14:21:31 -0700 Subject: [PATCH] remove unused dependencies and tooling --- .mocharc.json | 2 - package-lock.json | 165 +---------------- package.json | 5 +- test/tools/chai-addons.js | 10 - test/tools/mongodb_reporter.js | 329 --------------------------------- 5 files changed, 2 insertions(+), 509 deletions(-) delete mode 100644 test/tools/chai-addons.js delete mode 100644 test/tools/mongodb_reporter.js diff --git a/.mocharc.json b/.mocharc.json index 90685c7..4c05ee3 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,9 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/mocharc.json", - "require": ["source-map-support/register", "test/tools/chai-addons.js"], "extension": ["ts"], "recursive": true, "failZero": true, - "reporter": "test/tools/mongodb_reporter.js", "color": true } diff --git a/package-lock.json b/package-lock.json index 29ea80b..96470c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,14 +17,11 @@ "@mongodb-js/zstd": "^1.2.0", "@typescript-eslint/eslint-plugin": "^8.11.0", "chai": "^4.5.0", - "chai-subset": "^1.6.0", "eslint": "^9.14.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.2.1", "mocha": "^10.8.2", - "prettier": "^3.3.3", - "sinon-chai": "^3.7.0", - "source-map-support": "^0.5.21" + "prettier": "^3.3.3" }, "engines": { "node": ">= 16.20.1" @@ -319,55 +316,6 @@ "url": "https://opencollective.com/unts" } }, - "node_modules/@sinonjs/commons": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz", - "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==", - "dev": true, - "peer": true, - "dependencies": { - "type-detect": "4.0.8" - } - }, - "node_modules/@sinonjs/commons/node_modules/type-detect": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true, - "peer": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/@sinonjs/fake-timers": { - "version": "13.0.5", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-13.0.5.tgz", - "integrity": "sha512-36/hTbH2uaWuGVERyC6da9YwGWnzUZXuPro/F2LfsdOsLnCojz/iSH8MxUt/FD2S5XBSVPhmArFUXcpCQ2Hkiw==", - "dev": true, - "peer": true, - "dependencies": { - "@sinonjs/commons": "^3.0.1" - } - }, - "node_modules/@sinonjs/samsam": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.2.tgz", - "integrity": "sha512-v46t/fwnhejRSFTGqbpn9u+LQ9xJDse10gNnPgAcxgdoCDMXj/G2asWAC/8Qs+BAZDicX+MNZouXT1A7c83kVw==", - "dev": true, - "peer": true, - "dependencies": { - "@sinonjs/commons": "^3.0.1", - "lodash.get": "^4.4.2", - "type-detect": "^4.1.0" - } - }, - "node_modules/@sinonjs/text-encoding": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.3.tgz", - "integrity": "sha512-DE427ROAphMQzU4ENbliGYrBSYPXF+TtLg9S8vzeA+OF4ZKzoDdzfL8sxuMUGS/lgRhM6j1URSk9ghf7Xo1tyA==", - "dev": true, - "peer": true - }, "node_modules/@types/estree": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", @@ -727,12 +675,6 @@ "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, - "node_modules/buffer-from": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true - }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -772,15 +714,6 @@ "node": ">=4" } }, - "node_modules/chai-subset": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/chai-subset/-/chai-subset-1.6.0.tgz", - "integrity": "sha512-K3d+KmqdS5XKW5DWPd5sgNffL3uxdDe+6GdnJh3AYPhwnBGRY5urfvfcbRtWIvvpz+KxkL9FeBB6MZewLUNwug==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -1591,13 +1524,6 @@ "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, - "node_modules/just-extend": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-6.2.0.tgz", - "integrity": "sha512-cYofQu2Xpom82S6qD778jBDpwvvy39s1l/hrYij2u9AMdQcGRpaBu6kY4mVhuno5kJVi1DAz4aiphA2WI1/OAw==", - "dev": true, - "peer": true - }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -1635,13 +1561,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash.get": { - "version": "4.4.2", - "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", - "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==", - "dev": true, - "peer": true - }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -1804,20 +1723,6 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, - "node_modules/nise": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/nise/-/nise-6.1.1.tgz", - "integrity": "sha512-aMSAzLVY7LyeM60gvBS423nBmIPP+Wy7St7hsb+8/fc1HmeoHJfLO8CKse4u3BtOZvQLJghYPI2i/1WZrEj5/g==", - "dev": true, - "peer": true, - "dependencies": { - "@sinonjs/commons": "^3.0.1", - "@sinonjs/fake-timers": "^13.0.1", - "@sinonjs/text-encoding": "^0.7.3", - "just-extend": "^6.2.0", - "path-to-regexp": "^8.1.0" - } - }, "node_modules/node-addon-api": { "version": "8.2.2", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.2.2.tgz", @@ -1921,16 +1826,6 @@ "node": ">=8" } }, - "node_modules/path-to-regexp": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", - "integrity": "sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ==", - "dev": true, - "peer": true, - "engines": { - "node": ">=16" - } - }, "node_modules/pathval": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", @@ -2151,64 +2046,6 @@ "node": ">=8" } }, - "node_modules/sinon": { - "version": "19.0.2", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-19.0.2.tgz", - "integrity": "sha512-euuToqM+PjO4UgXeLETsfQiuoyPXlqFezr6YZDFwHR3t4qaX0fZUe1MfPMznTL5f8BWrVS89KduLdMUsxFCO6g==", - "dev": true, - "peer": true, - "dependencies": { - "@sinonjs/commons": "^3.0.1", - "@sinonjs/fake-timers": "^13.0.2", - "@sinonjs/samsam": "^8.0.1", - "diff": "^7.0.0", - "nise": "^6.1.1", - "supports-color": "^7.2.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/sinon" - } - }, - "node_modules/sinon-chai": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/sinon-chai/-/sinon-chai-3.7.0.tgz", - "integrity": "sha512-mf5NURdUaSdnatJx3uhoBOrY9dtL19fiOtAdT1Azxg3+lNJFiuN0uzaU3xX1LeAfL17kHQhTAJgpsfhbMJMY2g==", - "dev": true, - "peerDependencies": { - "chai": "^4.0.0", - "sinon": ">=4.0.0" - } - }, - "node_modules/sinon/node_modules/diff": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-7.0.0.tgz", - "integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==", - "dev": true, - "peer": true, - "engines": { - "node": ">=0.3.1" - } - }, - "node_modules/source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/source-map-support": { - "version": "0.5.21", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", - "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", - "dev": true, - "dependencies": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - } - }, "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", diff --git a/package.json b/package.json index 5f5c4ae..73bf94c 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,11 @@ "@mongodb-js/zstd": "^1.2.0", "@typescript-eslint/eslint-plugin": "^8.11.0", "chai": "^4.5.0", - "chai-subset": "^1.6.0", "eslint": "^9.14.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.2.1", "mocha": "^10.8.2", - "prettier": "^3.3.3", - "sinon-chai": "^3.7.0", - "source-map-support": "^0.5.21" + "prettier": "^3.3.3" }, "engines": { "node": ">= 16.20.1" diff --git a/test/tools/chai-addons.js b/test/tools/chai-addons.js deleted file mode 100644 index 3cf0974..0000000 --- a/test/tools/chai-addons.js +++ /dev/null @@ -1,10 +0,0 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ -/* eslint-disable strict */ - -'use strict'; -// configure chai -const chai = require('chai'); -chai.use(require('sinon-chai')); -chai.use(require('chai-subset')); - -chai.config.truncateThreshold = 0; diff --git a/test/tools/mongodb_reporter.js b/test/tools/mongodb_reporter.js deleted file mode 100644 index 30026d6..0000000 --- a/test/tools/mongodb_reporter.js +++ /dev/null @@ -1,329 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable strict */ -/* eslint-disable @typescript-eslint/no-var-requires */ -//@ts-check - -'use strict'; -const mocha = require('mocha'); -const chalk = require('chalk'); - -chalk.level = 3; - -const { - EVENT_RUN_BEGIN, - EVENT_RUN_END, - EVENT_TEST_FAIL, - EVENT_TEST_PASS, - EVENT_SUITE_BEGIN, - EVENT_SUITE_END, - EVENT_TEST_PENDING, - EVENT_TEST_BEGIN, - EVENT_TEST_END -} = mocha.Runner.constants; - -const fs = require('fs'); -const os = require('os'); - -/** - * @typedef {object} MongoMochaSuiteExtension - * @property {Date} timestamp - suite start date - * @property {string} stdout - capture of stdout - * @property {string} stderr - capture of stderr - * @property {MongoMochaTest} test - capture of stderr - * @typedef {object} MongoMochaTestExtension - * @property {Date} startTime - test start date - * @property {Date} endTime - test end date - * @property {number} elapsedTime - difference between end and start - * @property {Error} [error] - The possible error from a test - * @property {true} [skipped] - Set if test was skipped - * @typedef {MongoMochaSuiteExtension & Mocha.Suite} MongoMochaSuite - * @typedef {MongoMochaTestExtension & Mocha.Test} MongoMochaTest - */ - -// 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} - */ -class MongoDBMochaReporter extends mocha.reporters.Spec { - constructor(runner) { - super(runner); - /** @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)); - - process.on('SIGINT', () => this.end(true)); - } - start() {} - - end(ctrlC) { - try { - if (ctrlC) console.log('emergency exit!'); - const output = { testSuites: [] }; - - for (const [id, [className, { suite }]] of [...this.suites.entries()].entries()) { - let totalSuiteTime = 0; - let testCases = []; - let failureCount = 0; - - const tests = /** @type {MongoMochaTest[]}*/ (suite.tests); - for (const test of tests) { - let time = test.elapsedTime / 1000; - time = Number.isNaN(time) ? 0 : time; - - totalSuiteTime += time; - failureCount += test.state === 'failed' ? 1 : 0; - - /** @type {string | Date | number} */ - let startTime = test.startTime; - startTime = startTime ? startTime.toISOString() : 0; - - /** @type {string | Date | number} */ - let endTime = test.endTime; - endTime = endTime ? endTime.toISOString() : 0; - - let error = test.error; - let failure = error - ? { - type: error.constructor.name, - message: error.message, - stack: error.stack - } - : undefined; - - let skipped = !!test.skipped; - - testCases.push({ - name: test.title, - className, - time, - startTime, - endTime, - skipped, - failure - }); - } - - /** @type {string | Date | number} */ - let timestamp = suite.timestamp; - timestamp = timestamp ? timestamp.toISOString().split('.')[0] : ''; - - output.testSuites.push({ - package: suite.file.includes('integration') ? 'Integration' : 'Unit', - id, - name: className, - timestamp, - hostname: os.hostname(), - tests: suite.tests.length, - failures: failureCount, - errors: '0', - time: totalSuiteTime, - testCases, - stdout: suite.stdout, - stderr: suite.stderr - }); - } - - if (!this.xunitWritten) { - fs.writeFileSync('xunit.xml', outputToXML(output), { encoding: 'utf8' }); - } - this.xunitWritten = true; - console.log(chalk.bold('wrote xunit.xml')); - } catch (error) { - console.error(chalk.red(`Failed to output xunit report! ${error}`)); - } finally { - if (ctrlC) process.exit(1); - } - } - - /** - * @param {MongoMochaSuite} suite - */ - onSuite(suite) { - 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) - }); - } else { - console.warn(`${chalk.yellow('WARNING:')} ${suite.fullTitle()} started twice`); - } - } - - /** - * @param {MongoMochaSuite} suite - */ - suiteEnd(suite) { - if (suite.root) return; - const currentSuite = this.suites.get(suite.fullTitle()); - if (!currentSuite) { - console.error('Suite never started >:('); - process.exit(1); - } - if (currentSuite.stdout || currentSuite.stderr) { - suite.stdout = currentSuite.stdout.unhook(); - suite.stderr = currentSuite.stderr.unhook(); - delete currentSuite.stdout; - delete currentSuite.stderr; - } - } - - /** - * @param {MongoMochaTest} test - */ - onTest(test) { - test.startTime = new Date(); - } - - /** - * @param {MongoMochaTest} test - */ - testEnd(test) { - test.endTime = new Date(); - test.elapsedTime = Number(test.endTime) - Number(test.startTime); - } - - /** - * @param {MongoMochaTest} test - */ - pass(test) { - if (REPORT_TO_STDIO) console.log(chalk.green(`✔ ${test.fullTitle()}`)); - } - - /** - * @param {MongoMochaTest} test - * @param {Error} error - */ - fail(test, error) { - if (REPORT_TO_STDIO) console.log(chalk.red(`⨯ ${test.fullTitle()} -- ${error.message}`)); - test.error = error; - } - - /** - * @param {MongoMochaTest & {skipReason?: string}} test - */ - pending(test) { - if (REPORT_TO_STDIO) console.log(chalk.cyan(`↬ ${test.fullTitle()}`)); - if (typeof test.skipReason === 'string') { - console.log(chalk.cyan(`${' '.repeat(test.titlePath().length + 1)}↬ ${test.skipReason}`)); - } - test.skipped = true; - } -} - -module.exports = MongoDBMochaReporter; - -function replaceIllegalXMLCharacters(string) { - // prettier-ignore - return String(string) - .split('"').join('"') - .split('<').join('﹤') - .split('>').join('﹥') - .split('&').join('﹠'); -} - -const ANSI_ESCAPE_REGEX = - // eslint-disable-next-line no-control-regex - /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; -function outputToXML(output) { - function cdata(str) { - return `') - .join('\\]\\]\\>')}]]>`; - } - - function makeTag(name, attributes, selfClose, content) { - const attributesString = Object.entries(attributes || {}) - .map(([k, v]) => `${k}="${replaceIllegalXMLCharacters(v)}"`) - .join(' '); - let tag = `<${name}${attributesString ? ' ' + attributesString : ''}`; - if (selfClose) return tag + '/>\n'; - else tag += '>'; - if (content) return tag + content + ``; - return tag; - } - - let s = - '\n\n\n'; - - for (const suite of output.testSuites) { - s += makeTag('testsuite', { - package: suite.package, - id: suite.id, - name: suite.name, - timestamp: suite.timestamp, - hostname: suite.hostname, - tests: suite.tests, - failures: suite.failures, - errors: suite.errors, - time: suite.time - }); - s += '\n\t' + makeTag('properties') + '\n'; // can put metadata here? - for (const test of suite.testCases) { - s += - '\t' + - makeTag( - 'testcase', - { - name: test.name, - classname: test.className, - time: test.time, - start: test.startTime, - end: test.endTime - }, - !test.failure && !test.skipped - ); - if (test.failure) { - s += - '\n\t\t' + - makeTag('failure', { type: test.failure.type }, false, cdata(test.failure.stack)) + - '\n'; - s += `\t\n`; - } - if (test.skipped) { - s += makeTag('skipped', {}, true); - s += `\t\n`; - } - } - s += '\t' + makeTag('system-out', {}, false, cdata(suite.stdout)) + '\n'; - s += '\t' + makeTag('system-err', {}, false, cdata(suite.stderr)) + '\n'; - s += `\n`; - } - - return s + '\n'; -}