-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathdart2js_integration_test.dart
85 lines (73 loc) · 2.81 KB
/
dart2js_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
// Copyright (c) 2017, 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')
@Tags(['integration'])
import 'dart:async';
import 'dart:io';
import 'package:test/test.dart';
import 'common/utils.dart';
const _outputDir = 'dart2js_test';
void main() {
group('Can run tests using dart2js', () {
tearDown(() async {
var dir = Directory(_outputDir);
if (await dir.exists()) {
await dir.delete(recursive: true);
}
});
test('via build.yaml config flag', () async {
await expectTestsPass(usePrecompiled: true, buildArgs: [
'--config=dart2js',
'--output=$_outputDir',
]);
await _expectWasCompiledWithDart2JS(minified: false);
}, onPlatform: {'windows': const Skip('flaky on windows')});
test('via --define flag', () async {
await expectTestsPass(usePrecompiled: true, buildArgs: [
'--define',
'build_web_compilers|entrypoint=compiler=dart2js',
'--define',
'build_web_compilers|entrypoint=dart2js_args=["--minify","--checked"]',
'--output=$_outputDir',
]);
await _expectWasCompiledWithDart2JS(minified: true);
}, onPlatform: {'windows': const Skip('flaky on windows')});
test('via --release mode', () async {
await expectTestsPass(usePrecompiled: true, buildArgs: [
'--release',
'--output=$_outputDir',
]);
await _expectWasCompiledWithDart2JS(minified: true);
}, onPlatform: {'windows': const Skip('flaky on windows')});
test('--define overrides --config', () async {
await expectTestsPass(usePrecompiled: true, buildArgs: [
'--config',
'dart2js',
'--define',
'build_web_compilers|entrypoint=compiler=dart2js',
'--define',
'build_web_compilers|entrypoint=dart2js_args=["--minify","--checked"]',
'--output=$_outputDir',
]);
await _expectWasCompiledWithDart2JS(minified: true);
}, onPlatform: {'windows': const Skip('flaky on windows')});
});
}
Future<void> _expectWasCompiledWithDart2JS({bool minified = false}) async {
var jsFile = File(
'$_outputDir/test/hello_world_deferred_test.dart.browser_test.dart.js');
expect(await jsFile.exists(), isTrue);
// sanity check that it was indeed compiled with dart2js
var content = await jsFile.readAsString();
if (minified) {
expect(content, isNot(startsWith('//')));
expect(content, contains('typeof dartMainRunner==="function"'));
} else {
expect(content, startsWith('// Generated by dart2js'));
}
var jsDeferredPartFile = File(
'$_outputDir/test/hello_world_deferred_test.dart.browser_test.dart.js'
'_1.part.js');
expect(await jsDeferredPartFile.exists(), isTrue);
}