Skip to content

Commit

Permalink
[test] enable mocha parallel test execution
Browse files Browse the repository at this point in the history
- add an option `--no-parallel` to dev-tool to opt out parallel test execution

- currently mocha-junit-reporter isn't working with --parallel
michaelleeallen/mocha-junit-reporter#140
  • Loading branch information
jeremymeng committed Dec 5, 2023
1 parent d652007 commit a17016a
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 11 deletions.
10 changes: 9 additions & 1 deletion common/tools/dev-tool/src/commands/run/testNodeJSInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export const commandInfo = makeCommandInfo(
default: false,
description: "whether to run with test-proxy",
},
"no-parallel": {
shortName: "np",
kind: "boolean",
default: false,
description: "whether to disable Mocha parallel test execution",
},
},
);

Expand All @@ -25,7 +31,9 @@ export default leafCommand(commandInfo, async (options) => {
(await isModuleProject())
? "-r source-map-support/register.js"
: "-r ../../../common/tools/esm-workaround -r esm -r source-map-support/register"
} --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace`;
} --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace ${
options["no-parallel"] ? "" : "--parallel"
}`;
const updatedArgs = options["--"]?.map((opt) =>
opt.includes("**") && !opt.startsWith("'") && !opt.startsWith('"') ? `"${opt}"` : opt,
);
Expand Down
10 changes: 9 additions & 1 deletion common/tools/dev-tool/src/commands/run/testNodeTSInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ export const commandInfo = makeCommandInfo(
default: false,
description: "whether to disable launching test-proxy",
},
"no-parallel": {
shortName: "np",
kind: "boolean",
default: false,
description: "whether to disable Mocha parallel test execution",
},
},
);

export default leafCommand(commandInfo, async (options) => {
const isModuleProj = await isModuleProject();
const defaultMochaArgs = `${
isModuleProj ? "" : "-r esm "
}-r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace`;
}-r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace ${
options["no-parallel"] ? "" : "--parallel"
}`;
const updatedArgs = options["--"]?.map((opt) =>
opt.includes("**") && !opt.startsWith("'") && !opt.startsWith('"') ? `"${opt}"` : opt,
);
Expand Down
2 changes: 1 addition & 1 deletion common/tools/dev-tool/src/util/testProxyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export async function startTestProxy(): Promise<TestProxy> {
export async function isProxyToolActive(): Promise<boolean> {
try {
const response = await fetch(
`http://localhost:${process.env.TEST_PROXY_HTTP_PORT ?? 5000}/info/available`
`http://localhost:${process.env.TEST_PROXY_HTTP_PORT ?? 5000}/info/available`,
);

if (!response.ok) {
Expand Down
2 changes: 1 addition & 1 deletion common/tools/eslint-plugin-azure-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"integration-test:browser": "echo skipped",
"integration-test:node": "echo skipped",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"unit-test:node": "mocha --require source-map-support/register --timeout 10000 --full-trace --recursive dist/tests",
"unit-test:node": "mocha --require source-map-support/register --timeout 10000 --full-trace --parallel --recursive dist/tests",
"unit-test:browser": "echo skipped",
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"test": "npm run clean && npm run build:test && npm run unit-test"
Expand Down
4 changes: 3 additions & 1 deletion common/tools/mocha-multi-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class MultiReporter {
// Invoking the spec reporter with the runner
new Mocha.reporters.Spec(runner);
// Invoking mocha-junit-reporter to generate XML reports of test summaries for CI
new MochaJUnitReporter(runner);
// new MochaJUnitReporter(runner, {
// mochaFile: "./test-results.[hash].xml",
// });
}
}

Expand Down
4 changes: 3 additions & 1 deletion sdk/core/core-rest-pipeline/test/defaultRetryPolicy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { assert } from "chai";
import { assert, use as chaiUse } from "chai";
import chaiPromises from "chai-as-promised";
chaiUse(chaiPromises);
import * as sinon from "sinon";
import { RestError, SendRequest, createPipelineRequest, defaultRetryPolicy } from "../src";
import { DEFAULT_RETRY_POLICY_COUNT } from "../src/constants";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { assert } from "chai";
import { assert, use as chaiUse } from "chai";
import chaiPromises from "chai-as-promised";
chaiUse(chaiPromises);
import * as sinon from "sinon";
import {
PipelineResponse,
Expand Down
4 changes: 3 additions & 1 deletion sdk/core/core-rest-pipeline/test/formDataPolicy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { assert } from "chai";
import { assert, use as chaiUse } from "chai";
import chaiPromises from "chai-as-promised";
chaiUse(chaiPromises);
import * as sinon from "sinon";
import {
PipelineResponse,
Expand Down
4 changes: 3 additions & 1 deletion sdk/core/core-rest-pipeline/test/multipartPolicy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { createHttpHeaders } from "../src/httpHeaders";
import { PipelineRequest, PipelineResponse, SendRequest } from "../src/interfaces";
import { createPipelineRequest } from "../src/pipelineRequest";
import { multipartPolicy } from "../src/policies/multipartPolicy";
import { assert } from "chai";
import { assert, use as chaiUse } from "chai";
import chaiPromises from "chai-as-promised";
chaiUse(chaiPromises);
import { PipelineRequestOptions } from "../src/pipelineRequest";
import { stringToUint8Array } from "@azure/core-util";
import { assertBodyMatches } from "./util";
Expand Down
4 changes: 3 additions & 1 deletion sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { assert } from "chai";
import { assert, use as chaiUse } from "chai";
import chaiPromises from "chai-as-promised";
chaiUse(chaiPromises);
import * as sinon from "sinon";
import {
PipelineRequest,
Expand Down
2 changes: 1 addition & 1 deletion sdk/test-utils/recorder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 -- --timeout 1200000 \"test/*.spec.ts\"",
"test:node-with-proxy": "dev-tool run test:node-ts-input --no-parallel=true -- --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

0 comments on commit a17016a

Please sign in to comment.