Skip to content

Commit 51463b0

Browse files
Keep the browser executable env override through a settings merge (dart-lang#2722)
Fixes dart-lang#2609 Update `README.md` and `configuration.md` to document the four environment variables and the precedence of configuration. Fix broken anchor links. Fix configuration merging to include the environment overrides to resolve the bug where using browser configuration would cause the runner to ignore the environment variables. Add a test in `cutsom_platform_test.dart` to configure chrome arguments and use an override environment variable.
1 parent b87a249 commit 51463b0

5 files changed

Lines changed: 55 additions & 5 deletions

File tree

‎pkgs/test/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
restricted temporary authentication file to prevent secret leakage in command
2020
line process arguments.
2121
* Enable asserts in the `exe` compiler.
22+
* Keep the `CHROME_EXECUTABLE`, `MS_EDGE_EXECUTABLE`, `FIREFOX_EXECUTABLE`, and
23+
`SAFARI_EXECUTABLE` overrides working when the browser is also configured
24+
through `override_platforms` or `define_platforms`. Any setting on those
25+
platforms used to drop the variable.
2226

2327
## 1.31.2
2428

‎pkgs/test/README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,10 @@ last, just as they would in nested groups. This means that for configuration
633633
like duration-based timeouts, the last matching value wins.
634634

635635
You can also set up global platform-specific configuration using the
636-
[package configuration file][configuring platforms].
636+
[package configuration file][configuring platforms]. The `CHROME_EXECUTABLE`,
637+
`MS_EDGE_EXECUTABLE`, `FIREFOX_EXECUTABLE`, and `SAFARI_EXECUTABLE` environment
638+
variables point the runner at a browser binary somewhere else, and take
639+
precedence over that file.
637640

638641
[configuring platforms]: https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md#configuring-platforms
639642

‎pkgs/test/doc/configuration.md‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ This tells the test runner to use the `chromium` executable for Chrome tests. It
712712
calls that executable with the same logic and flags it normally uses for Chrome.
713713

714714
Each platform can define exactly which settings it supports. All browsers and
715-
Node.js support [the same settings](#browser-and-node-js-settings), but the VM
715+
Node.js support [the same settings](#browser-and-nodejs-settings), but the VM
716716
doesn't support any settings and so can't be overridden.
717717

718718
### `define_platforms`
@@ -745,7 +745,7 @@ User-defined platforms also count as their parents, so Chromium will run tests
745745
that say `testOn: "chrome"` as well.
746746

747747
Each platform can define exactly which settings it supports. All browsers and
748-
Node.js support [the same settings](#browser-and-node-js-settings), but the VM
748+
Node.js support [the same settings](#browser-and-nodejs-settings), but the VM
749749
doesn't support any settings and so can't be extended.
750750

751751
This field is not supported in the
@@ -815,6 +815,21 @@ define_platforms:
815815
executable: chromium
816816
```
817817

818+
Each built-in browser also reads an environment variable, which takes precedence
819+
over both the defaults above and anything `executable` sets:
820+
821+
| Browser | Variable |
822+
| --- | --- |
823+
| Chrome | `CHROME_EXECUTABLE` |
824+
| Edge | `MS_EDGE_EXECUTABLE` |
825+
| Firefox | `FIREFOX_EXECUTABLE` |
826+
| Safari | `SAFARI_EXECUTABLE` |
827+
828+
The value is used as the path, with no lookup of its own. This is meant for
829+
machines where the browser lives somewhere the defaults do not cover, such as a
830+
CI image that installs Chrome under its own prefix, without editing the config
831+
file that the rest of the project shares.
832+
818833
#### `headless`
819834

820835
The `headless` field says whether or not to run the browser in headless mode.

‎pkgs/test/lib/src/runner/executable_settings.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class ExecutableSettings {
232232
linuxExecutable: other._linuxExecutable ?? _linuxExecutable,
233233
macOSExecutables: other._macOSExectuables ?? _macOSExectuables,
234234
windowsExecutable: other._windowsExecutable ?? _windowsExecutable,
235+
environmentOverride: other._environmentOverride ?? _environmentOverride,
235236
);
236237
}
237238

‎pkgs/test/test/runner/configuration/custom_platform_test.dart‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ void main() {
9999
await test.shouldExit(0);
100100
}, tags: 'chrome');
101101

102+
test('with an executable from the environment', () async {
103+
// The environment override is only reachable through the default
104+
// settings, so it has to survive being merged with the user's.
105+
await d.file('dart_test.yaml', '''
106+
override_platforms:
107+
chrome:
108+
settings:
109+
arguments: --disable-gpu
110+
''').create();
111+
112+
var test = await runTest(
113+
['-p', 'chrome', 'test.dart'],
114+
environment: {'CHROME_EXECUTABLE': '_does_not_exist'},
115+
);
116+
expect(
117+
test.stdout,
118+
emitsThrough(contains('Failed to run Chrome: $noSuchFileMessage')),
119+
);
120+
await test.shouldExit(1);
121+
}, tags: 'chrome');
122+
102123
test('with non-headless mode', () async {
103124
await d.file('dart_test.yaml', '''
104125
override_platforms:
@@ -382,7 +403,10 @@ void main() {
382403
executable: _does_not_exist
383404
''').create();
384405

385-
var test = await runTest(['-p', 'chrome', 'test.dart']);
406+
var test = await runTest(
407+
['-p', 'chrome', 'test.dart'],
408+
environment: {'CHROME_EXECUTABLE': '_does_not_exist'},
409+
);
386410
expect(
387411
test.stdout,
388412
emitsThrough(contains('Failed to run Chrome: $noSuchFileMessage')),
@@ -905,7 +929,10 @@ void main() {
905929
executable: _does_not_exist
906930
''').create();
907931

908-
var test = await runTest(['-p', 'chromium', 'test.dart']);
932+
var test = await runTest(
933+
['-p', 'chromium', 'test.dart'],
934+
environment: {'CHROME_EXECUTABLE': '_does_not_exist'},
935+
);
909936
expect(
910937
test.stdout,
911938
emitsThrough(contains('Failed to run Chrome: $noSuchFileMessage')),

0 commit comments

Comments
 (0)