Skip to content

Commit 74492ab

Browse files
authored
[js/webgpu] use Headless for webgpu test by default (microsoft#19702)
### Description use Chromium Headless for webgpu test by default. Still use normal Chromium with window when debug=true or perfMode=true. Use the [`--headless=new`](https://developer.chrome.com/docs/chromium/new-headless) mode. ### Motivation and Context try to use a more stable way to launch npm tests to avoid a "chrome not found" issue in pipeline, which may potentially caused by windowed application.
1 parent 0ce2bd8 commit 74492ab

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

web/karma.conf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ module.exports = function(config) {
8686
hostname,
8787
listenAddress,
8888
customLaunchers: {
89-
// the following flags are used to make sure Edge on CI agents to initialize WebGPU correctly.
89+
// Chromium-based browsers
9090
EdgeTest: {base: 'Edge', flags: chromiumFlags},
9191
ChromeTest: {base: 'Chrome', flags: chromiumFlags},
92-
ChromeTestHeadless: {base: 'ChromeHeadless', flags: chromiumFlags},
9392
ChromeCanaryTest: {base: 'ChromeCanary', flags: chromiumFlags},
93+
9494
//
9595
// ==== BrowserStack browsers ====
9696
//

web/script/test-runner-cli.ts

+7-22
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,13 @@ async function main() {
542542
npmlog.info('TestRunnerCli.Run', '(4/4) Running karma to start test runner...');
543543
const webgpu = args.backends.indexOf('webgpu') > -1;
544544
const webnn = args.backends.indexOf('webnn') > -1;
545-
const browser = getBrowserNameFromEnv(
546-
args.env,
547-
args.bundleMode === 'perf' ? 'perf' :
548-
args.debug ? 'debug' :
549-
'test',
550-
webgpu);
545+
const browser = getBrowserNameFromEnv(args.env);
551546
const karmaArgs = ['karma', 'start', `--browsers ${browser}`];
552547
const chromiumFlags = ['--enable-features=SharedArrayBuffer', ...args.chromiumFlags];
548+
if (args.bundleMode === 'dev' && !args.debug) {
549+
// use headless for 'test' mode (when 'perf' and 'debug' are OFF)
550+
chromiumFlags.push('--headless=new');
551+
}
553552
if (args.debug) {
554553
karmaArgs.push('--log-level info --timeout-mocha 9999999');
555554
chromiumFlags.push('--remote-debugging-port=9333');
@@ -662,10 +661,10 @@ async function main() {
662661
fs.writeJSONSync(path.join(TEST_ROOT, './testdata-config.json'), config);
663662
}
664663

665-
function getBrowserNameFromEnv(env: TestRunnerCliArgs['env'], mode: 'debug'|'perf'|'test', webgpu: boolean) {
664+
function getBrowserNameFromEnv(env: TestRunnerCliArgs['env']) {
666665
switch (env) {
667666
case 'chrome':
668-
return selectChromeBrowser(mode, webgpu);
667+
return 'ChromeTest';
669668
case 'edge':
670669
return 'EdgeTest';
671670
case 'firefox':
@@ -680,20 +679,6 @@ async function main() {
680679
throw new Error(`env "${env}" not supported.`);
681680
}
682681
}
683-
684-
function selectChromeBrowser(mode: 'debug'|'perf'|'test', webgpu: boolean) {
685-
if (webgpu) {
686-
return 'ChromeTest';
687-
} else {
688-
switch (mode) {
689-
case 'debug':
690-
case 'perf':
691-
return 'ChromeTest';
692-
default:
693-
return 'ChromeTestHeadless';
694-
}
695-
}
696-
}
697682
}
698683

699684
void main();

0 commit comments

Comments
 (0)