Skip to content

Commit

Permalink
[web] filter test targets; cache host.dart compilation (flutter#12445)
Browse files Browse the repository at this point in the history
* filter test targets; cache host.dart compilation
  • Loading branch information
yjbanov authored Sep 25, 2019
1 parent efb7bf4 commit 3360d86
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/web_ui/dev/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Environment {
));

/// Path to the "web_engine_tester" package.
io.Directory get goldenTesterRootDir => io.Directory(pathlib.join(
io.Directory get webEngineTesterRootDir => io.Directory(pathlib.join(
webSdkRootDir.path,
'web_engine_tester',
));
Expand Down
47 changes: 39 additions & 8 deletions lib/web_ui/dev/test_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class TestsCommand extends Command<bool> {

_copyAhemFontIntoWebUi();
await _buildHostPage();
await _buildTests();

final List<FilePath> targets =
this.targets.map((t) => FilePath.fromCwd(t)).toList();
await _buildTests(targets: targets);
if (targets.isEmpty) {
await _runAllTests();
} else {
Expand Down Expand Up @@ -143,27 +143,52 @@ class TestsCommand extends Command<bool> {
}
}

// TODO(yjbanov): skip rebuild if host.dart hasn't changed.
Future<void> _buildHostPage() async {
final String hostDartPath = path.join('lib', 'static', 'host.dart');
final io.File hostDartFile = io.File(path.join(
environment.webEngineTesterRootDir.path,
hostDartPath,
));
final io.File timestampFile = io.File(path.join(
environment.webEngineTesterRootDir.path,
'$hostDartPath.js.timestamp',
));

final String timestamp = hostDartFile.statSync().modified.millisecondsSinceEpoch.toString();
if (timestampFile.existsSync()) {
final String lastBuildTimestamp = timestampFile.readAsStringSync();
if (lastBuildTimestamp == timestamp) {
// The file is still fresh. No need to rebuild.
return;
} else {
// Record new timestamp, but don't return. We need to rebuild.
print('${hostDartFile.path} timestamp changed. Rebuilding.');
}
} else {
print('Building ${hostDartFile.path}.');
}

final int exitCode = await runProcess(
environment.dart2jsExecutable,
<String>[
'lib/static/host.dart',
hostDartPath,
'-o',
'lib/static/host.dart.js',
'$hostDartPath.js',
],
workingDirectory: environment.goldenTesterRootDir.path,
workingDirectory: environment.webEngineTesterRootDir.path,
);

if (exitCode != 0) {
io.stderr.writeln(
'Failed to compile tests. Compiler exited with exit code $exitCode');
'Failed to compile ${hostDartFile.path}. Compiler exited with exit code $exitCode');
io.exit(1);
}

// Record the timestamp to avoid rebuilding unless the file changes.
timestampFile.writeAsStringSync(timestamp);
}

Future<void> _buildTests() async {
// TODO(yjbanov): learn to build only requested tests: https://github.com/flutter/flutter/issues/37810
Future<void> _buildTests({ List<FilePath> targets }) async {
final int exitCode = await runProcess(
environment.pubExecutable,
<String>[
Expand All @@ -173,6 +198,12 @@ class TestsCommand extends Command<bool> {
'test',
'-o',
'build',
if (targets != null)
for (FilePath path in targets)
...[
'--build-filter=${path.relativeToWebUi}.js',
'--build-filter=${path.relativeToWebUi}.browser_test.dart.js',
],
],
workingDirectory: environment.webUiRootDir.path,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dev_dependencies:
path: 1.6.4
test: 1.6.5
quiver: 2.0.5
build_runner: 1.6.5
build_runner: 1.7.0
build_test: 0.10.8
build_web_compilers: 2.1.5
yaml: 2.2.0
Expand Down

0 comments on commit 3360d86

Please sign in to comment.