Skip to content
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

[dev-tool] revert old files back to ts-node #28844

Merged
merged 1 commit into from
Mar 9, 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
25 changes: 22 additions & 3 deletions common/tools/dev-tool/src/commands/run/testNodeJSInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -17,21 +18,39 @@ 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,
);
const mochaArgs = updatedArgs?.length
? 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",
};

Expand Down
4 changes: 2 additions & 2 deletions common/tools/dev-tool/src/commands/run/testNodeTSInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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,
Expand Down