flutter/packages/flutter_tools/test/dart_dependencies_test.dart
Michael Goderbauer 644e7b131d Faster hot reload (#8600)
This implements the `DartDependencySetBuilder` completely in Dart instead of calling out to `sky_snapshot` (Linux/Mac) or `gen_snapshot` (Windows) and allows us to use the same code path on all supported host platforms.

It also slightly reduces hot reload times on Linux from ~750ms to ~690ms for the unchanged flutter_gallery app and significantly reduces hot reload times on Windows from almost 1.5s to just slightly slower than on Linux.

This change will also allow us to retire `sky_snapshot` completely in the future.
2017-03-07 13:09:48 -08:00

41 lines
1.8 KiB
Dart

// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:analyzer/analyzer.dart';
import 'package:flutter_tools/src/dart/dependencies.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:test/test.dart';
import 'src/context.dart';
void main() {
group('DartDependencySetBuilder', () {
final String basePath = fs.path.dirname(fs.path.fromUri(platform.script));
final String dataPath = fs.path.join(basePath, 'data', 'dart_dependencies_test');
testUsingContext('good', () {
final String testPath = fs.path.join(dataPath, 'good');
final String mainPath = fs.path.join(testPath, 'main.dart');
final String packagesPath = fs.path.join(testPath, '.packages');
final DartDependencySetBuilder builder =
new DartDependencySetBuilder(mainPath, packagesPath);
final Set<String> dependencies = builder.build();
expect(dependencies.contains(fs.path.canonicalize(mainPath)), isTrue);
expect(dependencies.contains(fs.path.canonicalize(fs.path.join(testPath, 'foo.dart'))), isTrue);
});
testUsingContext('syntax_error', () {
final String testPath = fs.path.join(dataPath, 'syntax_error');
final String mainPath = fs.path.join(testPath, 'main.dart');
final String packagesPath = fs.path.join(testPath, '.packages');
final DartDependencySetBuilder builder =
new DartDependencySetBuilder(mainPath, packagesPath);
try {
builder.build();
fail('expect an assertion to be thrown.');
} on AnalyzerErrorGroup catch (e) {
expect(e.toString(), contains('foo.dart: Expected a string literal'));
}
});
});
}