flutter test --wasm support (#145347)
* Adds support for `flutter test --wasm`. * The test compilation flow is a bit different now, so that it supports compilers other than DDC. Specifically, when we run a set of unit tests, we generate a "switchboard" main function that imports each unit test and runs the main function for a specific one based off of a value set by the JS bootstrapping code. This way, there is one compile step and the same compile output is invoked for each unit test file. * Also, removes all references to `dart:html` from flutter/flutter. * Adds CI steps for running the framework unit tests with dart2wasm+skwasm * These steps are marked as `bringup: true`, so we don't know what kind of failures they will result in. Any failures they have will not block the tree at all yet while we're still in `bringup: true`. Once this PR is merged, I plan on looking at any failures and either fixing them or disabling them so we can get these CI steps running on presubmit. This fixes https://github.com/flutter/flutter/issues/126692
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [_extension_web.dart], which has the dart:html implementation
|
||||
/// * [_extension_web.dart], which has the web implementation
|
||||
void registerWebServiceExtension(Future<Map<String, dynamic>> Function(Map<String, String>) call) {
|
||||
throw UnsupportedError('Use registerServiceExtension instead');
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js';
|
||||
import 'dart:js_util' as js_util;
|
||||
import 'dart:js_interop';
|
||||
import 'dart:js_interop_unsafe';
|
||||
|
||||
/// The dart:html implementation of [registerWebServiceExtension].
|
||||
@JS('window')
|
||||
external JSObject get _window;
|
||||
|
||||
/// The web implementation of [registerWebServiceExtension].
|
||||
///
|
||||
/// Registers Web Service Extension for Flutter Web application.
|
||||
///
|
||||
@@ -21,13 +23,13 @@ void registerWebServiceExtension(Future<Map<String, dynamic>> Function(Map<Strin
|
||||
// Define the result variable because packages/flutter_driver/lib/src/driver/web_driver.dart
|
||||
// checks for this value to become non-null when waiting for the result. If this value is
|
||||
// undefined at the time of the check, WebDriver throws an exception.
|
||||
context[r'$flutterDriverResult'] = null;
|
||||
_window.setProperty(r'$flutterDriverResult'.toJS, null);
|
||||
|
||||
js_util.setProperty(html.window, r'$flutterDriver', allowInterop((dynamic message) async {
|
||||
_window.setProperty(r'$flutterDriver'.toJS, (JSAny message) {
|
||||
final Map<String, String> params = Map<String, String>.from(
|
||||
jsonDecode(message as String) as Map<String, dynamic>);
|
||||
final Map<String, dynamic> result = Map<String, dynamic>.from(
|
||||
await call(params));
|
||||
context[r'$flutterDriverResult'] = json.encode(result);
|
||||
}));
|
||||
jsonDecode((message as JSString).toDart) as Map<String, dynamic>);
|
||||
call(params).then((Map<String, dynamic> result) {
|
||||
_window.setProperty(r'$flutterDriverResult'.toJS, json.encode(result).toJS);
|
||||
});
|
||||
}.toJS);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import '../common/error.dart';
|
||||
import '../common/find.dart';
|
||||
import '../common/handler_factory.dart';
|
||||
import '../common/message.dart';
|
||||
import '_extension_io.dart' if (dart.library.html) '_extension_web.dart';
|
||||
import '_extension_io.dart' if (dart.library.js_interop) '_extension_web.dart';
|
||||
|
||||
const String _extensionMethodName = 'driver';
|
||||
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:js' as js;
|
||||
import 'dart:js_interop';
|
||||
import 'dart:js_interop_unsafe';
|
||||
|
||||
import 'package:flutter_driver/src/extension/_extension_web.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@JS('window')
|
||||
external JSObject get _window;
|
||||
|
||||
void main() {
|
||||
group('test web_extension', () {
|
||||
late Future<Map<String, dynamic>> Function(Map<String, String>) call;
|
||||
@@ -21,11 +25,11 @@ void main() {
|
||||
expect(() => registerWebServiceExtension(call),
|
||||
returnsNormally);
|
||||
|
||||
expect(js.context.hasProperty(r'$flutterDriver'), true);
|
||||
expect(js.context[r'$flutterDriver'], isNotNull);
|
||||
expect(_window.hasProperty(r'$flutterDriver'.toJS).toDart, true);
|
||||
expect(_window.getProperty(r'$flutterDriver'.toJS), isNotNull);
|
||||
|
||||
expect(js.context.hasProperty(r'$flutterDriverResult'), true);
|
||||
expect(js.context[r'$flutterDriverResult'], isNull);
|
||||
expect(_window.hasProperty(r'$flutterDriverResult'.toJS).toDart, true);
|
||||
expect(_window.getProperty(r'$flutterDriverResult'.toJS), isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user