Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dart-lang/test
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7832931
Choose a base ref
..
head repository: dart-lang/test
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7fab079
Choose a head ref
2 changes: 1 addition & 1 deletion pkgs/checks/doc/migrating_from_matcher.md
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ behavior and signature changes to align with modern Dart idioms.
high potential for minor or major breaking changes during the preview window.
Once this package is stable, yes! The experience of using `checks` improves on
`matcher`. See some of the [improvements to look forward to in checks
below][#improvements-you-can-expect].
below](#improvements-you-can-expect).

[matcher]: https://pub.dev/packages/matcher

4 changes: 3 additions & 1 deletion pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
## 1.24.2-dev
## 1.24.2

* Copy an existing nonce from a script on the test HTML page to the script
created by the test runner host javascript. This only impacts environments
testing with custom HTML that includes a nonce.
* Support the Microsoft Edge browser (use the `edge` platform in your the test
configuration file or `-p edge` on the command line).

## 1.24.1

3 changes: 3 additions & 0 deletions pkgs/test/dart_test.yaml
Original file line number Diff line number Diff line change
@@ -43,6 +43,9 @@ tags:
add_tags: [dart2js]
test_on: windows
skip: https://github.com/dart-lang/test/issues/1614
edge:
add_tags: [dart2js]
test_on: windows

# Tests that run pub. These tests may need to be excluded when there are local
# dependency_overrides.
1 change: 1 addition & 0 deletions pkgs/test/lib/src/executable.dart
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ Future<void> main(List<String> args) async {
registerPlatformPlugin([Runtime.nodeJS], () => NodePlatform());
registerPlatformPlugin([
Runtime.chrome,
Runtime.edge,
Runtime.firefox,
Runtime.safari,
Runtime.internetExplorer
3 changes: 3 additions & 0 deletions pkgs/test/lib/src/runner/browser/browser_manager.dart
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ import 'browser.dart';
import 'chrome.dart';
import 'firefox.dart';
import 'internet_explorer.dart';
import 'microsoft_edge.dart';
import 'safari.dart';

/// A class that manages the connection to a single running browser.
@@ -163,6 +164,8 @@ class BrowserManager {
return Safari(url, settings: settings);
case Runtime.internetExplorer:
return InternetExplorer(url, settings: settings);
case Runtime.edge:
return MicrosoftEdge(url, configuration, settings: settings);
default:
throw ArgumentError('$browser is not a browser.');
}
49 changes: 14 additions & 35 deletions pkgs/test/lib/src/runner/browser/chrome.dart
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import '../executable_settings.dart';
import 'browser.dart';
import 'chromium.dart';
import 'default_settings.dart';

/// A class for running an instance of Chrome.
@@ -45,39 +46,20 @@ class Chrome extends Browser {
var idToUrl = <String, String>{};
return Chrome._(() async {
Future<Process> tryPort([int? port]) async {
var dir = createTempDir();
var args = [
'--user-data-dir=$dir',
url.toString(),
'--enable-logging=stdout',
'--v=1',
'--disable-extensions',
'--disable-popup-blocking',
'--bwsi',
'--no-first-run',
'--no-default-browser-check',
'--disable-default-apps',
'--disable-translate',
'--disable-dev-shm-usage',
if (settings!.headless && !configuration.pauseAfterLoad) ...[
'--headless',
'--disable-gpu',
var process = await ChromiumBasedBrowser.chrome.spawn(
url,
configuration,
settings: settings,
additionalArgs: [
if (port != null)
// Chrome doesn't provide any way of ensuring that this port was
// successfully bound. It produces an error if the binding fails,
// but without a reliable and fast way to tell if it succeeded
// that doesn't provide us much. It's very unlikely that this port
// will fail, though.
'--remote-debugging-port=$port',
],
if (!configuration.debug)
// We don't actually connect to the remote debugger, but Chrome will
// close as soon as the page is loaded if we don't turn it on.
'--remote-debugging-port=0',
...settings.arguments,
if (port != null)
// Chrome doesn't provide any way of ensuring that this port was
// successfully bound. It produces an error if the binding fails,
// but without a reliable and fast way to tell if it succeeded that
// doesn't provide us much. It's very unlikely that this port will
// fail, though.
'--remote-debugging-port=$port',
];

var process = await Process.start(settings.executable, args);
);

if (port != null) {
remoteDebuggerCompleter.complete(
@@ -88,9 +70,6 @@ class Chrome extends Browser {
remoteDebuggerCompleter.complete(null);
}

unawaited(
process.exitCode.then((_) => Directory(dir).deleteWithRetry()));

return process;
}

63 changes: 63 additions & 0 deletions pkgs/test/lib/src/runner/browser/chromium.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io';

import 'package:test/src/runner/browser/default_settings.dart';
import 'package:test_api/src/backend/runtime.dart'; // ignore: implementation_imports
import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
import 'package:test_core/src/util/io.dart'; // ignore: implementation_imports

import '../executable_settings.dart';

enum ChromiumBasedBrowser {
chrome(Runtime.chrome),
microsoftEdge(Runtime.edge);

final Runtime runtime;

const ChromiumBasedBrowser(this.runtime);

Future<Process> spawn(
Uri url,
Configuration configuration, {
ExecutableSettings? settings,
List<String> additionalArgs = const [],
}) async {
settings ??= defaultSettings[runtime];

var dir = createTempDir();
var args = [
'--user-data-dir=$dir',
url.toString(),
'--enable-logging=stdout',
'--v=1',
'--disable-extensions',
'--disable-popup-blocking',
'--bwsi',
'--no-first-run',
'--no-default-browser-check',
'--disable-default-apps',
'--disable-translate',
'--disable-dev-shm-usage',
if (settings!.headless && !configuration.pauseAfterLoad) ...[
'--headless',
'--disable-gpu',
],
if (!configuration.debug)
// We don't actually connect to the remote debugger, but Chrome will
// close as soon as the page is loaded if we don't turn it on.
'--remote-debugging-port=0',
...settings.arguments,
...additionalArgs,
];

var process = await Process.start(settings.executable, args);

unawaited(process.exitCode.then((_) => Directory(dir).deleteWithRetry()));

return process;
}
}
9 changes: 8 additions & 1 deletion pkgs/test/lib/src/runner/browser/default_settings.dart
Original file line number Diff line number Diff line change
@@ -15,12 +15,19 @@ final defaultSettings = UnmodifiableMapView({
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
windowsExecutable: r'Google\Chrome\Application\chrome.exe',
environmentOverride: 'CHROME_EXECUTABLE'),
Runtime.edge: ExecutableSettings(
linuxExecutable: 'microsoft-edge-stable',
windowsExecutable: r'Microsoft\Edge\Application\msedge.exe',
macOSExecutable:
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
environmentOverride: 'MS_EDGE_EXECUTABLE',
),
Runtime.firefox: ExecutableSettings(
linuxExecutable: 'firefox',
macOSExecutable: '/Applications/Firefox.app/Contents/MacOS/firefox-bin',
windowsExecutable: r'Mozilla Firefox\firefox.exe'),
Runtime.internetExplorer:
ExecutableSettings(windowsExecutable: r'Internet Explorer\iexplore.exe'),
Runtime.safari: ExecutableSettings(
macOSExecutable: '/Applications/Safari.app/Contents/MacOS/Safari')
macOSExecutable: '/Applications/Safari.app/Contents/MacOS/Safari'),
});
23 changes: 23 additions & 0 deletions pkgs/test/lib/src/runner/browser/microsoft_edge.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports

import '../executable_settings.dart';
import 'browser.dart';
import 'chromium.dart';

/// A class for running an instance of Microsoft Edge, a Chromium-based browser.
class MicrosoftEdge extends Browser {
@override
String get name => 'Edge';

MicrosoftEdge(Uri url, Configuration configuration,
{ExecutableSettings? settings})
: super(() => ChromiumBasedBrowser.microsoftEdge.spawn(
url,
configuration,
settings: settings,
));
}
6 changes: 3 additions & 3 deletions pkgs/test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: test
version: 1.24.2-dev
version: 1.24.2
description: >-
A full featured library for writing and running Dart tests across platforms.
repository: https://github.com/dart-lang/test/tree/master/pkgs/test
@@ -32,8 +32,8 @@ dependencies:
webkit_inspection_protocol: ^1.0.0
yaml: ^3.0.0
# Use an exact version until the test_api and test_core package are stable.
test_api: 0.5.1
test_core: 0.5.1
test_api: 0.5.2
test_core: 0.5.2
# Use a tight version constraint to ensure that a constraint on matcher
# properly constrains all features it provides.
matcher: '>=0.12.15 <0.12.16'
76 changes: 76 additions & 0 deletions pkgs/test/test/runner/browser/microsoft_edge_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')
@Tags(['edge'])

import 'package:test/src/runner/browser/microsoft_edge.dart';
import 'package:test/src/runner/executable_settings.dart';
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;

import '../../io.dart';
import '../../utils.dart';
import 'code_server.dart';

void main() {
setUpAll(precompileTestExecutable);

test('starts edge with the given URL', () async {
var server = await CodeServer.start();

server.handleJavaScript('''
var webSocket = new WebSocket(window.location.href.replace("http://", "ws://"));
webSocket.addEventListener("open", function() {
webSocket.send("loaded!");
});
''');
var webSocket = server.handleWebSocket();

var edge = MicrosoftEdge(server.url, configuration());
addTearDown(() => edge.close());

expect(await (await webSocket).stream.first, equals('loaded!'));
}, timeout: Timeout.factor(2));

test('reports an error in onExit', () {
var edge = MicrosoftEdge(Uri.parse('https://dart.dev'), configuration(),
settings: ExecutableSettings(
linuxExecutable: '_does_not_exist',
macOSExecutable: '_does_not_exist',
windowsExecutable: '_does_not_exist'));
expect(
edge.onExit,
throwsA(isApplicationException(
startsWith('Failed to run Edge: $noSuchFileMessage'))));
});

test('can run successful tests', () async {
await d.file('test.dart', '''
import 'package:test/test.dart';
void main() {
test("success", () {});
}
''').create();

var test = await runTest(['-p', 'edge', 'test.dart']);
expect(test.stdout, emitsThrough(contains('+1: All tests passed!')));
await test.shouldExit(0);
});

test('can run failing tests', () async {
await d.file('test.dart', '''
import 'package:test/test.dart';
void main() {
test("failure", () => throw TestFailure("oh no"));
}
''').create();

var test = await runTest(['-p', 'edge', 'test.dart']);
expect(test.stdout, emitsThrough(contains('-1: Some tests failed.')));
await test.shouldExit(1);
});
}
3 changes: 2 additions & 1 deletion pkgs/test/test/runner/runner_test.dart
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ Output:

final _runtimes = '[vm (default), chrome, firefox'
'${Platform.isMacOS ? ', safari' : ''}'
'${Platform.isWindows ? ', ie' : ''}, node, '
'${Platform.isWindows ? ', ie' : ''}, edge, node, '
'experimental-chrome-wasm]';

final _runtimeCompilers = [
@@ -129,6 +129,7 @@ final _runtimeCompilers = [
'[firefox]: dart2js (default)',
if (Platform.isMacOS) '[safari]: dart2js (default)',
if (Platform.isWindows) '[ie]: dart2js (default)',
'[edge]: dart2js (default)',
'[node]: dart2js (default)',
'[experimental-chrome-wasm]: dart2wasm (default)',
].map((str) => ' $str').join('\n');
5 changes: 5 additions & 0 deletions pkgs/test_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.5.2

* Remove deprecation for the `scaffolding.dart` and `backend.dart` libraries.
* Export `registerException` from the `scaffolding.dart` library.

## 0.5.1

* Handle a missing `'compiler'` value when running a test compiled against a
4 changes: 0 additions & 4 deletions pkgs/test_api/lib/backend.dart
Original file line number Diff line number Diff line change
@@ -2,10 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Deprecated('package:test_api is not intended for general use. '
'Please use package:test.')
library test_api.backend;

export 'src/backend/compiler.dart' show Compiler;
export 'src/backend/metadata.dart' show Metadata;
export 'src/backend/platform_selector.dart' show PlatformSelector;
4 changes: 1 addition & 3 deletions pkgs/test_api/lib/scaffolding.dart
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@
/// {@canonicalFor tags.Tags}
/// {@canonicalFor test_on.TestOn}
/// {@canonicalFor timeout.Timeout}
@Deprecated('package:test_api is not intended for general use. '
'Please use package:test.')
library test_api.scaffolding;

export 'src/backend/configuration/on_platform.dart' show OnPlatform;
@@ -22,4 +20,4 @@ export 'src/scaffolding/spawn_hybrid.dart' show spawnHybridUri, spawnHybridCode;
export 'src/scaffolding/test_structure.dart'
show group, test, setUp, setUpAll, tearDown, tearDownAll, addTearDown;
export 'src/scaffolding/utils.dart'
show pumpEventQueue, printOnFailure, markTestSkipped;
show markTestSkipped, printOnFailure, pumpEventQueue, registerException;
Loading