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

[EngSys] Move from ts-node to tsx for tests #28801

Merged
merged 4 commits into from
Mar 6, 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
819 changes: 422 additions & 397 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions common/tools/dev-tool/src/commands/run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { subCommand, makeCommandInfo } from "../../framework/command";
export const commandInfo = makeCommandInfo("run", "run scripts such as test:node");

export default subCommand(commandInfo, {
"test:node-tsx-ts": () => import("./testNodeTsxTS"),
mpodwysocki marked this conversation as resolved.
Show resolved Hide resolved
"test:node-tsx-js": () => import("./testNodeTsxJS"),
"test:node-ts-input": () => import("./testNodeTSInput"),
"test:node-js-input": () => import("./testNodeJSInput"),
"test:browser": () => import("./testBrowser"),
Expand Down
25 changes: 3 additions & 22 deletions common/tools/dev-tool/src/commands/run/testNodeJSInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ 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-js-input",
"test:node-tsx-js",
"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 @@ -18,39 +17,21 @@ 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 = `${esmLoaderArgs} -r source-map-support/register.js ${reporterArgs} --full-trace`;
const defaultMochaArgs = `-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 ${defaultMochaArgs} ${mochaArgs}`,
command: `c8 mocha --require tsx ${defaultMochaArgs} ${mochaArgs}`,
name: "node-tests",
};

Expand Down
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-ts-input",
"test:node-tsx-ts",
"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 Down
45 changes: 45 additions & 0 deletions common/tools/dev-tool/src/commands/run/testNodeTsxJS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license

import { leafCommand, makeCommandInfo } from "../../framework/command";

import concurrently from "concurrently";
import { createPrinter } from "../../util/printer";
import { runTestsWithProxyTool } from "../../util/testUtils";

export const commandInfo = makeCommandInfo(
"test:node-js-input",
mpodwysocki marked this conversation as resolved.
Show resolved Hide resolved
"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": {
shortName: "ntp",
kind: "boolean",
default: false,
description: "whether to run with test-proxy",
},
},
);

export default leafCommand(commandInfo, async (options) => {
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 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}`,
name: "node-tests",
};

if (!options["no-test-proxy"]) {
return runTestsWithProxyTool(command);
}

createPrinter("test-info").info("Running tests without test-proxy");
await concurrently([command]).result;
return true;
});
44 changes: 44 additions & 0 deletions common/tools/dev-tool/src/commands/run/testNodeTsxTS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license

import concurrently from "concurrently";
import { leafCommand, makeCommandInfo } from "../../framework/command";
import { runTestsWithProxyTool } from "../../util/testUtils";
import { createPrinter } from "../../util/printer";

export const commandInfo = makeCommandInfo(
"test:node-tsx-ts",
"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": {
shortName: "ntp",
kind: "boolean",
default: false,
description: "whether to disable launching test-proxy",
},
},
);

export default leafCommand(commandInfo, async (options) => {
const reporterArgs =
"--reporter ../../../common/tools/mocha-multi-reporter.js --reporter-option output=test-results.xml";
const defaultMochaArgs = `${reporterArgs} --full-trace`;
const updatedArgs = options["--"]?.map((opt) =>
opt.includes("**") && !opt.startsWith("'") && !opt.startsWith('"') ? `"${opt}"` : opt,
);
const mochaArgs = updatedArgs?.length
? updatedArgs.join(" ")
: '--timeout 1200000 --exclude "test/**/browser/*.spec.ts" "test/**/*.spec.ts"';
const command = {
command: `mocha --require tsx ${defaultMochaArgs} ${mochaArgs}`,
mpodwysocki marked this conversation as resolved.
Show resolved Hide resolved
name: "node-tests",
};

if (!options["no-test-proxy"]) {
return runTestsWithProxyTool(command);
}

createPrinter("test-info").info("Running tests without test-proxy");
await concurrently([command]).result;
return true;
});
17 changes: 7 additions & 10 deletions sdk/appconfiguration/app-configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"build:samples": "echo Obsolete.",
"build": "npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local",
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf dist dist-* types *.tgz *.log",
"clean": "rimraf --glob dist dist-* types *.tgz *.log",
"execute:samples": "dev-tool samples run samples-dev",
"extract-api": "tsc -p . && api-extractor run --local",
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
Expand All @@ -53,12 +53,12 @@
"pack": "npm pack 2>&1",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"integration-test:browser": "npm run build:test && dev-tool run test:browser",
"integration-test:node": "dev-tool run test:node-js-input --use-esm-workaround=true -- --timeout 180000 'dist-esm/test/**/*.spec.js'",
"integration-test:node": "dev-tool run test:node-tsx-js -- --timeout 180000 'dist-esm/test/**/*.spec.js'",
"test:browser": "npm run clean && npm run build:test && npm run unit-test:browser",
"test:node": "npm run clean && npm run build:test && npm run unit-test:node",
"test": "npm run test:node && npm run test:browser",
"unit-test:browser": "dev-tool run test:browser",
"unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'",
"unit-test:node": "dev-tool run test:node-tsx-ts -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'",
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
},
"engines": {
Expand Down Expand Up @@ -105,10 +105,10 @@
"@types/mocha": "^10.0.0",
"@types/node": "^18.0.0",
"@types/sinon": "^17.0.0",
"c8": "^8.0.0",
"chai": "^4.2.0",
"dotenv": "^16.0.0",
"eslint": "^8.0.0",
"esm": "^3.2.18",
"karma": "^6.2.0",
"karma-chrome-launcher": "^3.0.0",
"karma-coverage": "^2.0.0",
Expand All @@ -120,13 +120,10 @@
"karma-sourcemap-loader": "^0.3.8",
"mocha": "^10.0.0",
"nock": "^12.0.3",
"c8": "^8.0.0",
"rimraf": "^3.0.0",
"rimraf": "^5.0.5",
"sinon": "^17.0.0",
"ts-node": "^10.0.0",
"typescript": "~5.3.3",
"uglify-js": "^3.4.9",
"cross-env": "^7.0.2"
"tsx": "^4.7.1",
"typescript": "~5.3.3"
},
"//sampleConfiguration": {
"productName": "Azure App Configuration",
Expand Down
15 changes: 7 additions & 8 deletions sdk/eventgrid/eventgrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@
"build:test": "tsc -p . && dev-tool run bundle",
"build": "npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local",
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf dist dist-browser dist-esm dist-test temp types *.tgz *.log",
"clean": "rimraf --glob dist dist-browser dist-esm dist-test temp types *.tgz *.log",
"execute:samples": "dev-tool samples run samples-dev",
"extract-api": "tsc -p . && api-extractor run --local",
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"generate:client": "autorest --typescript ./swagger/README.md && node ./scripts/setPathToEmpty.js",
"integration-test:browser": "dev-tool run test:browser",
"integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 \"dist-esm/test/**/*.spec.js\"",
"integration-test:node": "dev-tool run test:node-tsx-js -- --timeout 5000000 \"dist-esm/test/**/*.spec.js\"",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js",
Expand All @@ -85,7 +85,7 @@
"test:node": "npm run clean && npm run build:test && npm run unit-test:node",
"test": "npm run clean && npm run build:test && npm run unit-test",
"unit-test:browser": "dev-tool run test:browser",
"unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 'test/**/*.spec.ts'",
"unit-test:node": "dev-tool run test:node-tsx-ts -- --timeout 1200000 'test/**/*.spec.ts'",
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
},
"sideEffects": false,
Expand All @@ -112,6 +112,7 @@
"@types/node": "^18.0.0",
"@types/sinon": "^17.0.0",
"@types/uuid": "^8.0.0",
"c8": "^8.0.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.2",
Expand All @@ -127,12 +128,10 @@
"karma-mocha-reporter": "^2.2.5",
"karma-sourcemap-loader": "^0.3.8",
"mocha": "^10.0.0",
"c8": "^8.0.0",
"rimraf": "^3.0.0",
"rimraf": "^5.0.5",
"sinon": "^17.0.0",
"source-map-support": "^0.5.9",
"ts-node": "^10.0.0",
"typescript": "~5.3.3",
"esm": "^3.2.18"
"tsx": "^4.7.1",
"typescript": "~5.3.3"
}
}