-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathbuild_integration_test.dart
112 lines (98 loc) · 4.04 KB
/
build_integration_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@TestOn('vm')
import 'dart:io';
import 'package:build_runner_core/src/util/constants.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'common/utils.dart';
void main() {
setUp(() async {
ensureCleanGitClient();
// Run a regular build in known clean state to speed up these tests.
await runBuild();
});
group('PostProcessBuilder', () {
test('creates expected outputs', () async {
var generated =
await readGeneratedFileAsString('_test/lib/hello.txt.post');
var original = await File('lib/hello.txt').readAsString();
expect(generated, equals(original));
});
test('can be configured with build.yaml', () async {
await runBuild(trailingArgs: ['--config', 'post_process']);
var generated =
await readGeneratedFileAsString('_test/lib/hello.txt.post');
expect(generated, equals('goodbye'));
});
test('can be configured with --define', () async {
var content = 'cool';
await runBuild(trailingArgs: [
'--define',
'provides_builder:some_post_process_builder=default_content=$content'
]);
var generated =
await readGeneratedFileAsString('_test/lib/hello.txt.post');
expect(generated, equals(content));
});
test('rebuilds if the input file changes and not otherwise', () async {
var result = await runBuild();
expect(result.stdout, contains('with 0 outputs'));
await replaceAllInFile('lib/hello.txt', 'hello', 'goodbye');
result = await runBuild();
expect(result.stdout, contains('with 1 outputs'));
var content = await readGeneratedFileAsString('_test/lib/hello.txt.post');
expect(content, contains('goodbye'));
});
});
group('regression tests', () {
test('Failing optional outputs which are required during the next build',
() async {
// Run a build with DDC that should fail
final path = p.join('lib', 'bad_file.dart');
await createFile(path, 'not valid dart syntax');
final testFile = p.join('test', 'hello_world_test.dart');
await replaceAllInFile(testFile, '//import_anchor',
"import: 'package:_test/bad_file.dart';");
final result = await runBuild(trailingArgs: ['--fail-on-severe']);
expect(result.exitCode, isNot(0));
expect(result.stdout, contains('Failed'));
// Remove the import to the bad file so it is no longer a requirement for
// the overall build
await replaceAllInFile(testFile, "import: 'package:_test/bad_file.dart';",
'//import_anchor');
final nextBuild = await runBuild(trailingArgs: ['--fail-on-severe']);
expect(nextBuild.exitCode, 0);
});
test(
'Restores previously deleted outputs if they are not deleted in subsequent builds',
() async {
final dartSource =
File(p.join('build', 'web', 'packages', '_test', 'app.dart'));
await runBuild(trailingArgs: [
'--define=build_web_compilers|dart_source_cleanup=enabled=true',
'--output',
'build'
]);
expect(dartSource.existsSync(), false);
await runBuild(trailingArgs: ['--output', 'build']);
expect(dartSource.existsSync(), true);
});
test('Re-snapshots if there is no asset graph', () async {
var assetGraph = assetGraphPathFor(p.url
.join('.dart_tool', 'build', 'entrypoint', 'build.dart.snapshot'));
await File(assetGraph).delete();
var nextBuild = await runBuild();
expect(
nextBuild.stdout.split('\n'),
containsAllInOrder([
contains('Generating build script'),
contains('Deleted previous snapshot due to missing asset graph.'),
contains('Creating build script snapshot'),
contains('Building new asset graph.'),
contains('Succeeded after'),
]));
});
});
}