forked from flutter/gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for compiled js bundle size (flutter#105)
* Add integration test for compiled js bundle * Make gallery_compile_test into its own step Former-commit-id: e03ff1c
- Loading branch information
1 parent
30be840
commit 0ac835c
Showing
3 changed files
with
113 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2020 The Flutter team. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:test/test.dart'; | ||
import 'package:path/path.dart' as path; | ||
|
||
// Benchmark size in kB. | ||
const int bundleSizeBenchmark = 4000; | ||
const int gzipBundleSizeBenchmark = 1000; | ||
|
||
void main() { | ||
group('Web Compile', () { | ||
test('bundle size', () async { | ||
final js = path.join( | ||
Directory.current.path, | ||
'build', | ||
'web', | ||
'main.dart.js', | ||
); | ||
await _runProcess('flutter', [ | ||
'build', | ||
'web', | ||
'-v', | ||
'--release', | ||
'--no-pub', | ||
]); | ||
await _runProcess('gzip', ['-k', js]); | ||
final bundleSize = await _measureSize(js); | ||
final gzipBundleSize = await _measureSize(js + '.gz'); | ||
|
||
if (bundleSize > bundleSizeBenchmark) { | ||
fail( | ||
'The size the compiled web build "$js" was $bundleSize kB. This is ' | ||
'larger than the benchmark that was set at $bundleSizeBenchmark kB.' | ||
'\n\n' | ||
'The build size should be as minimal as possible to reduce the web ' | ||
'app’s initial startup time. If this change is intentional, and' | ||
' expected, please increase the constant "bundleSizeBenchmark".'); | ||
} else if (gzipBundleSize > gzipBundleSizeBenchmark) { | ||
fail('The size the compiled and gzipped web build "$js" was' | ||
' $gzipBundleSize kB. This is larger than the benchmark that was ' | ||
'set at $gzipBundleSizeBenchmark kB.\n\n' | ||
'The build size should be as minimal as possible to reduce the ' | ||
'web app’s initial startup time. If this change is intentional, and' | ||
' expected, please increase the constant "gzipBundleSizeBenchmark".'); | ||
} | ||
}, timeout: const Timeout(Duration(minutes: 5))); | ||
}); | ||
} | ||
|
||
Future<int> _measureSize(String file) async { | ||
final result = await _runProcess('du', ['-k', file]); | ||
return int.parse( | ||
(result.stdout as String).split(RegExp(r'\s+')).first.trim()); | ||
} | ||
|
||
Future<ProcessResult> _runProcess( | ||
String executable, List<String> arguments) async { | ||
final result = await Process.run(executable, arguments); | ||
stdout.write(result.stdout); | ||
stderr.write(result.stderr); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters