Enable web foundation tests (#34032)

This commit is contained in:
Jonah Williams
2019-06-09 11:03:46 -07:00
committed by GitHub
parent f3e698fba4
commit 7f7c00a4e9
11 changed files with 98 additions and 30 deletions

View File

@@ -12,3 +12,6 @@ export 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
/// A matcher that compares the type of the actual value to the type argument T.
Matcher isInstanceOf<T>() => test_package.TypeMatcher<T>();
/// Whether we are running in a web browser.
const bool isBrowser = identical(0, 0.0);

View File

@@ -14,7 +14,7 @@ void main() {
});
expect(log[0], contains('Example label'));
expect(log[1], contains('debugPrintStack'));
});
}, skip: isBrowser);
test('debugPrintStack', () {
final List<String> log = captureOutput(() {
@@ -39,7 +39,7 @@ void main() {
expect(joined, contains('captureOutput'));
expect(joined, contains('\nExample information\n'));
});
}, skip: isBrowser);
test('FlutterErrorDetails.toString', () {
expect(

View File

@@ -102,7 +102,7 @@ void main() {
expect(log, <String>['badListener', 'listener1', 'listener2']);
expect(tester.takeException(), isNullThrownError);
log.clear();
});
}, skip: isBrowser);
test('ChangeNotifier with mutating listener', () {
final TestNotifier test = TestNotifier();

View File

@@ -1187,7 +1187,7 @@ void main() {
expect(missing.isFiltered(DiagnosticLevel.info), isFalse);
validateObjectFlagPropertyJsonSerialization(present);
validateObjectFlagPropertyJsonSerialization(missing);
});
}, skip: isBrowser);
test('describe bool property', () {
final FlagProperty yes = FlagProperty(

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@TestOn('!chrome')
import 'dart:async';
import 'package:flutter/foundation.dart';

View File

@@ -161,7 +161,20 @@ final List<core.BuilderApplication> builders = <core.BuilderApplication>[
defaultGenerateFor: const InputSet(
include: <String>[
'lib/**',
'web/**',
],
),
),
core.apply(
'flutter_tools|test_entrypoint',
<BuilderFactory>[
(BuilderOptions options) => FlutterWebTestEntrypointBuilder(
options.config['targets'] ?? const <String>[]
),
],
core.toRoot(),
hideOutput: true,
defaultGenerateFor: const InputSet(
include: <String>[
'test/**_test.dart.browser_test.dart',
],
),
@@ -213,6 +226,7 @@ class BuildRunnerWebCompilationProxy extends WebCompilationProxy {
skipBuildScriptCheck: true,
trackPerformance: false,
deleteFilesByDefault: true,
enableLowResourcesMode: platform.environment['FLUTTER_LOW_RESOURCE_MODE']?.toLowerCase() == 'true',
);
final Set<core.BuildDirectory> buildDirs = <core.BuildDirectory>{
if (testOutputDir != null)
@@ -290,6 +304,10 @@ class BuildRunnerWebCompilationProxy extends WebCompilationProxy {
'targets': targets,
'release': release,
},
'flutter_tools|test_entrypoint': <String, dynamic>{
'targets': targets,
'release': release,
},
'flutter_tools|shell': <String, dynamic>{
'targets': targets,
}
@@ -347,6 +365,40 @@ class BuildRunnerWebCompilationProxy extends WebCompilationProxy {
}
}
/// A ddc-only entrypoint builder that respects the Flutter target flag.
class FlutterWebTestEntrypointBuilder implements Builder {
const FlutterWebTestEntrypointBuilder(this.targets);
final List<String> targets;
@override
Map<String, List<String>> get buildExtensions => const <String, List<String>>{
'.dart': <String>[
ddcBootstrapExtension,
jsEntrypointExtension,
jsEntrypointSourceMapExtension,
jsEntrypointArchiveExtension,
digestsEntrypointExtension,
],
};
@override
Future<void> build(BuildStep buildStep) async {
bool matches = false;
for (String target in targets) {
if (buildStep.inputId.path.contains(target)) {
matches = true;
break;
}
}
if (!matches) {
return;
}
log.info('building for target ${buildStep.inputId.path}');
await bootstrapDdc(buildStep, platform: flutterWebPlatform);
}
}
/// A ddc-only entrypoint builder that respects the Flutter target flag.
class FlutterWebEntrypointBuilder implements Builder {
const FlutterWebEntrypointBuilder(this.targets, this.release);

View File

@@ -110,6 +110,7 @@ class TestCommand extends FastFlutterCommand {
@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
DevelopmentArtifact.universal,
DevelopmentArtifact.web,
};
@override

View File

@@ -73,13 +73,16 @@ Future<int> runTests(
.absolute
.uri
.toFilePath();
await webCompilationProxy.initialize(
final bool result = await webCompilationProxy.initialize(
projectDirectory: flutterProject.directory,
testOutputDir: tempBuildDir,
targets: testFiles.map((String testFile) {
return fs.path.relative(testFile, from: flutterProject.directory.path);
}).toList(),
);
if (!result) {
throwToolExit('Failed to compile tests');
}
testArgs.add('--platform=chrome');
testArgs.add('--precompiled=$tempBuildDir');
testArgs.add('--');

View File

@@ -98,16 +98,19 @@ class ChromeLauncher {
'--disable-default-apps',
'--disable-translate',
if (headless)
...<String>['--headless', '--disable-gpu'],
...<String>['--headless', '--disable-gpu', '--no-sandbox'],
url,
];
final Process process = await processManager.start(args);
final Process process = await processManager.start(args, runInShell: true);
// Wait until the DevTools are listening before trying to connect.
await process.stderr
.transform(utf8.decoder)
.transform(const LineSplitter())
.firstWhere((String line) => line.startsWith('DevTools listening'))
.firstWhere((String line) => line.startsWith('DevTools listening'), orElse: () {
return 'Failed to spawn stderr';
})
.timeout(const Duration(seconds: 60), onTimeout: () {
throwToolExit('Unable to connect to Chrome DevTools.');
return null;