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:
@@ -2,11 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js_interop';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:meta/dart2js.dart';
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
// Tests that the framework prints stack traces in all build modes.
|
||||
//
|
||||
@@ -35,10 +36,12 @@ Future<void> main() async {
|
||||
}
|
||||
|
||||
print(output);
|
||||
html.HttpRequest.request(
|
||||
'/test-result',
|
||||
method: 'POST',
|
||||
sendData: '$output',
|
||||
web.window.fetch(
|
||||
'/test-result'.toJS,
|
||||
web.RequestInit(
|
||||
method: 'POST',
|
||||
body: '$output'.toJS,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js_interop';
|
||||
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
Future<void> main() async {
|
||||
await html.window.navigator.serviceWorker?.ready;
|
||||
const String response = 'CLOSE?version=1';
|
||||
await html.HttpRequest.getString(response);
|
||||
html.document.body?.appendHtml(response);
|
||||
await web.window.navigator.serviceWorker.ready.toDart;
|
||||
final JSString response = 'CLOSE?version=1'.toJS;
|
||||
await web.window.fetch(response).toDart;
|
||||
web.document.body?.append(response);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js_interop';
|
||||
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
Future<void> main() async {
|
||||
const String response = 'CLOSE?version=1';
|
||||
await html.HttpRequest.getString(response);
|
||||
html.document.body?.appendHtml(response);
|
||||
final JSString response = 'CLOSE?version=1'.toJS;
|
||||
await web.window.fetch(response).toDart;
|
||||
web.document.body?.append(response);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
|
||||
// @dart = 2.12
|
||||
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js_interop';
|
||||
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
// Verify that web applications can be run in sound mode.
|
||||
void main() {
|
||||
@@ -16,9 +18,11 @@ void main() {
|
||||
output = '--- TEST SUCCEEDED ---';
|
||||
}
|
||||
print(output);
|
||||
html.HttpRequest.request(
|
||||
'/test-result',
|
||||
method: 'POST',
|
||||
sendData: output,
|
||||
web.window.fetch(
|
||||
'/test-result'.toJS,
|
||||
web.RequestInit(
|
||||
method: 'POST',
|
||||
body: output.toJS,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js_interop';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:meta/dart2js.dart';
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
/// Expected sequence of method calls.
|
||||
const List<String> callChain = <String>['baz', 'bar', 'foo'];
|
||||
@@ -32,7 +33,7 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
|
||||
packageScheme: 'package',
|
||||
package: 'packages',
|
||||
packagePath: 'web_integration/stack_trace.dart',
|
||||
line: 119,
|
||||
line: 122,
|
||||
column: 3,
|
||||
className: '<unknown>',
|
||||
method: 'baz',
|
||||
@@ -43,7 +44,7 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
|
||||
packageScheme: 'package',
|
||||
package: 'packages',
|
||||
packagePath: 'web_integration/stack_trace.dart',
|
||||
line: 114,
|
||||
line: 117,
|
||||
column: 3,
|
||||
className: '<unknown>',
|
||||
method: 'bar',
|
||||
@@ -54,7 +55,7 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
|
||||
packageScheme: 'package',
|
||||
package: 'packages',
|
||||
packagePath: 'web_integration/stack_trace.dart',
|
||||
line: 109,
|
||||
line: 112,
|
||||
column: 3,
|
||||
className: '<unknown>',
|
||||
method: 'foo',
|
||||
@@ -97,10 +98,12 @@ void main() {
|
||||
output.writeln('--- TEST FAILED ---');
|
||||
}
|
||||
print(output);
|
||||
html.HttpRequest.request(
|
||||
'/test-result',
|
||||
method: 'POST',
|
||||
sendData: '$output',
|
||||
web.window.fetch(
|
||||
'/test-result'.toJS,
|
||||
web.RequestInit(
|
||||
method: 'POST',
|
||||
body: '$output'.toJS,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js_interop';
|
||||
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
Future<void> main() async {
|
||||
final StringBuffer output = StringBuffer();
|
||||
@@ -16,9 +18,11 @@ Future<void> main() async {
|
||||
print('--- TEST FAILED ---');
|
||||
}
|
||||
|
||||
html.HttpRequest.request(
|
||||
'/test-result',
|
||||
method: 'POST',
|
||||
sendData: '$output',
|
||||
web.window.fetch(
|
||||
'/test-result'.toJS,
|
||||
web.RequestInit(
|
||||
method: 'POST',
|
||||
body: '$output'.toJS,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,16 +2,20 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js_interop';
|
||||
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
// Attempt to load a file that is hosted in the applications's `web/` directory.
|
||||
Future<void> main() async {
|
||||
try {
|
||||
final html.HttpRequest request = await html.HttpRequest.request(
|
||||
'/example',
|
||||
method: 'GET',
|
||||
);
|
||||
final String? body = request.responseText;
|
||||
final web.Response response = await web.window.fetch(
|
||||
'/example'.toJS,
|
||||
web.RequestInit(
|
||||
method: 'GET',
|
||||
),
|
||||
).toDart;
|
||||
final String body = (await response.text().toDart).toDart;
|
||||
if (body == 'This is an Example') {
|
||||
print('--- TEST SUCCEEDED ---');
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js_interop';
|
||||
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
// Attempt to load CanvasKit resources hosted on gstatic.
|
||||
Future<void> main() async {
|
||||
@@ -12,12 +14,13 @@ Future<void> main() async {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final html.HttpRequest request = await html.HttpRequest.request(
|
||||
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.js',
|
||||
method: 'GET',
|
||||
);
|
||||
final dynamic response = request.response;
|
||||
if (response != null) {
|
||||
final web.Response response = await web.window.fetch(
|
||||
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.js'.toJS,
|
||||
web.RequestInit(
|
||||
method: 'GET',
|
||||
),
|
||||
).toDart;
|
||||
if (response.ok) {
|
||||
print('--- TEST SUCCEEDED ---');
|
||||
} else {
|
||||
print('--- TEST FAILED ---');
|
||||
@@ -27,12 +30,13 @@ Future<void> main() async {
|
||||
print('--- TEST FAILED ---');
|
||||
}
|
||||
try {
|
||||
final html.HttpRequest request = await html.HttpRequest.request(
|
||||
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.wasm',
|
||||
method: 'GET',
|
||||
);
|
||||
final dynamic response = request.response;
|
||||
if (response != null) {
|
||||
final web.Response response = await web.window.fetch(
|
||||
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.wasm'.toJS,
|
||||
web.RequestInit(
|
||||
method: 'GET',
|
||||
)
|
||||
).toDart;
|
||||
if (response.ok) {
|
||||
print('--- TEST SUCCEEDED ---');
|
||||
} else {
|
||||
print('--- TEST FAILED ---');
|
||||
|
||||
@@ -14,10 +14,12 @@ dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
web: 0.5.1
|
||||
|
||||
characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
meta: 1.12.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
|
||||
# PUBSPEC CHECKSUM: 6f95
|
||||
# PUBSPEC CHECKSUM: 8d22
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import 'package:web_integration/a.dart'
|
||||
if (dart.library.io) 'package:web_integration/b.dart' as message1;
|
||||
import 'package:web_integration/c.dart'
|
||||
if (dart.library.html) 'package:web_integration/d.dart' as message2;
|
||||
if (dart.library.js_interop) 'package:web_integration/d.dart' as message2;
|
||||
|
||||
void main() {
|
||||
if (message1.message == 'a' && message2.message == 'd') {
|
||||
|
||||
Reference in New Issue
Block a user