Open lijy91 opened 6 months ago
Hmm, this is a bit of a head-scratcher and probably related to package:test
. You can repro with an even smaller example:
@TestOn('browser')
library;
import 'package:test/test.dart';
import 'package:web/web.dart';
void main() {
test('should render', () async {
print(window.parent);
});
}
This same code (window.parent
) succeeds when compiled directly with dart compile js
. The reason why there's a cast failure is because dart2js never set up the interceptors fully. When there's a cast from window.parent
to JSObject?
, we check the object's interceptor. The interceptor doesn't have the $isJSObject
property, because it never ran the code that set that up:
J.JavaScriptObject.prototype = {$isJSObject: 1};
This then leads to the cast failure.
It seems like we directly call the closure which contains the body of the test and never set up any of the dart2js runtime. I believe there's a postMessage
somewhere to execute the test, and maybe that's not calling the right entrypoint, but I'm not too familiar with the package:test
code that does this or who would know more. @jakemac53 any ideas perhaps? I've been using dart test test/smoke_test.dart --platform=chrome --pause-after-load
with the test contents replaced with the above to single step through this.
Error Log:
Steps to Reproduce:
import 'package:test/test.dart'; import 'package:web/web.dart';
void main() { test('should render', () async { document.body!.append(HTMLSpanElement()..text = 'Hello World!!'); print(window.parent); // An error will be thrown here expect(document.body!.children.length, 1); }); }
dart test test/main_test.dart --debug