Skip to content

Commit

Permalink
[dev-tool] ensure browsers are installed for playwright browser tests (
Browse files Browse the repository at this point in the history
…Azure#28329)

and update the `unit-test:browser` NPM scripts of core-util and
core-rest-pipeline
  • Loading branch information
jeremymeng authored Jan 23, 2024
1 parent 4884552 commit 234a31f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
30 changes: 23 additions & 7 deletions common/tools/dev-tool/src/commands/run/testVitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { leafCommand, makeCommandInfo } from "../../framework/command";
import { runTestsWithProxyTool } from "../../util/testUtils";
import { createPrinter } from "../../util/printer";

const log = createPrinter("test:vitest");

export const commandInfo = makeCommandInfo(
"test:vitest",
"runs tests using vitest with the default and the provided options; starts the proxy-tool in record and playback modes",
Expand All @@ -16,7 +18,7 @@ export const commandInfo = makeCommandInfo(
default: false,
description: "whether to disable launching test-proxy",
},
"browser": {
browser: {
shortName: "br",
kind: "boolean",
default: false,
Expand All @@ -25,24 +27,38 @@ export const commandInfo = makeCommandInfo(
},
);

async function playwrightInstall(): Promise<void> {
const { result } = concurrently([
{
command: "npx playwright install",
name: "playwright install",
},
]);

await result;
log.info("playwright browsers installed");
}

export default leafCommand(commandInfo, async (options) => {
const args = options["browser"] ? "-c vitest.browser.config.mts": "";
if (options["browser"]) {
await playwrightInstall();
}

const args = options["browser"] ? "-c vitest.browser.config.mts" : "";
const updatedArgs = options["--"]?.map((opt) =>
opt.includes("**") && !opt.startsWith("'") && !opt.startsWith('"') ? `"${opt}"` : opt,
);
const vitestArgs = updatedArgs?.length
? updatedArgs.join(" ")
: '';
const vitestArgs = updatedArgs?.length ? updatedArgs.join(" ") : "";
const command = {
command: `vitest ${args} ${vitestArgs}`,
name: "vi-tests",
name: "vitest",
};

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

createPrinter("test-info").info("Running vitest without test-proxy");
log.info("Running vitest without test-proxy");
await concurrently([command]).result;
return true;
});
2 changes: 1 addition & 1 deletion sdk/core/core-rest-pipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
"test:node": "npm run unit-test:node && npm run integration-test:node",
"test": "npm run test:node && npm run test:browser",
"unit-test:browser": "playwright install && dev-tool run test:vitest --no-test-proxy=true --browser=true",
"unit-test:browser": "dev-tool run test:vitest --no-test-proxy=true --browser=true",
"unit-test:node": "dev-tool run test:vitest --no-test-proxy=true",
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
},
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
"test:node": "npm run unit-test:node && npm run integration-test:node",
"test": "npm run test:node && npm run test:browser",
"unit-test:browser": "playwright install && dev-tool run test:vitest --no-test-proxy=true --browser=true",
"unit-test:browser": "dev-tool run test:vitest --no-test-proxy=true --browser=true",
"unit-test:node": "dev-tool run test:vitest --no-test-proxy=true",
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
},
Expand Down

0 comments on commit 234a31f

Please sign in to comment.