Skip to content
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
35 changes: 35 additions & 0 deletions common/tools/dev-tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,41 @@ It provides a place to centralize scripts, resources, and processes for developm
- `prep` (prepare samples for local source-linked execution)
- `run` (execute a sample or all samples within a directory)
- `check-node-versions` (execute samples with different node versions, typically in preparation for release)
- `test-proxy`
- `start` (start the test-proxy tool. This requires docker.)
- `wait-for-proxy-endpoint` (waits until the proxy endpoint is ready or aborts in 120 seconds, whichever happens first)
- `run`

- `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)

- Mocha settings added by default

> `-r esm -r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace`

- Example usage

```bash
dev-tool run test:node-ts-input -- --timeout 1200000 'test/*.spec.ts'
```
- `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)

- Mocha settings added by default

> `-r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace`

- Also, calls mocha with `nyc` for code coverage

- Example usage

```bash
dev-tool run test:node-js-input -- --timeout 5000000 "dist-esm/test/{,!(browser)/**/}/*.spec.js"
```

- `test:browser` (runs the browser tests using karma, and concurrently runs the proxy tool in record/playback modes if it is not already active)
- Example usage
```bash
dev-tool run test:browser
```

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`.

Expand Down
12 changes: 3 additions & 9 deletions common/tools/dev-tool/src/commands/run/testBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ import { runTestsWithProxyTool } from "../../util/testUtils";

export const commandInfo = makeCommandInfo(
"test:browser",
"runs the browser tests using karma with the default and the provided options; starts the proxy-tool in record and playback modes",
{
karma: {
kind: "string",
description: "Karma options (such as --single-run)",
default: "--single-run"
}
}
"runs the browser tests using karma with the default and the provided options; starts the proxy-tool in record and playback modes"
);

export default leafCommand(commandInfo, async (options) => {
const karmaArgs = options["--"]?.length ? options["--"]?.join(" ") : "--single-run";
return runTestsWithProxyTool({
command: `karma start ${options.karma}`,
command: `karma start ${karmaArgs}`,
name: "browser-tests"
});
});
17 changes: 7 additions & 10 deletions common/tools/dev-tool/src/commands/run/testNodeJSInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ import { runTestsWithProxyTool } from "../../util/testUtils";

export const commandInfo = makeCommandInfo(
"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",
{
mocha: {
kind: "string",
description:
"Mocha options along with the bundled test file(JS) with rollup as expected by mocha",
default: '--timeout 5000000 "dist-esm/test/{,!(browser)/**/}/*.spec.js"'
}
}
"runs the node tests using mocha with the default and the provided options; starts the proxy-tool in record and playback modes"
);

export default leafCommand(commandInfo, async (options) => {
const defaultMochaArgs =
"-r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace";
const mochaArgs = options["--"]?.length
? options["--"]?.join(" ")
: '--timeout 5000000 "dist-esm/test/{,!(browser)/**/}/*.spec.js"';
return runTestsWithProxyTool({
command: `nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace ${options.mocha}`,
command: `nyc mocha ${defaultMochaArgs} ${mochaArgs}`,
name: "node-tests"
});
});
17 changes: 7 additions & 10 deletions common/tools/dev-tool/src/commands/run/testNodeTSInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ import { runTestsWithProxyTool } from "../../util/testUtils";

export const commandInfo = makeCommandInfo(
"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",
{
mocha: {
kind: "string",
description:
"Mocha options along with the test files(glob pattern) in TS as expected by mocha",
default: '--timeout 1200000 --exclude "test/**/browser/*.spec.ts" "test/**/*.spec.ts"'
}
}
"runs the node tests using mocha with the default and the provided options; starts the proxy-tool in record and playback modes"
);

export default leafCommand(commandInfo, async (options) => {
const defaultMochaArgs =
"-r esm -r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace";
const mochaArgs = options["--"]?.length
? options["--"]?.join(" ")
: '--timeout 1200000 --exclude "test/**/browser/*.spec.ts" "test/**/*.spec.ts"';
return runTestsWithProxyTool({
command: `mocha -r esm -r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace ${options.mocha}`,
command: `mocha ${defaultMochaArgs} ${mochaArgs}`,
name: "node-tests"
});
});
4 changes: 3 additions & 1 deletion common/tools/dev-tool/src/util/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ async function shouldRunProxyTool(): Promise<boolean> {
}
}

export async function runTestsWithProxyTool(testCommandObj: concurrently.CommandObj): Promise<boolean> {
export async function runTestsWithProxyTool(
testCommandObj: concurrently.CommandObj
): Promise<boolean> {
if (
await shouldRunProxyTool() // Boolean to figure out if we need to run just the mocha command or the test-proxy too
) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/test-utils/recorder-new/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "concurrently \"npm run tests:server\" \"npm run test:browser-with-proxy\" --kill-others --success first",
"integration-test:node": "concurrently \"npm run tests:server\" \"npm run test:node-with-proxy\" --kill-others --success first",
"test:node-with-proxy": "dev-tool run test:node-ts-input --mocha=\"--timeout 1200000 'test/*.spec.ts'\"",
"test:node-with-proxy": "dev-tool run test:node-ts-input -- --timeout 1200000 \"test/*.spec.ts\"",
"test:browser-with-proxy": "dev-tool run test:browser",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"tests:server": "cross-env TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\": \\\"commonjs\\\"}\" ts-node test/utils/server.ts",
Expand Down
2 changes: 1 addition & 1 deletion sdk/test-utils/testing-recorder-new/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"extract-api": "echo skipped",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "dev-tool run test:browser",
"integration-test:node": "dev-tool run test:node-ts-input --mocha=\"--timeout 1200000 'test/*.spec.ts'\"",
"integration-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 \"test/*.spec.ts\"",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "eslint --no-eslintrc -c ../../.eslintrc.internal.json package.json src test --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint --no-eslintrc -c ../../.eslintrc.internal.json package.json src test --ext .ts",
Expand Down