Skip to content

Commit 0e5c028

Browse files
authored
Only use environment variable for chrome (#1970)
Add a new argument to the `ExectuableSettings` constructor to add an environment variable that can override the specific executable, instead of overriding for all uses of `ExectuableSettings`. Pass this variable from the chrome browser. Add a test that the override is ignored when running a firefox test.
1 parent 0b08d70 commit 0e5c028

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

pkgs/test/lib/src/runner/browser/default_settings.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ final defaultSettings = UnmodifiableMapView({
1313
linuxExecutable: 'google-chrome',
1414
macOSExecutable:
1515
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
16-
windowsExecutable: r'Google\Chrome\Application\chrome.exe'),
16+
windowsExecutable: r'Google\Chrome\Application\chrome.exe',
17+
environmentOverride: 'CHROME_EXECUTABLE'),
1718
Runtime.firefox: ExecutableSettings(
1819
linuxExecutable: 'firefox',
1920
macOSExecutable: '/Applications/Firefox.app/Contents/MacOS/firefox-bin',

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ class ExecutableSettings {
3434
/// `PROGRAMFILES(X64)` environment variables.
3535
final String? _windowsExecutable;
3636

37+
/// The environment variable, if any, to use as an override for the default
38+
/// path.
39+
final String? _environmentOverride;
40+
3741
/// The path to the executable for the current operating system.
3842
String get executable {
39-
final envVariable = Platform.environment['CHROME_EXECUTABLE'];
40-
if (envVariable != null) return envVariable;
43+
if (_environmentOverride != null) {
44+
final envVariable = Platform.environment[_environmentOverride];
45+
if (envVariable != null) return envVariable;
46+
}
4147

4248
if (Platform.isMacOS) return _macOSExecutable!;
4349
if (!Platform.isWindows) return _linuxExecutable!;
@@ -172,11 +178,13 @@ class ExecutableSettings {
172178
String? linuxExecutable,
173179
String? macOSExecutable,
174180
String? windowsExecutable,
181+
String? environmentOverride,
175182
bool? headless})
176183
: arguments = arguments == null ? const [] : List.unmodifiable(arguments),
177184
_linuxExecutable = linuxExecutable,
178185
_macOSExecutable = macOSExecutable,
179186
_windowsExecutable = windowsExecutable,
187+
_environmentOverride = environmentOverride,
180188
_headless = headless;
181189

182190
/// Merges [this] with [other], with [other]'s settings taking priority.

pkgs/test/test/runner/browser/firefox_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,22 @@ void main() {
7979
expect(test.stdout, emitsThrough(contains('-1: Some tests failed.')));
8080
await test.shouldExit(1);
8181
});
82+
83+
test('not impacted by CHROME_EXECUTABLE var', () async {
84+
await d.file('test.dart', '''
85+
import 'dart:html';
86+
87+
import 'package:test/test.dart';
88+
89+
void main() {
90+
test("success", () {
91+
assert(window.navigator.vendor != 'Google Inc.');
92+
});
93+
}
94+
''').create();
95+
var test = await runTest(['-p', 'firefox', 'test.dart'],
96+
environment: {'CHROME_EXECUTABLE': '/some/bad/path'});
97+
expect(test.stdout, emitsThrough(contains('+1: All tests passed!')));
98+
await test.shouldExit(0);
99+
});
82100
}

0 commit comments

Comments
 (0)