Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running browser tests that use deferred loading #2090

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Simplify the initialization of the per-suite message channel within browser
tests. See https://github.com/dart-lang/test/issues/2065
* Add a timeout to browser test suite loads.
* Fix running of browser tests that use deferred loaded libraries.

## 1.24.6

Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies:

# Use an exact version until the test_api and test_core package are stable.
test_api: 0.6.1
test_core: 0.5.6
test_core: 0.5.7

typed_data: ^1.3.0
web_socket_channel: ^2.0.0
Expand Down
54 changes: 54 additions & 0 deletions pkgs/test/test/runner/browser/runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -921,4 +921,58 @@ void main() {
await test.shouldExit(0);
}, tags: 'chrome');
});

group('deferred loading', () {
test('can run browser tests with deferred library imports', () async {
await d.file('deferred.dart', '''
int x = 1;
''').create();
await d.file('test.dart', '''
import 'package:test/test.dart';

import 'deferred.dart' deferred as d;

void main() {
test("success", () async {
await d.loadLibrary();
expect(d.x, 1);
});
}
''').create();
var test = await runTest(['-p', 'chrome', 'test.dart']);

expect(test.stdout, emitsThrough(contains('+1: All tests passed!')));
await test.shouldExit(0);
}, tags: 'chrome');

test('stack trace mapping works for deferred loaded libraries', () async {
await d.file('deferred.dart', '''
int get x {
throw 'Oh no!';
}
''').create();
await d.file('test.dart', '''
import 'package:test/test.dart';

import 'deferred.dart' deferred as d;

void main() {
test("failure", () async {
await d.loadLibrary();
expect(d.x, 1);
});
}
''').create();

var test = await runTest(['-p', 'chrome', 'test.dart']);
expect(
test.stdout,
containsInOrder([
'Oh no!',
'deferred.dart',
'test.dart',
]));
await test.shouldExit(1);
}, tags: 'chrome');
});
}
3 changes: 3 additions & 0 deletions pkgs/test_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 0.5.7-wip

* Pass --disable-program-split to dart2js to fix tests which use deferred
loading.

## 0.5.6

* Add support for discontinuing after the first failing test with `--fail-fast`.
Expand Down
1 change: 1 addition & 0 deletions pkgs/test_core/lib/src/runner/dart2js_compiler_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Dart2JsCompilerPool extends CompilerPool {
wrapperPath,
'--out=$path',
'--packages=${await packageConfigUri}',
'--disable-program-split',
..._extraArgs,
...suiteConfig.dart2jsArgs
];
Expand Down
Loading