Write the package config location to the test bootstrap. (#150440)
Work towards. This is the Flutter companion to https://github.com/dart-lang/test/pull/2245. Work towards https://github.com/dart-lang/test/issues/2246.
This commit is contained in:
parent
9ab8b6e150
commit
5ebc993dff
@ -618,6 +618,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
|
|||||||
integrationTestUserIdentifier: stringArg(FlutterOptions.kDeviceUser),
|
integrationTestUserIdentifier: stringArg(FlutterOptions.kDeviceUser),
|
||||||
testTimeRecorder: testTimeRecorder,
|
testTimeRecorder: testTimeRecorder,
|
||||||
nativeAssetsBuilder: nativeAssetsBuilder,
|
nativeAssetsBuilder: nativeAssetsBuilder,
|
||||||
|
buildInfo: buildInfo,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
testTimeRecorder?.stop(TestTimePhases.TestRunner, testRunnerTimeRecorderStopwatch!);
|
testTimeRecorder?.stop(TestTimePhases.TestRunner, testRunnerTimeRecorderStopwatch!);
|
||||||
|
@ -15,6 +15,7 @@ import 'package:test_core/src/platform.dart'; // ignore: implementation_imports
|
|||||||
import '../base/common.dart';
|
import '../base/common.dart';
|
||||||
import '../base/file_system.dart';
|
import '../base/file_system.dart';
|
||||||
import '../base/io.dart';
|
import '../base/io.dart';
|
||||||
|
import '../build_info.dart';
|
||||||
import '../cache.dart';
|
import '../cache.dart';
|
||||||
import '../compile.dart';
|
import '../compile.dart';
|
||||||
import '../convert.dart';
|
import '../convert.dart';
|
||||||
@ -71,6 +72,7 @@ FlutterPlatform installHook({
|
|||||||
TestTimeRecorder? testTimeRecorder,
|
TestTimeRecorder? testTimeRecorder,
|
||||||
UriConverter? uriConverter,
|
UriConverter? uriConverter,
|
||||||
TestCompilerNativeAssetsBuilder? nativeAssetsBuilder,
|
TestCompilerNativeAssetsBuilder? nativeAssetsBuilder,
|
||||||
|
BuildInfo? buildInfo,
|
||||||
}) {
|
}) {
|
||||||
assert(enableVmService || enableObservatory || (!debuggingOptions.startPaused && debuggingOptions.hostVmServicePort == null));
|
assert(enableVmService || enableObservatory || (!debuggingOptions.startPaused && debuggingOptions.hostVmServicePort == null));
|
||||||
|
|
||||||
@ -102,6 +104,7 @@ FlutterPlatform installHook({
|
|||||||
testTimeRecorder: testTimeRecorder,
|
testTimeRecorder: testTimeRecorder,
|
||||||
uriConverter: uriConverter,
|
uriConverter: uriConverter,
|
||||||
nativeAssetsBuilder: nativeAssetsBuilder,
|
nativeAssetsBuilder: nativeAssetsBuilder,
|
||||||
|
buildInfo: buildInfo,
|
||||||
);
|
);
|
||||||
platformPluginRegistration(platform);
|
platformPluginRegistration(platform);
|
||||||
return platform;
|
return platform;
|
||||||
@ -120,6 +123,9 @@ FlutterPlatform installHook({
|
|||||||
/// configuration files as outlined in the [flutter_test] library. By default,
|
/// configuration files as outlined in the [flutter_test] library. By default,
|
||||||
/// the test file will be launched directly.
|
/// the test file will be launched directly.
|
||||||
///
|
///
|
||||||
|
/// The [packageConfigUri] argument specifies the package config location for
|
||||||
|
/// the test file being launched. This is expected to be a file URI.
|
||||||
|
///
|
||||||
/// The [updateGoldens] argument will set the [autoUpdateGoldens] global
|
/// The [updateGoldens] argument will set the [autoUpdateGoldens] global
|
||||||
/// variable in the [flutter_test] package before invoking the test.
|
/// variable in the [flutter_test] package before invoking the test.
|
||||||
///
|
///
|
||||||
@ -132,6 +138,7 @@ String generateTestBootstrap({
|
|||||||
required Uri testUrl,
|
required Uri testUrl,
|
||||||
required InternetAddress host,
|
required InternetAddress host,
|
||||||
File? testConfigFile,
|
File? testConfigFile,
|
||||||
|
Uri? packageConfigUri,
|
||||||
bool updateGoldens = false,
|
bool updateGoldens = false,
|
||||||
String languageVersionHeader = '',
|
String languageVersionHeader = '',
|
||||||
bool nullSafety = false,
|
bool nullSafety = false,
|
||||||
@ -174,6 +181,15 @@ import '$testUrl' as test;
|
|||||||
import '${Uri.file(testConfigFile.path)}' as test_config;
|
import '${Uri.file(testConfigFile.path)}' as test_config;
|
||||||
''');
|
''');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IMPORTANT: DO NOT RENAME, REMOVE, OR MODIFY THE
|
||||||
|
// 'const packageConfigLocation' VARIABLE.
|
||||||
|
// Dash tooling like Dart DevTools performs an evaluation on this variable at
|
||||||
|
// runtime to get the package config location for Flutter test targets.
|
||||||
|
buffer.write('''
|
||||||
|
|
||||||
|
const packageConfigLocation = '$packageConfigUri';
|
||||||
|
''');
|
||||||
buffer.write('''
|
buffer.write('''
|
||||||
|
|
||||||
/// Returns a serialized test suite.
|
/// Returns a serialized test suite.
|
||||||
@ -295,6 +311,7 @@ class FlutterPlatform extends PlatformPlugin {
|
|||||||
this.testTimeRecorder,
|
this.testTimeRecorder,
|
||||||
this.uriConverter,
|
this.uriConverter,
|
||||||
this.nativeAssetsBuilder,
|
this.nativeAssetsBuilder,
|
||||||
|
this.buildInfo,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String shellPath;
|
final String shellPath;
|
||||||
@ -312,6 +329,7 @@ class FlutterPlatform extends PlatformPlugin {
|
|||||||
final String? icudtlPath;
|
final String? icudtlPath;
|
||||||
final TestTimeRecorder? testTimeRecorder;
|
final TestTimeRecorder? testTimeRecorder;
|
||||||
final TestCompilerNativeAssetsBuilder? nativeAssetsBuilder;
|
final TestCompilerNativeAssetsBuilder? nativeAssetsBuilder;
|
||||||
|
final BuildInfo? buildInfo;
|
||||||
|
|
||||||
// This can be used by internal projects that require custom logic for converting package: URIs to local paths.
|
// This can be used by internal projects that require custom logic for converting package: URIs to local paths.
|
||||||
final UriConverter? uriConverter;
|
final UriConverter? uriConverter;
|
||||||
@ -641,6 +659,8 @@ class FlutterPlatform extends PlatformPlugin {
|
|||||||
return generateTestBootstrap(
|
return generateTestBootstrap(
|
||||||
testUrl: testUrl,
|
testUrl: testUrl,
|
||||||
testConfigFile: findTestConfigFile(globals.fs.file(testUrl), globals.logger),
|
testConfigFile: findTestConfigFile(globals.fs.file(testUrl), globals.logger),
|
||||||
|
// This MUST be a file URI.
|
||||||
|
packageConfigUri: buildInfo != null ? globals.fs.path.toUri(buildInfo!.packageConfigPath) : null,
|
||||||
host: host!,
|
host: host!,
|
||||||
updateGoldens: updateGoldens!,
|
updateGoldens: updateGoldens!,
|
||||||
flutterTestDep: packageConfig['flutter_test'] != null,
|
flutterTestDep: packageConfig['flutter_test'] != null,
|
||||||
|
@ -64,6 +64,7 @@ abstract class FlutterTestRunner {
|
|||||||
String? integrationTestUserIdentifier,
|
String? integrationTestUserIdentifier,
|
||||||
TestTimeRecorder? testTimeRecorder,
|
TestTimeRecorder? testTimeRecorder,
|
||||||
TestCompilerNativeAssetsBuilder? nativeAssetsBuilder,
|
TestCompilerNativeAssetsBuilder? nativeAssetsBuilder,
|
||||||
|
BuildInfo? buildInfo,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Runs tests using the experimental strategy of spawning each test in a
|
/// Runs tests using the experimental strategy of spawning each test in a
|
||||||
@ -131,6 +132,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
|||||||
String? integrationTestUserIdentifier,
|
String? integrationTestUserIdentifier,
|
||||||
TestTimeRecorder? testTimeRecorder,
|
TestTimeRecorder? testTimeRecorder,
|
||||||
TestCompilerNativeAssetsBuilder? nativeAssetsBuilder,
|
TestCompilerNativeAssetsBuilder? nativeAssetsBuilder,
|
||||||
|
BuildInfo? buildInfo,
|
||||||
}) async {
|
}) async {
|
||||||
// Configure package:test to use the Flutter engine for child processes.
|
// Configure package:test to use the Flutter engine for child processes.
|
||||||
final String shellPath = globals.artifacts!.getArtifactPath(Artifact.flutterTester);
|
final String shellPath = globals.artifacts!.getArtifactPath(Artifact.flutterTester);
|
||||||
@ -258,6 +260,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
|||||||
integrationTestUserIdentifier: integrationTestUserIdentifier,
|
integrationTestUserIdentifier: integrationTestUserIdentifier,
|
||||||
testTimeRecorder: testTimeRecorder,
|
testTimeRecorder: testTimeRecorder,
|
||||||
nativeAssetsBuilder: nativeAssetsBuilder,
|
nativeAssetsBuilder: nativeAssetsBuilder,
|
||||||
|
buildInfo: buildInfo,
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -13,6 +13,7 @@ import 'package:flutter_tools/src/base/common.dart';
|
|||||||
import 'package:flutter_tools/src/base/file_system.dart';
|
import 'package:flutter_tools/src/base/file_system.dart';
|
||||||
import 'package:flutter_tools/src/base/logger.dart';
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
import 'package:flutter_tools/src/base/terminal.dart';
|
import 'package:flutter_tools/src/base/terminal.dart';
|
||||||
|
import 'package:flutter_tools/src/build_info.dart';
|
||||||
import 'package:flutter_tools/src/cache.dart';
|
import 'package:flutter_tools/src/cache.dart';
|
||||||
import 'package:flutter_tools/src/commands/test.dart';
|
import 'package:flutter_tools/src/commands/test.dart';
|
||||||
import 'package:flutter_tools/src/device.dart';
|
import 'package:flutter_tools/src/device.dart';
|
||||||
@ -1479,6 +1480,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
|
|||||||
String? integrationTestUserIdentifier,
|
String? integrationTestUserIdentifier,
|
||||||
TestTimeRecorder? testTimeRecorder,
|
TestTimeRecorder? testTimeRecorder,
|
||||||
TestCompilerNativeAssetsBuilder? nativeAssetsBuilder,
|
TestCompilerNativeAssetsBuilder? nativeAssetsBuilder,
|
||||||
|
BuildInfo? buildInfo,
|
||||||
}) async {
|
}) async {
|
||||||
lastEnableVmServiceValue = enableVmService;
|
lastEnableVmServiceValue = enableVmService;
|
||||||
lastDebuggingOptionsValue = debuggingOptions;
|
lastDebuggingOptionsValue = debuggingOptions;
|
||||||
|
@ -122,4 +122,41 @@ void main() {
|
|||||||
expect(flutterPlatform.uriConverter?.call('hello'), 'hello/test');
|
expect(flutterPlatform.uriConverter?.call('hello'), 'hello/test');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group('generateTestBootstrap', () {
|
||||||
|
group('writes a "const packageConfigLocation" string', () {
|
||||||
|
test('with null packageConfigUri', () {
|
||||||
|
final String contents = generateTestBootstrap(
|
||||||
|
testUrl:
|
||||||
|
Uri.parse('file:///Users/me/some_package/test/some_test.dart'),
|
||||||
|
host: InternetAddress('127.0.0.1', type: InternetAddressType.IPv4),
|
||||||
|
);
|
||||||
|
// IMPORTANT: DO NOT RENAME, REMOVE, OR MODIFY THE
|
||||||
|
// 'const packageConfigLocation' VARIABLE.
|
||||||
|
// Dash tooling like Dart DevTools performs an evaluation on this variable
|
||||||
|
// at runtime to get the package config location for Flutter test targets.
|
||||||
|
expect(contents, contains("const packageConfigLocation = 'null';"));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('with non-null packageConfigUri', () {
|
||||||
|
final String contents = generateTestBootstrap(
|
||||||
|
testUrl:
|
||||||
|
Uri.parse('file:///Users/me/some_package/test/some_test.dart'),
|
||||||
|
host: InternetAddress('127.0.0.1', type: InternetAddressType.IPv4),
|
||||||
|
packageConfigUri: Uri.parse(
|
||||||
|
'file:///Users/me/some_package/.dart_tool/package_config.json'),
|
||||||
|
);
|
||||||
|
// IMPORTANT: DO NOT RENAME, REMOVE, OR MODIFY THE
|
||||||
|
// 'const packageConfigLocation' VARIABLE.
|
||||||
|
// Dash tooling like Dart DevTools performs an evaluation on this variable
|
||||||
|
// at runtime to get the package config location for Flutter test targets.
|
||||||
|
expect(
|
||||||
|
contents,
|
||||||
|
contains(
|
||||||
|
"const packageConfigLocation = 'file:///Users/me/some_package/.dart_tool/package_config.json';",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user