Skip to content

Commit

Permalink
Add an arguments field to executable settings
Browse files Browse the repository at this point in the history
See #391
  • Loading branch information
nex3 committed Oct 18, 2017
1 parent 40b596a commit 5983060
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
12 changes: 12 additions & 0 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,18 @@ provide the same settings that can be set using
[`define_platforms`](#define_platforms), which control how their executables are
invoked.

#### `arguments`

The `arguments` field provides extra arguments to the executable. It takes a
string, and parses it in the same way as the POSIX shell:

```yaml
override_platforms:
firefox:
settings:
arguments: -headless
```

#### `executable`

The `executable` field tells the test runner where to look for the executable to
Expand Down
19 changes: 18 additions & 1 deletion lib/src/runner/executable_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'dart:io';

import 'package:io/io.dart';
import 'package:path/path.dart' as p;
import 'package:source_span/source_span.dart';
import 'package:yaml/yaml.dart';
Expand Down Expand Up @@ -64,6 +65,22 @@ class ExecutableSettings {

/// Parses settings from a user-provided YAML mapping.
factory ExecutableSettings.parse(YamlMap settings) {
List<String> arguments;
var argumentsNode = settings.nodes["arguments"];
if (argumentsNode != null) {
if (argumentsNode.value is String) {
try {
arguments = shellSplit(argumentsNode.value);
} on FormatException catch (error) {
throw new SourceSpanFormatException(
error.message, argumentsNode.span);
}
} else {
throw new SourceSpanFormatException(
"Must be a string.", argumentsNode.span);
}
}

String linuxExecutable;
String macOSExecutable;
String windowsExecutable;
Expand All @@ -88,8 +105,8 @@ class ExecutableSettings {
}
}

// TODO(nweiz): Parse arguments once io#23 is released.
return new ExecutableSettings(
arguments: arguments,
linuxExecutable: linuxExecutable,
macOSExecutable: macOSExecutable,
windowsExecutable: windowsExecutable);
Expand Down
4 changes: 3 additions & 1 deletion lib/src/runner/node/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ class NodePlatform extends PlatformPlugin

/// Starts the Node.js process for [platform] with [jsPath].
Future<Process> _startProcess(TestPlatform platform, String jsPath) async {
var settings = _settings[platform];
try {
return await Process.start(_settings[platform].executable, [jsPath]);
return await Process.start(
settings.executable, settings.arguments.toList()..add(jsPath));
} catch (error, stackTrace) {
await new Future.error(
new ApplicationException(
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
collection: '^1.8.0'
glob: '^1.0.0'
http_multi_server: '>=1.0.0 <3.0.0'
io: '^0.3.0'
js: '^0.6.0'
meta: '^1.0.0'
node_preamble: '^1.3.0'
Expand Down
47 changes: 47 additions & 0 deletions test/runner/configuration/custom_platform_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,53 @@ void main() {
contains("Failed to run Chrome: $noSuchFileMessage")));
await test.shouldExit(1);
});

test("arguments must be a string", () async {
await d.file("dart_test.yaml", """
define_platforms:
chromium:
name: Chromium
extends: chrome
settings:
arguments: 12
""").create();

var test = await runTest(["-p", "chromium", "test.dart"]);
expect(test.stdout, containsInOrder(['Must be a string.', "^^"]));
await test.shouldExit(1);
});

test("arguments must be shell parseable", () async {
await d.file("dart_test.yaml", """
define_platforms:
chromium:
name: Chromium
extends: chrome
settings:
arguments: --foo 'bar
""").create();

var test = await runTest(["-p", "chromium", "test.dart"]);
expect(test.stdout,
containsInOrder(['Unmatched single quote.', "^^^^^^^^^^"]));
await test.shouldExit(1);
});

test("with an argument that causes the browser to quit", () async {
await d.file("dart_test.yaml", """
define_platforms:
chromium:
name: Chromium
extends: chrome
settings:
arguments: --version
""").create();

var test = await runTest(["-p", "chromium", "test.dart"]);
expect(test.stdout,
emitsThrough(contains("Chromium exited before connecting.")));
await test.shouldExit(0);
}, tags: "chrome");
});
});
});
Expand Down

0 comments on commit 5983060

Please sign in to comment.