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

write a test for running two precompiled browser tests #2295

Merged
merged 1 commit into from
Oct 18, 2024
Merged
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
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();
}