Skip to content

Commit 3105fcb

Browse files
pfaffeDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[testing] Correctly pass chromeBinary to karma
Karma's chrome launcher respects the CHROME_BIN env var to configure the Chrome binary to launch, and launches the system's chrome if unset, which is currently the case. We don't want to pollute the environment vars for passing settings around, so we instead subclass the Chrome launcher to use the correct default chrome. Bug: b:333423685 Change-Id: I546d25ad84e43ca76ee45734b4c69ccffb01f63a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5458994 Auto-Submit: Philip Pfaffe <[email protected]> Commit-Queue: Philip Pfaffe <[email protected]> Reviewed-by: Simon Zünd <[email protected]>
1 parent 6a564d1 commit 3105fcb

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

test/unit/karma.conf.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ function* reporters() {
2727
}
2828
}
2929

30+
const CustomChrome = function(this: unknown, _baseBrowserDecorator: unknown, _args: unknown, _config: unknown) {
31+
require('karma-chrome-launcher')['launcher:Chrome'][1].apply(this, arguments);
32+
};
33+
34+
CustomChrome.prototype = {
35+
name: 'ChromeLauncher',
36+
37+
DEFAULT_CMD: {
38+
[process.platform]: TestConfig.chromeBinary,
39+
},
40+
ENV_CMD: 'CHROME_BIN',
41+
};
42+
CustomChrome.$inject = ['baseBrowserDecorator', 'args', 'config'];
43+
3044
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3145
module.exports = function(config: any) {
3246
const targetDir = path.relative(SOURCE_ROOT, GEN_DIR);
@@ -60,7 +74,7 @@ module.exports = function(config: any) {
6074
browsers: ['BrowserWithArgs'],
6175
customLaunchers: {
6276
'BrowserWithArgs': {
63-
base: 'Chrome',
77+
base: CustomChrome.prototype.name,
6478
flags: [
6579
'--remote-allow-origins=*',
6680
`--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`,
@@ -84,7 +98,7 @@ module.exports = function(config: any) {
8498
},
8599

86100
plugins: [
87-
require('karma-chrome-launcher'),
101+
{[`launcher:${CustomChrome.prototype.name}`]: ['type', CustomChrome]},
88102
require('karma-mocha'),
89103
require('karma-mocha-reporter'),
90104
require('karma-chai'),

0 commit comments

Comments
 (0)