Skip to content

Commit 1409903

Browse files
HarshaNallurujeremymengwitemple-msft
authored
[Unified Recorder] Updates the dev-tool commands to follow the new syntax (Azure#19419)
* update test commands - new syntax * TODO * readme * readme with examples * Update common/tools/dev-tool/README.md Co-authored-by: Jeremy Meng <[email protected]> * Update common/tools/dev-tool/README.md Co-authored-by: Jeremy Meng <[email protected]> * Update common/tools/dev-tool/README.md Co-authored-by: Jeremy Meng <[email protected]> * readme feedback * Update sdk/test-utils/testing-recorder-new/package.json Co-authored-by: Will Temple <[email protected]> * Update sdk/test-utils/recorder-new/package.json Co-authored-by: Will Temple <[email protected]> * Update common/tools/dev-tool/README.md Co-authored-by: Will Temple <[email protected]> * update "--" usage * simplification from Will * options["--"]?.length ? options["--"]?.join(" ") : <default> Co-authored-by: Jeremy Meng <[email protected]> Co-authored-by: Will Temple <[email protected]>
1 parent e2eea7e commit 1409903

File tree

7 files changed

+57
-32
lines changed

7 files changed

+57
-32
lines changed

common/tools/dev-tool/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,41 @@ It provides a place to centralize scripts, resources, and processes for developm
2222
- `prep` (prepare samples for local source-linked execution)
2323
- `run` (execute a sample or all samples within a directory)
2424
- `check-node-versions` (execute samples with different node versions, typically in preparation for release)
25+
- `test-proxy`
26+
- `start` (start the test-proxy tool. This requires docker.)
27+
- `wait-for-proxy-endpoint` (waits until the proxy endpoint is ready or aborts in 120 seconds, whichever happens first)
28+
- `run`
29+
30+
- `test:node-ts-input` (runs the node tests with TS input files with the default mocha configs, and concurrently runs the proxy tool in record/playback modes if it is not already active)
31+
32+
- Mocha settings added by default
33+
34+
> `-r esm -r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace`
35+
36+
- Example usage
37+
38+
```bash
39+
dev-tool run test:node-ts-input -- --timeout 1200000 'test/*.spec.ts'
40+
```
41+
- `test:node-js-input` (runs the node tests with JS input files with the default mocha configs, and concurrently runs the proxy tool in record/playback modes if it is not already active)
42+
43+
- Mocha settings added by default
44+
45+
> `-r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace`
46+
47+
- Also, calls mocha with `nyc` for code coverage
48+
49+
- Example usage
50+
51+
```bash
52+
dev-tool run test:node-js-input -- --timeout 5000000 "dist-esm/test/{,!(browser)/**/}/*.spec.js"
53+
```
54+
55+
- `test:browser` (runs the browser tests using karma, and concurrently runs the proxy tool in record/playback modes if it is not already active)
56+
- Example usage
57+
```bash
58+
dev-tool run test:browser
59+
```
2560

2661
The `dev-tool about` command will print some information about how to use the command. All commands additionally accept the `--help` argument, which will print information about the usage of that specific command. For example, to show help information for the `resolve` command above, issue the command `dev-tool package resolve --help`.
2762

common/tools/dev-tool/src/commands/run/testBrowser.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@ import { runTestsWithProxyTool } from "../../util/testUtils";
66

77
export const commandInfo = makeCommandInfo(
88
"test:browser",
9-
"runs the browser tests using karma with the default and the provided options; starts the proxy-tool in record and playback modes",
10-
{
11-
karma: {
12-
kind: "string",
13-
description: "Karma options (such as --single-run)",
14-
default: "--single-run"
15-
}
16-
}
9+
"runs the browser tests using karma with the default and the provided options; starts the proxy-tool in record and playback modes"
1710
);
1811

1912
export default leafCommand(commandInfo, async (options) => {
13+
const karmaArgs = options["--"]?.length ? options["--"]?.join(" ") : "--single-run";
2014
return runTestsWithProxyTool({
21-
command: `karma start ${options.karma}`,
15+
command: `karma start ${karmaArgs}`,
2216
name: "browser-tests"
2317
});
2418
});

common/tools/dev-tool/src/commands/run/testNodeJSInput.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@ import { runTestsWithProxyTool } from "../../util/testUtils";
66

77
export const commandInfo = makeCommandInfo(
88
"test:node-js-input",
9-
"runs the node tests using mocha with the default and the provided options; starts the proxy-tool in record and playback modes",
10-
{
11-
mocha: {
12-
kind: "string",
13-
description:
14-
"Mocha options along with the bundled test file(JS) with rollup as expected by mocha",
15-
default: '--timeout 5000000 "dist-esm/test/{,!(browser)/**/}/*.spec.js"'
16-
}
17-
}
9+
"runs the node tests using mocha with the default and the provided options; starts the proxy-tool in record and playback modes"
1810
);
1911

2012
export default leafCommand(commandInfo, async (options) => {
13+
const defaultMochaArgs =
14+
"-r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace";
15+
const mochaArgs = options["--"]?.length
16+
? options["--"]?.join(" ")
17+
: '--timeout 5000000 "dist-esm/test/{,!(browser)/**/}/*.spec.js"';
2118
return runTestsWithProxyTool({
22-
command: `nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace ${options.mocha}`,
19+
command: `nyc mocha ${defaultMochaArgs} ${mochaArgs}`,
2320
name: "node-tests"
2421
});
2522
});

common/tools/dev-tool/src/commands/run/testNodeTSInput.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@ import { runTestsWithProxyTool } from "../../util/testUtils";
66

77
export const commandInfo = makeCommandInfo(
88
"test:node-ts-input",
9-
"runs the node tests using mocha with the default and the provided options; starts the proxy-tool in record and playback modes",
10-
{
11-
mocha: {
12-
kind: "string",
13-
description:
14-
"Mocha options along with the test files(glob pattern) in TS as expected by mocha",
15-
default: '--timeout 1200000 --exclude "test/**/browser/*.spec.ts" "test/**/*.spec.ts"'
16-
}
17-
}
9+
"runs the node tests using mocha with the default and the provided options; starts the proxy-tool in record and playback modes"
1810
);
1911

2012
export default leafCommand(commandInfo, async (options) => {
13+
const defaultMochaArgs =
14+
"-r esm -r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace";
15+
const mochaArgs = options["--"]?.length
16+
? options["--"]?.join(" ")
17+
: '--timeout 1200000 --exclude "test/**/browser/*.spec.ts" "test/**/*.spec.ts"';
2118
return runTestsWithProxyTool({
22-
command: `mocha -r esm -r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace ${options.mocha}`,
19+
command: `mocha ${defaultMochaArgs} ${mochaArgs}`,
2320
name: "node-tests"
2421
});
2522
});

common/tools/dev-tool/src/util/testUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ async function shouldRunProxyTool(): Promise<boolean> {
2222
}
2323
}
2424

25-
export async function runTestsWithProxyTool(testCommandObj: concurrently.CommandObj): Promise<boolean> {
25+
export async function runTestsWithProxyTool(
26+
testCommandObj: concurrently.CommandObj
27+
): Promise<boolean> {
2628
if (
2729
await shouldRunProxyTool() // Boolean to figure out if we need to run just the mocha command or the test-proxy too
2830
) {

sdk/test-utils/recorder-new/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
2525
"integration-test:browser": "concurrently \"npm run tests:server\" \"npm run test:browser-with-proxy\" --kill-others --success first",
2626
"integration-test:node": "concurrently \"npm run tests:server\" \"npm run test:node-with-proxy\" --kill-others --success first",
27-
"test:node-with-proxy": "dev-tool run test:node-ts-input --mocha=\"--timeout 1200000 'test/*.spec.ts'\"",
27+
"test:node-with-proxy": "dev-tool run test:node-ts-input -- --timeout 1200000 \"test/*.spec.ts\"",
2828
"test:browser-with-proxy": "dev-tool run test:browser",
2929
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
3030
"tests:server": "cross-env TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\": \\\"commonjs\\\"}\" ts-node test/utils/server.ts",

sdk/test-utils/testing-recorder-new/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"extract-api": "echo skipped",
1919
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
2020
"integration-test:browser": "dev-tool run test:browser",
21-
"integration-test:node": "dev-tool run test:node-ts-input --mocha=\"--timeout 1200000 'test/*.spec.ts'\"",
21+
"integration-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 \"test/*.spec.ts\"",
2222
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
2323
"lint:fix": "eslint --no-eslintrc -c ../../.eslintrc.internal.json package.json src test --ext .ts --fix --fix-type [problem,suggestion]",
2424
"lint": "eslint --no-eslintrc -c ../../.eslintrc.internal.json package.json src test --ext .ts",

0 commit comments

Comments
 (0)