@@ -52,6 +52,8 @@ class BrowserWasmPlatform extends PlatformPlugin
52
52
Uri .parse ('package:test/src/runner/browser/static/favicon.ico' ))),
53
53
p.fromUri (packageConfig.resolve (
54
54
Uri .parse ('package:test/src/runner/wasm/static/default.html.tpl' ))),
55
+ p.fromUri (packageConfig.resolve (
56
+ Uri .parse ('package:test/src/runner/wasm/static/run_wasm_chrome.js' ))),
55
57
root: root);
56
58
}
57
59
@@ -117,8 +119,11 @@ class BrowserWasmPlatform extends PlatformPlugin
117
119
/// The default template for html tests.
118
120
final String _defaultTemplatePath;
119
121
122
+ /// The `package:test` side wrapper for the Dart2Wasm runtime.
123
+ final String _jsRuntimeWrapper;
124
+
120
125
BrowserWasmPlatform ._(this ._server, Configuration config, String faviconPath,
121
- this ._defaultTemplatePath,
126
+ this ._defaultTemplatePath, this ._jsRuntimeWrapper,
122
127
{String ? root})
123
128
: _config = config,
124
129
_root = root ?? p.current {
@@ -159,9 +164,13 @@ class BrowserWasmPlatform extends PlatformPlugin
159
164
var testName = htmlEscape.convert (test);
160
165
var template = _config.customHtmlTemplatePath ?? _defaultTemplatePath;
161
166
var contents = File (template).readAsStringSync ();
167
+ var jsRuntime = 'dart2wasm_runtime.mjs' ;
162
168
var processedContents = contents
163
169
// Checked during loading phase that there is only one {{testScript}} placeholder.
164
170
.replaceFirst ('{{testScript}}' , link)
171
+ .replaceFirst ('{{jsRuntimeUrl}}' , jsRuntime)
172
+ .replaceFirst ('{{wasmUrl}}' ,
173
+ p.basename ('$test .browser_test.dart.wasm' ))
165
174
.replaceAll ('{{testName}}' , testName);
166
175
return shelf.Response .ok (processedContents,
167
176
headers: {'Content-Type' : 'text/html' });
@@ -235,13 +244,14 @@ class BrowserWasmPlatform extends PlatformPlugin
235
244
return _compileFutures.putIfAbsent (dartPath, () async {
236
245
var dir = Directory (_compiledDir).createTempSync ('test_' ).path;
237
246
238
- // TODO: Update this path to the actual wasm output file path.
239
- var wasmCompiledPath =
240
- p.join (dir, '${p .basename (dartPath )}.browser_test.dart.js' );
241
- // TODO: Update this to the actual url we want to serve the compiled WASM
242
- // file(s).
243
- var wasmUrl = '${p .toUri (p .relative (dartPath , from : _root )).path }'
244
- '.browser_test.dart.js' ;
247
+ var baseCompiledPath =
248
+ p.join (dir, '${p .basename (dartPath )}.browser_test.dart' );
249
+ var baseUrl =
250
+ '${p .toUri (p .relative (dartPath , from : _root )).path }.browser_test.dart' ;
251
+ var wasmUrl = '$baseUrl .wasm' ;
252
+ var jsRuntimeWrapperUrl = '$baseUrl .js' ;
253
+ var jsRuntimeUrl = p.join (p.dirname (dartPath), 'dart2wasm_runtime.mjs' );
254
+ var htmlUrl = '$baseUrl .html' ;
245
255
246
256
// TODO: This may need to be specialized, or it may just work. Not sure.
247
257
var bootstrapContent = '''
@@ -255,21 +265,31 @@ class BrowserWasmPlatform extends PlatformPlugin
255
265
}
256
266
''' ;
257
267
258
- await _compilers.compile (bootstrapContent, wasmCompiledPath , suiteConfig);
268
+ await _compilers.compile (bootstrapContent, baseCompiledPath , suiteConfig);
259
269
if (_closed) return ;
260
270
261
- var bootstrapUrl = '${p .toUri (p .relative (dartPath , from : _root )).path }'
262
- '.browser_test.dart' ;
263
- _wasmHandler.add (bootstrapUrl, (request) {
264
- return shelf.Response .ok (bootstrapContent,
265
- headers: {'Content-Type' : 'application/dart' });
271
+ var wasmPath = '$baseCompiledPath .wasm' ;
272
+ _wasmHandler.add (wasmUrl, (request) {
273
+ return shelf.Response .ok (File (wasmPath).readAsBytesSync (),
274
+ headers: {'Content-Type' : 'application/wasm' });
266
275
});
267
276
268
- _wasmHandler.add (wasmUrl, (request) {
269
- // TODO: Update this with proper headers at a minimum.
270
- return shelf.Response .ok (File (wasmCompiledPath).readAsBytesSync (),
277
+ _wasmHandler.add (jsRuntimeWrapperUrl, (request) {
278
+ return shelf.Response .ok (File (_jsRuntimeWrapper).readAsBytesSync (),
271
279
headers: {'Content-Type' : 'application/javascript' });
272
280
});
281
+
282
+ var jsRuntimePath = p.join (dir, 'dart2wasm_runtime.mjs' );
283
+ _wasmHandler.add (jsRuntimeUrl, (request) {
284
+ return shelf.Response .ok (File (jsRuntimePath).readAsBytesSync (),
285
+ headers: {'Content-Type' : 'application/javascript' });
286
+ });
287
+
288
+ var htmlPath = '$baseCompiledPath .html' ;
289
+ _wasmHandler.add (htmlUrl, (request) {
290
+ return shelf.Response .ok (File (htmlPath).readAsBytesSync (),
291
+ headers: {'Content-Type' : 'text/html' });
292
+ });
273
293
});
274
294
}
275
295
0 commit comments