Skip to content

Commit

Permalink
Add integration test for compiled js bundle size (flutter#105)
Browse files Browse the repository at this point in the history
* Add integration test for compiled js bundle

* Make gallery_compile_test into its own step

Former-commit-id: e03ff1c
  • Loading branch information
perclasson authored Apr 16, 2020
1 parent 30be840 commit 0ac835c
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 7 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,36 @@ jobs:
# TODO: Enable verify-code-segments for Unix and Windows when it behaves the same as on macOS:
# https://github.com/material-components/material-components-flutter-gallery/issues/565
if: runner.os == 'macOS'

integration-test:
name: Integration tests
runs-on: ubuntu-latest
steps:
# Set up Flutter and add it to the path.
- name: Clone Flutter repository with master channel.
uses: actions/checkout@v2
with:
repository: 'flutter/flutter'
ref: 'master'
path: 'flutter'
fetch-depth: 0
- name: Add Flutter to the PATH.
run: echo "::add-path::/$GITHUB_WORKSPACE/flutter/bin"
- name: Run Flutter doctor.
run: flutter doctor -v
- name: Enable Flutter web.
run: flutter config --enable-web

# Clone the Gallery repository under `code`, to avoid conflicts with `flutter`.
- name: Clone the Gallery repository.
uses: actions/checkout@v2
with:
path: 'code'

# Run integration tests.
- name: Get packages for the Flutter project.
run: flutter pub get
working-directory: code
- name: Run gallery_compile_test.
run: flutter test integration_test/gallery_compile_test.dart
working-directory: code
66 changes: 66 additions & 0 deletions integration_test/gallery_compile_test.dart
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;
}
21 changes: 14 additions & 7 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3+2"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
collection:
dependency: "direct main"
description:
Expand Down Expand Up @@ -106,6 +113,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.4"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -402,13 +416,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.4"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
rally_assets:
dependency: "direct main"
description:
Expand Down

0 comments on commit 0ac835c

Please sign in to comment.