Skip to content

chore: convert mocha hooks cjs exports to esm exports #4135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"require": [
"source-map-support/register",
"ts-node/register",
"test/tools/runner/chai-addons.js",
"test/tools/runner/chai_addons.ts",
"test/tools/runner/hooks/unhandled_checker.ts"
],
"extension": [
Expand Down
2 changes: 1 addition & 1 deletion test/mocha_mongodb.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"require": [
"source-map-support/register",
"ts-node/register",
"test/tools/runner/chai-addons.js",
"test/tools/runner/chai_addons.ts",
"test/tools/runner/hooks/configuration.ts",
"test/tools/runner/hooks/unhandled_checker.ts",
"test/tools/runner/hooks/leak_checker.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
/* eslint-disable @typescript-eslint/no-var-requires */

import chai = require('chai');

// configure chai
const chai = require('chai');
chai.use(require('sinon-chai'));
chai.use(require('chai-subset'));
chai.use(require('../spec-runner/matcher').default);
Expand Down
14 changes: 5 additions & 9 deletions test/tools/runner/hooks/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const testSkipBeforeEachHook = async function () {
* @param skippedTests - define list of tests to skip
* @returns
*/
const skipBrokenAuthTestBeforeEachHook = function (
export const skipBrokenAuthTestBeforeEachHook = function (
{ skippedTests }: { skippedTests: string[] } = { skippedTests: [] }
) {
return function () {
Expand Down Expand Up @@ -222,12 +222,8 @@ export function installNodeDNSWorkaroundHooks() {
}
}

module.exports = {
mochaHooks: {
beforeAll: [beforeAllPluginImports, testConfigBeforeHook],
beforeEach: [testSkipBeforeEachHook],
afterAll: [cleanUpMocksAfterHook]
},
skipBrokenAuthTestBeforeEachHook,
installNodeDNSWorkaroundHooks
export const mochaHooks = {
beforeAll: [beforeAllPluginImports, testConfigBeforeHook],
beforeEach: [testSkipBeforeEachHook],
afterAll: [cleanUpMocksAfterHook]
};
2 changes: 1 addition & 1 deletion test/tools/runner/hooks/leak_checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ const socketLeakCheckAfterEach: Mocha.AsyncFunc = async function socketLeakCheck
const beforeAll = TRACE_SOCKETS ? [socketLeakCheckBeforeAll] : [];
const beforeEach = [leakCheckerBeforeEach];
const afterEach = [leakCheckerAfterEach, ...(TRACE_SOCKETS ? [socketLeakCheckAfterEach] : [])];
module.exports = { mochaHooks: { beforeAll, beforeEach, afterEach } };
export const mochaHooks = { beforeAll, beforeEach, afterEach };
2 changes: 1 addition & 1 deletion test/tools/runner/hooks/unhandled_checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ function afterEachUnhandled() {
unhandled.unknown = [];
}

module.exports = { mochaHooks: { beforeEach: beforeEachUnhandled, afterEach: afterEachUnhandled } };
export const mochaHooks = { beforeEach: beforeEachUnhandled, afterEach: afterEachUnhandled };