Skip to content

Commit

Permalink
[dev-tool] revert old files back to ts-node (#28844)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR

- @azure/dev-tool

### Issues associated with this PR


### Describe the problem that is addressed by this PR

Reverts back to the original for the testing ts-node for JS and TS.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_

- #28801

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [x] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
mpodwysocki authored Mar 9, 2024
1 parent e7b4723 commit 85409f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
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

0 comments on commit 85409f5

Please sign in to comment.