Skip to content

[ERROR] Deferred library load doesn't work inside browser tests #2088

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

Closed
gmpassos opened this issue Sep 2, 2023 · 9 comments · Fixed by #2090
Closed

[ERROR] Deferred library load doesn't work inside browser tests #2088

gmpassos opened this issue Sep 2, 2023 · 9 comments · Fixed by #2090
Assignees

Comments

@gmpassos
Copy link
Contributor

gmpassos commented Sep 2, 2023

When dart2js is used by the package test it's not
able to serve the ...part.js file.

You can reproduce the bug running the test of this repository:
https://github.com/gmpassos/deferred_lib_issue

dart test -p chrome

Error output:

...

00:08 +0 -1: test/main_test.dart: View Test [E]                                                                                                                                                       
  DeferredLoadException: 'Loading http://localhost:50656/Sa1ttbh3Sd59FoFnteBXDihHx9rZDIUn/test/main_test.dart.browser_test.dart.js_1.part.js?dart2jsRetry=3 failed: Instance of 'Event'
  Context: js-failure-wrapper
  event log:
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"downloadFailure","l":"view_deferred","s":"http://localhost:50656/Sa1ttbh3Sd59FoFnteBXDihHx9rZDIUn/test/main_test.dart.browser_test.dart.js","i":13}
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"download","l":"view_deferred","i":12}
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"startLoad","l":"view_deferred","i":11}
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"retry2","l":"view_deferred","i":10}
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"download","l":"view_deferred","i":9}
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"startLoad","l":"view_deferred","i":8}
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"retry1","l":"view_deferred","i":7}
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"download","l":"view_deferred","i":6}
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"startLoad","l":"view_deferred","i":5}
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"retry0","l":"view_deferred","i":4}
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"download","l":"view_deferred","i":3}
  {"p":"main_test.dart.browser_test.dart.js_1.part.js","e":"startLoad","l":"view_deferred","i":2}
  {"p":"main","e":"beginPart","i":1}
  '

...

Dart Version:

dart --version
Dart SDK version: 3.1.0 (stable) (Tue Aug 15 21:33:36 2023 +0000) on "macos_x64"

The issue can be fixed at:

https://github.com/dart-lang/test/blob/master/pkgs/test/lib/src/runner/browser/platform.dart

@gmpassos
Copy link
Contributor Author

gmpassos commented Sep 5, 2023

It is possible to disable deferred loading on dart2js?

I don't think that test compilation should have deferred loading.

@sigmundch sigmundch transferred this issue from dart-lang/sdk Sep 5, 2023
@sigmundch
Copy link
Member

Thanks so much for filing this issue! I've transferred it to the package:test github issue tracker, since this appears to be an issue there.

Sometimes it's valuable to be able to write tests that use deferred loading, but I agree it can often be helpful to just disable it.

There is a dart2js flag to disable the split: --disable-program-split, so it would just be a matter of plumbing this through.

@sigmundch
Copy link
Member

According to https://pub.dev/packages/test#compiler-flags, it seems possible to pass this flag when invoking the test runner. Does your test work if you pass --dart2js-args="--disable-program-split"? (to be honest, I'm not sure if this is the right flag format)

@gmpassos
Copy link
Contributor Author

gmpassos commented Sep 5, 2023

Thanks for the reply.

I have tested it with --dart2js-args="--disable-program-split" and now it's working (after fix the test).

I have updated the project and added an extra CI workflow job. Now you can see that the test with the default configuration (test_chrome_normal) is failing and the one disabling deferred libraries (test_chrome_disable_program_split) is working:

https://github.com/gmpassos/deferred_lib_issue/actions/runs/6089670634/job/16522963991

  • Faling: dart test --platform chrome

  • Ok: dart test --platform chrome --dart2js-args="--disable-program-split"

@jakemac53
Copy link
Contributor

Would there be a downside to us passing that flag? Is it possible programs could be using deferred libraries incorrectly but their test would pass since we disabled the split?

@sigmundch
Copy link
Member

The flag is designed to preserve semantics, modulo loading files from the network, so the only downside is that it's loading more code upfront that may not be necessary. It's rare that developers want to test the actual network loading in their unit tests, but that's the other piece that would be missing from using the flag.

I think using the flag makes sense, unless you think the alternative is simple to support (e.g. to serve all the .js files together)

@jakemac53
Copy link
Contributor

The flag would be easier, but I am sure we could do it either way.

@jakemac53 jakemac53 self-assigned this Sep 6, 2023
@gmpassos
Copy link
Contributor Author

gmpassos commented Sep 6, 2023

You just need to make 'Dart2JsCompilerPool.compile' to return the output files. Then you can use this list to map the files to serve.

@jakemac53
Copy link
Contributor

You just need to make 'Dart2JsCompilerPool.compile' to return the output files. Then you can use this list to map the files to serve.

Dart2js doesn't actually tell you all the output files, but yeah we can likely just glob for them, which I plan to try first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants