Skip to content

Commit

Permalink
write a test for running two precompiled browser tests (#2295)
Browse files Browse the repository at this point in the history
This was intended as a regression test for
#2294 but it actually passes 😭
  • Loading branch information
jakemac53 authored Oct 18, 2024
1 parent 0dd3238 commit 73e30fb
Showing 1 changed file with 61 additions and 38 deletions.
99 changes: 61 additions & 38 deletions pkgs/test/test/runner/precompiled_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,36 @@ void main() {
setUpAll(precompileTestExecutable);

group('browser tests', () {
setUp(() async {
await d.file('to_precompile.dart', '''
import "package:test/bootstrap/browser.dart";
import "package:test/test.dart";
main(_) {
internalBootstrapBrowserTest(() => () => test("success", () {}));
}
''').create();

await d.dir('precompiled', [
d.file('test.html', '''
<!DOCTYPE html>
<html>
<head>
<title>test Test</title>
<script src="test.dart.browser_test.dart.js"></script>
</head>
</html>
''')
]).create();

var dart2js = await TestProcess.start(
Platform.resolvedExecutable,
[
'compile',
'js',
...Platform.executableArguments,
'--packages=${(await Isolate.packageConfig)!.toFilePath()}',
'to_precompile.dart',
'--out=precompiled/test.dart.browser_test.dart.js'
],
workingDirectory: d.sandbox);
await dart2js.shouldExit(0);

await d.file('test.dart', 'invalid dart}').create();
setUpAll(() async {
await _precompileBrowserTest('test.dart');
});

test('run a precompiled version of a test rather than recompiling',
() async {
var test = await runTest(
['-p', 'chrome', '--precompiled=precompiled/', 'test.dart']);
var test = await runTest([
'-p',
'chrome',
'--precompiled=precompiled/',
'test.dart',
]);
expect(test.stdout,
containsInOrder(['+0: success', '+1: All tests passed!']));
await test.shouldExit(0);
});

test('run two precompiled tests', () async {
await _precompileBrowserTest('test_2.dart');
var test = await runTest([
'-p',
'chrome',
'--precompiled=precompiled/',
'test.dart',
'test_2.dart',
]);
expect(test.stdout, containsInOrder(['+2: All tests passed!']));
await test.shouldExit(0);
});

test('can use the json reporter', () async {
var test = await runTest([
'-p',
Expand Down Expand Up @@ -239,3 +222,43 @@ Future<void> _writePackagesFile() async {
await d.dir('.dart_tool').create();
await savePackageConfig(config, Directory(d.sandbox));
}

Future<void> _precompileBrowserTest(String testPath) async {
var tmpDir = await Directory.systemTemp.createTemp('browser_test');
var file = File.fromUri(tmpDir.uri.resolve('precompiled.dart'));
await file.writeAsString('''
import "package:test/bootstrap/browser.dart";
import "package:test/test.dart";
main(_) {
internalBootstrapBrowserTest(() => () => test("success", () {}));
}
''');

await d.dir('precompiled', [
d.file(p.setExtension(testPath, 'html'), '''
<!DOCTYPE html>
<html>
<head>
<title>test Test</title>
<script src="$testPath.browser_test.dart.js"></script>
</head>
</html>
''')
]).create();

var dart2js = await TestProcess.start(
Platform.resolvedExecutable,
[
'compile',
'js',
...Platform.executableArguments,
'--packages=${(await Isolate.packageConfig)!.toFilePath()}',
file.path,
'--out=precompiled/$testPath.browser_test.dart.js'
],
workingDirectory: d.sandbox);
await dart2js.shouldExit(0);

await d.file(testPath, 'invalid dart}').create();
}

0 comments on commit 73e30fb

Please sign in to comment.