Skip to content

Create test_common package #1945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
407 changes: 288 additions & 119 deletions .github/workflows/dart.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Fill `BoundField.name` for records.
- Display records as a container of fields.
- Remove test-only code from `sdk_configuration.dart`.
- Move shared test-only code to a new `test_common` package.

**Breaking changes**
- Require `sdkConfigurationProvider` in `ExpressionCompilerService`
Expand Down
2 changes: 2 additions & 0 deletions dwds/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ dev_dependencies:
puppeteer: ^2.19.0
stream_channel: ^2.1.0
test: ^1.21.1
test_common:
path: ../test_common
webdriver: ^3.0.0
2 changes: 1 addition & 1 deletion dwds/test/build_daemon_callstack_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import 'dart:async';
import 'package:dwds/src/connections/debug_connection.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:vm_service/vm_service.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';
import 'fixtures/logging.dart';

class TestSetup {
static final contextUnsound = TestContext.withWeakNullSafety(
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/chrome_proxy_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import 'package:dwds/src/utilities/shared.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:vm_service/vm_service.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';
import 'fixtures/logging.dart';

final context = TestContext.withSoundNullSafety();

Expand Down
2 changes: 1 addition & 1 deletion dwds/test/dart_uri_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import 'package:dwds/src/loaders/strategy.dart';
import 'package:dwds/src/utilities/dart_uri.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';

import 'fixtures/fakes.dart';
import 'fixtures/logging.dart';

class TestStrategy extends FakeStrategy {
@override
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/evaluate_circular_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import 'dart:async';
import 'package:dwds/src/connections/debug_connection.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:vm_service/vm_service.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';
import 'fixtures/logging.dart';

class TestSetup {
static TestContext contextUnsound(String index) =>
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/evaluate_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import 'dart:async';
import 'package:dwds/src/connections/debug_connection.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:vm_service/vm_service.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';
import 'fixtures/logging.dart';

class TestSetup {
static TestContext contextUnsound(String index) =>
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/events_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import 'package:dwds/src/events.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:dwds/src/utilities/server.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:vm_service/vm_service.dart';
import 'package:webdriver/async_core.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';
import 'fixtures/logging.dart';

ChromeProxyService get service =>
fetchChromeProxyService(context.debugConnection);
Expand Down
11 changes: 6 additions & 5 deletions dwds/test/expression_compiler_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import 'dart:convert';
import 'dart:io';

import 'package:dwds/expression_compiler.dart';
import 'package:dwds/sdk_configuration.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be test_sdk_configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should not need any extra assets, so it is actually good to test it with the current SDK layout. I'll add a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait it is currently running with weak null safety! Will update (so then the statement that it does not need any extra assets will be true:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

import 'package:dwds/src/services/expression_compiler_service.dart';
import 'package:dwds/src/utilities/sdk_configuration.dart';
import 'package:dwds/src/utilities/server.dart';
import 'package:logging/logging.dart';
import 'package:shelf/shelf.dart';
import 'package:test/test.dart';

import 'fixtures/logging.dart';
import 'package:test_common/logging.dart';

ExpressionCompilerService get service => _service!;
late ExpressionCompilerService? _service;
Expand Down Expand Up @@ -47,10 +46,12 @@ void main() async {
final source = outputDir.uri.resolve('try.dart');
final packages = outputDir.uri.resolve('package_config.json');
final kernel = outputDir.uri.resolve('try.full.dill');
// Expression compiler service does not need any extra assets
// generated in the SDK, so we use the current SDK layout and
// configuration.
final executable = Platform.resolvedExecutable;
final dartdevc =
SdkConfiguration.defaultConfiguration.compilerWorkerPath!;

// redirect logs for testing
_output = StreamController<String>.broadcast();
output.stream.listen(printOnFailure);
Expand All @@ -76,7 +77,7 @@ void main() async {
sdkConfigurationProvider: DefaultSdkConfigurationProvider(),
);

await service.initialize(moduleFormat: 'amd');
await service.initialize(moduleFormat: 'amd', soundNullSafety: true);

// setup asset server
serveHttpRequests(server, assetHandler, (e, s) {
Expand Down
6 changes: 4 additions & 2 deletions dwds/test/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ import 'package:path/path.dart' as p;
import 'package:shelf/shelf.dart';
import 'package:shelf_proxy/shelf_proxy.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:test_common/test_sdk_configuration.dart';
import 'package:vm_service/vm_service.dart';
// ignore: deprecated_member_use
import 'package:webdriver/io.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'logging.dart';
import 'server.dart';
import 'test_sdk_configuration.dart';
import 'utilities.dart';

final _exeExt = Platform.isWindows ? '.exe' : '';
Expand Down Expand Up @@ -205,6 +205,7 @@ class TestContext {
// Generate missing SDK assets if needed.
final sdkConfigurationProvider =
TestSdkConfigurationProvider(verboseCompiler: verboseCompiler);
final sdkLayout = sdkConfigurationProvider.sdkLayout;
final configuration = await sdkConfigurationProvider.configuration;
configuration.validate();

Expand Down Expand Up @@ -335,6 +336,7 @@ class TestContext {
soundNullSafety: nullSafety == NullSafety.sound,
experiments: experiments,
verbose: verboseCompiler,
sdkLayout: sdkLayout,
);

final assetServerPort = await findUnusedPort();
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/frontend_server_breakpoint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import 'dart:async';
import 'package:dwds/src/connections/debug_connection.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:vm_service/vm_service.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';
import 'fixtures/logging.dart';

final context = TestContext.withWeakNullSafety(
packageName: '_testPackage',
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/frontend_server_callstack_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import 'dart:async';
import 'package:dwds/src/connections/debug_connection.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:vm_service/vm_service.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';
import 'fixtures/logging.dart';

class TestSetup {
static final contextUnsound = TestContext.withWeakNullSafety(
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/handlers/asset_handler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import 'package:shelf/shelf.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';

import '../fixtures/context.dart';
import '../fixtures/logging.dart';

void main() {
group('Asset handler', () {
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/records_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import 'package:dwds/src/connections/debug_connection.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:vm_service/vm_service.dart';

import 'fixtures/context.dart';
import 'fixtures/logging.dart';

class TestSetup {
TestContext context;
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/reload_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
@Timeout(Duration(minutes: 5))
import 'package:dwds/src/loaders/strategy.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:vm_service/vm_service.dart';

import 'fixtures/context.dart';
import 'fixtures/logging.dart';
import 'fixtures/utilities.dart';

final context = TestContext.withSoundNullSafety(
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/restore_breakpoints_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import 'dart:async';
import 'package:dwds/src/connections/debug_connection.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:vm_service/vm_service.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';
import 'fixtures/logging.dart';

final context = TestContext.withSoundNullSafety();
ChromeProxyService get service =>
Expand Down
55 changes: 11 additions & 44 deletions frontend_server_common/lib/src/devfs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
import 'package:dwds/asset_reader.dart';
import 'package:file/file.dart';
import 'package:path/path.dart' as p;
import 'package:test_common/test_sdk_layout.dart';

import 'asset_server.dart';
import 'bootstrap.dart';
import 'frontend_server_client.dart';
import 'utilities.dart';

final String dartWebSdkPath = p.join(dartSdkPath, 'lib', 'dev_compiler');

class WebDevFS {
WebDevFS({
Expand All @@ -25,6 +23,7 @@ class WebDevFS {
required this.index,
required this.soundNullSafety,
this.urlTunneler,
required this.sdkLayout,
});

final FileSystem fileSystem;
Expand All @@ -36,6 +35,7 @@ class WebDevFS {
final String index;
final UrlEncoder? urlTunneler;
final bool soundNullSafety;
final TestSdkLayout sdkLayout;
late final Directory _savedCurrentDirectory;

Future<Uri> create() async {
Expand Down Expand Up @@ -85,9 +85,9 @@ class WebDevFS {

assetServer.writeFile('main_module.digests', '{}');

var sdk = soundNullSafety ? dartSdkSound : dartSdk;
var sdk = soundNullSafety ? dartSdk : dartSdkWeak;
var sdkSourceMap =
soundNullSafety ? dartSdkSourcemapSound : dartSdkSourcemap;
soundNullSafety ? dartSdkSourcemap : dartSdkSourcemapWeak;
assetServer.writeFile('dart_sdk.js', sdk.readAsStringSync());
assetServer.writeFile('dart_sdk.js.map', sdkSourceMap.readAsStringSync());

Expand Down Expand Up @@ -129,45 +129,12 @@ class WebDevFS {
)..invalidatedModules = modules;
}

File get requireJS => fileSystem.file(fileSystem.path.join(
dartWebSdkPath,
'amd',
'require.js',
));

File get dartSdk => fileSystem.file(fileSystem.path.join(
dartWebSdkPath,
'kernel',
'amd',
'dart_sdk_unsound.js',
));

File get dartSdkSound => fileSystem.file(fileSystem.path.join(
dartWebSdkPath,
'kernel',
'amd',
'dart_sdk.js',
));

File get dartSdkSourcemap => fileSystem.file(fileSystem.path.join(
dartWebSdkPath,
'kernel',
'amd',
'dart_sdk_unsound.js.map',
));

File get dartSdkSourcemapSound => fileSystem.file(fileSystem.path.join(
dartWebSdkPath,
'kernel',
'amd',
'dart_sdk.js.map',
));

File get stackTraceMapper => fileSystem.file(fileSystem.path.join(
dartWebSdkPath,
'web',
'dart_stack_trace_mapper.js',
));
File get requireJS => fileSystem.file(sdkLayout.requireJsPath);
File get dartSdkWeak => fileSystem.file(sdkLayout.weakJsPath);
File get dartSdk => fileSystem.file(sdkLayout.soundJsPath);
File get dartSdkSourcemapWeak => fileSystem.file(sdkLayout.weakJsMapPath);
File get dartSdkSourcemap => fileSystem.file(sdkLayout.soundJsMapPath);
File get stackTraceMapper => fileSystem.file(sdkLayout.stackTraceMapperPath);
}

class UpdateFSReport {
Expand Down
9 changes: 4 additions & 5 deletions frontend_server_common/lib/src/frontend_server_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'dart:io';
import 'package:dwds/expression_compiler.dart';
import 'package:logging/logging.dart';
import 'package:package_config/package_config.dart';
import 'package:path/path.dart' as p;
import 'package:test_common/test_sdk_layout.dart';
import 'package:usage/uuid/uuid.dart';

import 'utilities.dart';
Expand All @@ -24,9 +24,6 @@ void defaultConsumer(String message, {StackTrace? stackTrace}) =>
? _serverLogger.info(message)
: _serverLogger.severe(message, null, stackTrace);

String get frontendServerExecutable =>
p.join(dartSdkPath, 'bin', 'snapshots', 'frontend_server.dart.snapshot');

typedef CompilerMessageConsumer = void Function(String message,
{StackTrace stackTrace});

Expand Down Expand Up @@ -261,6 +258,7 @@ class ResidentCompiler {
required this.platformDill,
required this.soundNullSafety,
this.experiments = const <String>[],
required this.sdkLayout,
this.verbose = false,
CompilerMessageConsumer compilerMessageConsumer = defaultConsumer,
}) : _stdoutHandler = StdoutHandler(consumer: compilerMessageConsumer);
Expand All @@ -273,6 +271,7 @@ class ResidentCompiler {
final String platformDill;
final bool soundNullSafety;
final List<String> experiments;
final TestSdkLayout sdkLayout;
final bool verbose;

/// The path to the root of the Dart SDK used to compile.
Expand Down Expand Up @@ -362,7 +361,7 @@ class ResidentCompiler {

Future<CompilerOutput?> _compile(
String scriptUri, String outputFilePath) async {
var frontendServer = frontendServerExecutable;
var frontendServer = sdkLayout.frontendServerSnapshotPath;
var args = <String>[
frontendServer,
'--sdk-root',
Expand Down
Loading