diff --git a/common/tools/dev-tool/src/commands/run/testNodeJSInput.ts b/common/tools/dev-tool/src/commands/run/testNodeJSInput.ts index c10a6014dcb2..25bb8acc8b65 100644 --- a/common/tools/dev-tool/src/commands/run/testNodeJSInput.ts +++ b/common/tools/dev-tool/src/commands/run/testNodeJSInput.ts @@ -5,10 +5,11 @@ import { leafCommand, makeCommandInfo } from "../../framework/command"; import concurrently from "concurrently"; import { createPrinter } from "../../util/printer"; +import { isModuleProject } from "../../util/resolveProject"; import { runTestsWithProxyTool } from "../../util/testUtils"; export const commandInfo = makeCommandInfo( - "test:node-tsx-js", + "test:node-js-input", "runs the node tests using mocha with the default and the provided options; starts the proxy-tool in record and playback modes", { "no-test-proxy": { @@ -17,13 +18,31 @@ export const commandInfo = makeCommandInfo( default: false, description: "whether to run with test-proxy", }, + "use-esm-workaround": { + shortName: "uew", + kind: "boolean", + default: false, + description: + "when true, uses the `esm` npm package for tests. Otherwise uses esm4mocha if needed", + }, }, ); export default leafCommand(commandInfo, async (options) => { + const isModule = await isModuleProject(); + let esmLoaderArgs = ""; + + if (isModule === false) { + if (options["use-esm-workaround"] === false) { + esmLoaderArgs = "--loader=../../../common/tools/esm4mocha.mjs"; + } else { + esmLoaderArgs = "-r ../../../common/tools/esm-workaround -r esm"; + } + } + const reporterArgs = "--reporter ../../../common/tools/mocha-multi-reporter.js --reporter-option output=test-results.xml"; - const defaultMochaArgs = `-r source-map-support/register.js ${reporterArgs} --full-trace`; + const defaultMochaArgs = `${esmLoaderArgs} -r source-map-support/register.js ${reporterArgs} --full-trace`; const updatedArgs = options["--"]?.map((opt) => opt.includes("**") && !opt.startsWith("'") && !opt.startsWith('"') ? `"${opt}"` : opt, ); @@ -31,7 +50,7 @@ export default leafCommand(commandInfo, async (options) => { ? updatedArgs.join(" ") : '--timeout 5000000 "dist-esm/test/{,!(browser)/**/}/*.spec.js"'; const command = { - command: `c8 mocha --require tsx ${defaultMochaArgs} ${mochaArgs}`, + command: `c8 mocha ${defaultMochaArgs} ${mochaArgs}`, name: "node-tests", }; diff --git a/common/tools/dev-tool/src/commands/run/testNodeTSInput.ts b/common/tools/dev-tool/src/commands/run/testNodeTSInput.ts index f0cf66c2cbce..a7540bd5568f 100644 --- a/common/tools/dev-tool/src/commands/run/testNodeTSInput.ts +++ b/common/tools/dev-tool/src/commands/run/testNodeTSInput.ts @@ -8,7 +8,7 @@ import { runTestsWithProxyTool } from "../../util/testUtils"; import { createPrinter } from "../../util/printer"; export const commandInfo = makeCommandInfo( - "test:node-tsx-ts", + "test:node-ts-input", "runs the node tests using mocha with the default and the provided options; starts the proxy-tool in record and playback modes", { "no-test-proxy": { @@ -25,7 +25,7 @@ export default leafCommand(commandInfo, async (options) => { const reporterArgs = "--reporter ../../../common/tools/mocha-multi-reporter.js --reporter-option output=test-results.xml"; const defaultMochaArgs = `${ - isModuleProj ? "--loader=ts-node/esm " : "" + isModuleProj ? "--loader=ts-node/esm " : "-r esm " }-r ts-node/register ${reporterArgs} --full-trace`; const updatedArgs = options["--"]?.map((opt) => opt.includes("**") && !opt.startsWith("'") && !opt.startsWith('"') ? `"${opt}"` : opt,