dart-lang / test

A library for writing unit tests in Dart.
https://pub.dev/packages/test
495 stars 213 forks source link

Run "pub run test" causes DeferredLoadException #974

Open jumperchen opened 5 years ago

jumperchen commented 5 years ago

Dart version: 2.1.0

Running with the following example causes DeferredLoadException.

For example, dart_test.dart

import 'package:test/test.dart';
import 'dart:async';
import 'dart:html';

import 'app_messages_all.dart';
main () {
    test('test dart DeferredLoadException', () async {
      await initializeMessages('fr');
      expect(1, 1);
    });
}

app_messages_all.dart - refers to - https://github.com/dart-lang/intl_translation/blob/master/test/two_components/app_messages_all.dart

app_messages_fr.dart refers to - https://github.com/dart-lang/intl_translation/blob/master/test/two_components/app_messages_fr.dart

Run with pub run test -p chrome test/dart_test.dart The error stacktrace:

00:14 +0 -1: test dart DeferredLoadException [E]
  DeferredLoadException: 'Loading http://localhost:56336/8dRVv4mrCGoXzAgX6JCzWPoz82uVKZYU/test/dart_issue/dart_test.dart.browser_test.dart.js_1.part.js failed: Instance of 'Event'
  event log:
   - _loadHunk: dart_test.dart.browser_test.dart.js_1.part.js
   - download: dart_test.dart.browser_test.dart.js_1.part.js from http://localhost:56336/8dRVv4mrCGoXzAgX6JCzWPoz82uVKZYU/test/dart_issue/dart_test.dart.browser_test.dart.js_1.part.js
   - download failed: dart_test.dart.browser_test.dart.js_1.part.js (context: js-failure-wrapper)
  '
  org-dartlang-sdk:///sdk/lib/async/future_impl.dart 22:35                      _Completer.completeError
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 213:7   _AsyncAwaitCompleter.completeError
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 295:13  Object._asyncRethrow
  test/dart_issue/app_messages_all.dart 26:7                                    <fn>
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 333:19  _wrapJsFunctionForAsync.closure.$protected
  ===== asynchronous gap ===========================
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1062:19                           _CustomZone.registerBinaryCallback
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 357:15  Object._wrapJsFunctionForAsync
  test/dart_issue/dart_test.dart 8:13                                           <fn>
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 333:19  _wrapJsFunctionForAsync.closure.$protected
  ===== asynchronous gap ===========================
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1062:19                           _CustomZone.registerBinaryCallback
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 357:15  Object._wrapJsFunctionForAsync
  package:test_api                                                              <fn>
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 333:19  _wrapJsFunctionForAsync.closure.$protected
  ===== asynchronous gap ===========================
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1062:19                           _CustomZone.registerBinaryCallback
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 357:15  Object._wrapJsFunctionForAsync
  package:test_api                                                              <fn>
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 333:19  _wrapJsFunctionForAsync.closure.$protected
  ===== asynchronous gap ===========================
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1062:19                           _CustomZone.registerBinaryCallback
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 357:15  Object._wrapJsFunctionForAsync
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1124:12                           _rootRun
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1021:19                           _CustomZone.run
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1516:10                           Object._runZoned
  ===== asynchronous gap ===========================
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1062:19                           _CustomZone.registerBinaryCallback
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 357:15  Object._wrapJsFunctionForAsync
  package:test_api                                                              <fn>
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 333:19  _wrapJsFunctionForAsync.closure.$protected
  ===== asynchronous gap ===========================
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1062:19                           _CustomZone.registerBinaryCallback
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 357:15  Object._wrapJsFunctionForAsync
  org-dartlang-sdk:///sdk/lib/async/future.dart 176:26                          Future.Future.<fn>
  ===== asynchronous gap ===========================
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1045:19                           _CustomZone.registerCallback
  org-dartlang-sdk:///sdk/lib/async/zone.dart 962:22                            _CustomZone.bindCallbackGuarded
  org-dartlang-sdk:///sdk/lib/async/timer.dart 52:37                            Object.Timer.Timer
  org-dartlang-sdk:///sdk/lib/async/timer.dart 87:9                             Object.Future.Future
  package:test_api                                                              <fn>
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 333:19  _wrapJsFunctionForAsync.closure.$protected
  ===== asynchronous gap ===========================
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1062:19                           _CustomZone.registerBinaryCallback
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 357:15  Object._wrapJsFunctionForAsync
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1124:12                           _rootRun
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1021:19                           _CustomZone.run
  org-dartlang-sdk:///sdk/lib/async/zone.dart 1516:10                           Object._runZoned
jakemac53 commented 5 years ago

I wonder if package:test supports deferred loading at all?

Note that for web tests you should get much better test iteration times if you use build_runner, which does support deferred loading (although I haven't tested running tests with deferred loading... but it should work).

To try that you would add a dev dependency on build_runner, build_web_compilers, and build_test. Then you can run pub run build_runner test [build-args-here] -- [test-args-here]. If you want to run your test with dart2js you would pass the -r build argument, otherwise it will use dartdevc (which will compile incrementally much faster).

jakemac53 commented 5 years ago

Also I confirmed package:test does not support deferred loading, https://github.com/dart-lang/test/blob/48a0d09e1b77e5e80e6b18eca6cf32626c6b59b9/pkgs/test/lib/src/runner/browser/platform.dart#L363 It does not add handlers for any extra js files.

jumperchen commented 5 years ago

@jakemac53 Thanks for your suggestion, we will use build_runner test instead. Because of the issue - https://github.com/dart-lang/sdk/issues/35533, we cannot run with DDC mode, only run with Dart2JS mode. :(

jakemac53 commented 5 years ago

Ok, we can leave this open as we should support deferred loading in package:test as well - I think it just hasn't come up as an issue in the past.

jakemac53 commented 5 years ago

Note that the issue you filed above should actually be filed on the https://github.com/dart-lang/build/ repo, which sets up the bootstrapping (not ddc itself - a bit confusing I know). That shouldn't be to difficult to resolve.