Skip to content

Commit

Permalink
Update Web CI to use data dir under Agent.TempDirectory (microsoft#20074
Browse files Browse the repository at this point in the history
)

### Description
Update Web CI to use data dir under Agent.TempDirectory

This change fixes the random failure caused by unstable access to karma
temp directory (which is under AppData\Local\Temp) on CI pipeline
  • Loading branch information
fs-eire authored Mar 26, 2024
1 parent 166de01 commit bc78d21
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 6 additions & 3 deletions web/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const karmaPlugins = args['karma-plugins'] || undefined;
const timeoutMocha = args['timeout-mocha'] || 60000;
const forceLocalHost = !!args['force-localhost'];

// user data directory; will be passed to the Edge/Chrome/ChromeCanary/Firefox launchers
const userDataDir = args['user-data-dir'];
// parse chromium flags
let chromiumFlags = args['chromium-flags'];
if (!chromiumFlags) {
Expand Down Expand Up @@ -87,9 +89,10 @@ module.exports = function(config) {
listenAddress,
customLaunchers: {
// Chromium-based browsers
EdgeTest: {base: 'Edge', flags: chromiumFlags},
ChromeTest: {base: 'Chrome', flags: chromiumFlags},
ChromeCanaryTest: {base: 'ChromeCanary', flags: chromiumFlags},
EdgeTest: {base: 'Edge', flags: chromiumFlags, edgeDataDir: userDataDir},
ChromeTest: {base: 'Chrome', flags: chromiumFlags, chromeDataDir: userDataDir},
ChromeCanaryTest: {base: 'ChromeCanary', flags: chromiumFlags, chromeDataDir: userDataDir},
FirefoxTest: {base: 'Firefox', profile: userDataDir},

//
// ==== BrowserStack browsers ====
Expand Down
6 changes: 6 additions & 0 deletions web/script/test-runner-cli-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Options:
--no-sandbox This flag will be passed to Chrome.
Sometimes Chrome need this flag to work together with Karma.
--user-data-dir=<...> This flag will be passed to browsers to specify the user data directory.
--chromium-flags=<...> This flag will be passed to Chrome and Edge browsers. Can be used multiple times.
Examples:
Expand Down Expand Up @@ -195,6 +196,7 @@ export interface TestRunnerCliArgs {
webnnOptions?: InferenceSession.WebNNExecutionProviderOption;
globalEnvFlags?: Test.Options['globalEnvFlags'];
noSandbox?: boolean;
userDataDir?: string;
chromiumFlags: string[];
}

Expand Down Expand Up @@ -477,6 +479,9 @@ export function parseTestRunnerCliArgs(cmdlineArgs: string[]): TestRunnerCliArgs
// Option: --no-sandbox
const noSandbox = !!args['no-sandbox'];

// Option: --user-data-dir
const userDataDir = args['user-data-dir'];

// parse chromium flags
let chromiumFlags = args['chromium-flags'];
if (!chromiumFlags) {
Expand Down Expand Up @@ -515,6 +520,7 @@ export function parseTestRunnerCliArgs(cmdlineArgs: string[]): TestRunnerCliArgs
wasmOptions,
globalEnvFlags,
noSandbox,
userDataDir,
chromiumFlags
};
}
5 changes: 4 additions & 1 deletion web/script/test-runner-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ async function main() {
karmaArgs.push('--log-level debug');
}
karmaArgs.push(`--bundle-mode=${args.bundleMode}`);
if (args.userDataDir) {
karmaArgs.push(`--user-data-dir="${args.userDataDir}"`);
}
karmaArgs.push(...chromiumFlags.map(flag => `--chromium-flags=${flag}`));
if (browser.startsWith('Edge')) {
// There are currently 2 Edge browser launchers:
Expand Down Expand Up @@ -671,7 +674,7 @@ async function main() {
case 'edge':
return 'EdgeTest';
case 'firefox':
return 'Firefox';
return 'FirefoxTest';
case 'electron':
return 'Electron';
case 'safari':
Expand Down

0 comments on commit bc78d21

Please sign in to comment.