mirror of
https://github.com/flutter/packages.git
synced 2025-08-06 00:42:13 +08:00
[ci] Run web tests in wasm (unit + integration). (#8111)
Adds CI configuration to run web integration tests (in the master channel) compiled to Wasm. It also removes the `build-examples` step from web integration tests, in some isolated testing: | platform tests shard | With build-examples | Without build-examples | |---|-----|-----| | 1 | 30m | 21m | | 2 | 13m | 11m | | 3 | 17m | 10m | ## Issues * Fixes https://github.com/flutter/flutter/issues/151664
This commit is contained in:
@ -41,6 +41,8 @@ class DartTestCommand extends PackageLoopingCommand {
|
||||
help: 'Runs tests on the given platform instead of the default platform '
|
||||
'("vm" in most cases, "chrome" for web plugin implementations).',
|
||||
);
|
||||
argParser.addFlag(kWebWasmFlag,
|
||||
help: 'Compile to WebAssembly rather than JavaScript');
|
||||
}
|
||||
|
||||
static const String _platformFlag = 'platform';
|
||||
@ -108,18 +110,21 @@ class DartTestCommand extends PackageLoopingCommand {
|
||||
platform = 'chrome';
|
||||
}
|
||||
|
||||
// Whether to run web tests compiled to wasm.
|
||||
final bool wasm = platform != 'vm' && getBoolArg(kWebWasmFlag);
|
||||
|
||||
bool passed;
|
||||
if (package.requiresFlutter()) {
|
||||
passed = await _runFlutterTests(package, platform: platform);
|
||||
passed = await _runFlutterTests(package, platform: platform, wasm: wasm);
|
||||
} else {
|
||||
passed = await _runDartTests(package, platform: platform);
|
||||
passed = await _runDartTests(package, platform: platform, wasm: wasm);
|
||||
}
|
||||
return passed ? PackageResult.success() : PackageResult.fail();
|
||||
}
|
||||
|
||||
/// Runs the Dart tests for a Flutter package, returning true on success.
|
||||
Future<bool> _runFlutterTests(RepositoryPackage package,
|
||||
{String? platform}) async {
|
||||
{String? platform, bool wasm = false}) async {
|
||||
final String experiment = getStringArg(kEnableExperiment);
|
||||
|
||||
final int exitCode = await processRunner.runAndStream(
|
||||
@ -131,6 +136,7 @@ class DartTestCommand extends PackageLoopingCommand {
|
||||
// Flutter defaults to VM mode (under a different name) and explicitly
|
||||
// setting it is deprecated, so pass nothing in that case.
|
||||
if (platform != null && platform != 'vm') '--platform=$platform',
|
||||
if (wasm) '--wasm',
|
||||
],
|
||||
workingDir: package.directory,
|
||||
);
|
||||
@ -139,7 +145,7 @@ class DartTestCommand extends PackageLoopingCommand {
|
||||
|
||||
/// Runs the Dart tests for a non-Flutter package, returning true on success.
|
||||
Future<bool> _runDartTests(RepositoryPackage package,
|
||||
{String? platform}) async {
|
||||
{String? platform, bool wasm = false}) async {
|
||||
// Unlike `flutter test`, `dart run test` does not automatically get
|
||||
// packages
|
||||
if (!await runPubGet(package, processRunner, super.platform)) {
|
||||
@ -156,6 +162,7 @@ class DartTestCommand extends PackageLoopingCommand {
|
||||
if (experiment.isNotEmpty) '--enable-experiment=$experiment',
|
||||
'test',
|
||||
if (platform != null) '--platform=$platform',
|
||||
if (wasm) '--compiler=dart2wasm',
|
||||
],
|
||||
workingDir: package.directory,
|
||||
);
|
||||
|
@ -337,6 +337,33 @@ test_on: vm && browser
|
||||
);
|
||||
});
|
||||
|
||||
test('runs in Chrome (wasm) when requested for Flutter package', () async {
|
||||
final RepositoryPackage package = createFakePackage(
|
||||
'a_package',
|
||||
packagesDir,
|
||||
isFlutter: true,
|
||||
extraFiles: <String>['test/empty_test.dart'],
|
||||
);
|
||||
|
||||
await runCapturingPrint(
|
||||
runner, <String>['dart-test', '--platform=chrome', '--wasm']);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
orderedEquals(<ProcessCall>[
|
||||
ProcessCall(
|
||||
getFlutterCommand(mockPlatform),
|
||||
const <String>[
|
||||
'test',
|
||||
'--color',
|
||||
'--platform=chrome',
|
||||
'--wasm',
|
||||
],
|
||||
package.path),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('runs in Chrome by default for Flutter plugins that implement web',
|
||||
() async {
|
||||
final RepositoryPackage plugin = createFakePlugin(
|
||||
@ -517,6 +544,33 @@ test_on: vm && browser
|
||||
);
|
||||
});
|
||||
|
||||
test('runs in Chrome (wasm) when requested for Dart package', () async {
|
||||
final RepositoryPackage package = createFakePackage(
|
||||
'package',
|
||||
packagesDir,
|
||||
extraFiles: <String>['test/empty_test.dart'],
|
||||
);
|
||||
|
||||
await runCapturingPrint(
|
||||
runner, <String>['dart-test', '--platform=chrome', '--wasm']);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
orderedEquals(<ProcessCall>[
|
||||
ProcessCall('dart', const <String>['pub', 'get'], package.path),
|
||||
ProcessCall(
|
||||
'dart',
|
||||
const <String>[
|
||||
'run',
|
||||
'test',
|
||||
'--platform=chrome',
|
||||
'--compiler=dart2wasm',
|
||||
],
|
||||
package.path),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('skips running in browser mode if package opts out', () async {
|
||||
final RepositoryPackage package = createFakePackage(
|
||||
'a_package',
|
||||
|
Reference in New Issue
Block a user