Skip to content

Commit

Permalink
Fix running browser tests that use deferred loading (#2090)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 committed Sep 7, 2023
1 parent 27dcae1 commit 83ae0d9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
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

0 comments on commit 83ae0d9

Please sign in to comment.