在浏览器测试中加载自定义 HTML

Load custom HTML on browser tests

我正在尝试使用自定义 HTML 文件在浏览器 (Chrome) 上编写测试。我关注了 the instructions,这是我所拥有的:

test/
 |- web_test.dart
 |- web_test.html
// test/web_test.dart
@TestOn('browser')

import 'dart:html' as html;

import 'package:flutter_test/flutter_test.dart';

void main() {
  test('It should load the custom html file', () {
    expect(html.document.title, 'Custom HTML file title');
  });
}
<!-- web_test.html -->
<!doctype html>
<html>

<head>
  <title>Custom HTML file title</title>
  <link rel="x-dart-test" href="web_test.dart">
  <script src="packages/test/dart.js"></script>
</head>

</html>

那我运行

flutter test --platform chrome

似乎没有使用自定义 html 文件:

日志:

00:02 +0 -1: It should load the custom html file [E]                                                                                                                                                                                                                                  
  Expected: 'Custom HTML file title'
    Actual: 'web_test.dart Test'
     Which: is different.
            Expected: Custom HTM ...
              Actual: web_test.d ...
                      ^
             Differ at offset 0
  
  dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49      throw_
  packages/test_api/src/expect/async_matcher.dart.js 164:22                         fail
  packages/test_api/src/expect/async_matcher.dart.js 159:12                         _expect
  packages/test_api/src/expect/async_matcher.dart.js 86:12                          expect$
  packages/flutter_test/src/matchers.dart.js 5108:12                                expect$
  web_test.dart.js 20:21                                                            <fn>
  packages/test_api/src/backend/declarer.dart.js 266:17                             <fn>
  dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50                <fn>
  packages/stack_trace/src/stack_zone_specification.dart.js 179:98                  <fn>
  packages/stack_trace/src/stack_zone_specification.dart.js 247:16                  [_run]
  packages/stack_trace/src/stack_zone_specification.dart.js 179:80                  <fn>
  dart-sdk/lib/async/zone.dart 1434:47                                              _rootRunUnary
  dart-sdk/lib/async/zone.dart 1335:19                                              runUnary
  dart-sdk/lib/async/future_impl.dart 159:18                                        handleValue
  dart-sdk/lib/async/future_impl.dart 766:44                                        handleValueCallback
  dart-sdk/lib/async/future_impl.dart 795:13                                        _propagateToListeners
  dart-sdk/lib/async/future_impl.dart 465:9                                         <fn>
  packages/stack_trace/src/stack_zone_specification.dart.js 247:16                  [_run]
  packages/stack_trace/src/stack_zone_specification.dart.js 170:71                  <fn>
  dart-sdk/lib/async/zone.dart 1426:13                                              _rootRun
  dart-sdk/lib/async/zone.dart 1328:19                                              run
  dart-sdk/lib/async/zone.dart 1236:7                                               runGuarded
  dart-sdk/lib/async/zone.dart 1276:23                                              callback
  dart-sdk/lib/async/schedule_microtask.dart 40:11                                  _microtaskLoop
  dart-sdk/lib/async/schedule_microtask.dart 49:5                                   _startMicrotaskLoop
  dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15               <fn>
  ===== asynchronous gap ===========================
  dart-sdk/lib/async/zone.dart 1356:19                                              registerUnaryCallback
  dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 67:19                _async
  packages/test_api/src/backend/declarer.dart.js 264:69                             <fn>
  dart-sdk/lib/async/zone.dart 1426:13                                              _rootRun
  dart-sdk/lib/async/zone.dart 1328:19                                              run
  dart-sdk/lib/async/zone.dart 1860:67                                              _runZoned
  dart-sdk/lib/async/zone.dart 1783:10                                              runZoned
  packages/test_api/src/backend/declarer.dart.js 264:21                             <fn>
  dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
  dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5                _async
  packages/test_api/src/backend/declarer.dart.js 254:90                             <fn>
  packages/test_api/src/backend/declarer.dart.js 733:15                             <fn>
  dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
  dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5                _async
  packages/test_api/src/backend/declarer.dart.js 730:61                             <fn>
  dart-sdk/lib/async/zone.dart 1426:13                                              _rootRun
  dart-sdk/lib/async/zone.dart 1328:19                                              run
  dart-sdk/lib/async/zone.dart 1860:67                                              _runZoned
  dart-sdk/lib/async/zone.dart 1783:10                                              runZoned
  packages/test_api/src/backend/declarer.dart.js 730:13                             [_waitForOutstandingCallbacks]
  packages/test_api/src/backend/declarer.dart.js 812:53                             <fn>
  dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50                <fn>
  packages/stack_trace/src/stack_zone_specification.dart.js 179:98                  <fn>
  packages/stack_trace/src/stack_zone_specification.dart.js 247:16                  [_run]
  packages/stack_trace/src/stack_zone_specification.dart.js 179:80                  <fn>
  dart-sdk/lib/async/zone.dart 1434:47                                              _rootRunUnary
  dart-sdk/lib/async/zone.dart 1335:19                                              runUnary
  dart-sdk/lib/async/future_impl.dart 159:18                                        handleValue
  dart-sdk/lib/async/future_impl.dart 766:44                                        handleValueCallback
  dart-sdk/lib/async/future_impl.dart 795:13                                        _propagateToListeners
  dart-sdk/lib/async/future_impl.dart 592:7                                         [_complete]
  dart-sdk/lib/async/future.dart 252:15                                             <fn>
  packages/stack_trace/src/stack_zone_specification.dart.js 247:16                  [_run]
  packages/stack_trace/src/stack_zone_specification.dart.js 170:71                  <fn>
  dart-sdk/lib/async/zone.dart 1418:47                                              _rootRun
  dart-sdk/lib/async/zone.dart 1328:19                                              run
  dart-sdk/lib/async/zone.dart 1236:7                                               runGuarded
  dart-sdk/lib/async/zone.dart 1276:23                                              <fn>
  packages/stack_trace/src/stack_zone_specification.dart.js 247:16                  [_run]
  packages/stack_trace/src/stack_zone_specification.dart.js 170:71                  <fn>
  dart-sdk/lib/async/zone.dart 1426:13                                              _rootRun
  dart-sdk/lib/async/zone.dart 1328:19                                              run
  dart-sdk/lib/async/zone.dart 1260:23                                              <fn>
  dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19           internalCallback
  ===== asynchronous gap ===========================
  dart-sdk/lib/async/zone.dart 1356:19                                              registerUnaryCallback
  dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 67:19                _async
  packages/test_api/src/backend/declarer.dart.js 809:65                             <fn>
  dart-sdk/lib/async/zone.dart 1426:13                                              _rootRun
  dart-sdk/lib/async/zone.dart 1328:19                                              run
  dart-sdk/lib/async/zone.dart 1860:67                                              _runZoned
  dart-sdk/lib/async/zone.dart 1783:10                                              runZoned
  packages/test_api/src/backend/declarer.dart.js 809:17                             <fn>
  packages/test_api/src/backend/declarer.dart.js 837:9                              [_guardIfGuarded]
  packages/test_api/src/backend/declarer.dart.js 808:30                             <fn>
  packages/stack_trace/src/stack_zone_specification.dart.js 1276:18                 <fn>
  dart-sdk/lib/async/zone.dart 1426:13                                              _rootRun
  dart-sdk/lib/async/zone.dart 1328:19                                              run
  dart-sdk/lib/async/zone.dart 1860:67                                              _runZoned
  dart-sdk/lib/async/zone.dart 1783:10                                              runZoned
  packages/stack_trace/src/stack_zone_specification.dart.js 1274:20                 capture
  packages/test_api/src/backend/declarer.dart.js 807:19                             [_onRun]
  packages/test_api/src/backend/live_test_controller.dart.js 162:20                 run
  packages/test_api/src/backend/remote_listener.dart.js 233:18                      <fn>
  dart-sdk/lib/async/zone.dart 1426:13                                              _rootRun
  dart-sdk/lib/async/zone.dart 1328:19                                              run
  dart-sdk/lib/async/zone.dart 1860:67                                              _runZoned
  dart-sdk/lib/async/zone.dart 1783:10                                              runZoned
  packages/test_api/src/backend/remote_listener.dart.js 232:13                      [_runLiveTest]
  packages/test_api/src/backend/remote_listener.dart.js 208:27                      <fn>
  dart-sdk/lib/async/zone.dart 1434:47                                              _rootRunUnary
  dart-sdk/lib/async/zone.dart 1335:19                                              runUnary
  dart-sdk/lib/async/zone.dart 1244:7                                               runUnaryGuarded
  dart-sdk/lib/async/stream_impl.dart 341:11                                        [_sendData]
  dart-sdk/lib/async/stream_impl.dart 271:7                                         [_add]
  dart-sdk/lib/async/stream_controller.dart 774:19                                  [_sendData]
  dart-sdk/lib/async/stream_controller.dart 648:7                                   [_add]
  dart-sdk/lib/async/stream_controller.dart 596:5                                   add
  dart-sdk/lib/async/zone.dart 1442:13                                              _rootRunUnary
  dart-sdk/lib/async/zone.dart 1335:19                                              runUnary
  dart-sdk/lib/async/zone.dart 1244:7                                               runUnaryGuarded
  dart-sdk/lib/async/stream_impl.dart 341:11                                        [_sendData]
  dart-sdk/lib/async/stream_impl.dart 271:7                                         [_add]
  dart-sdk/lib/async/stream_controller.dart 774:19                                  [_sendData]
  dart-sdk/lib/async/stream_controller.dart 648:7                                   [_add]
  dart-sdk/lib/async/stream_controller.dart 596:5                                   add
  dart-sdk/lib/async/stream_controller.dart 867:13                                  add
  packages/stream_channel/src/stream_channel_controller.dart.js 1295:24             add
  packages/stream_channel/src/stream_channel_controller.dart.js 504:33              <fn>
  dart-sdk/lib/async/zone.dart 1618:10                                              runUnaryGuarded
  dart-sdk/lib/internal/async_cast.dart 85:11                                       [_onData]
  dart-sdk/lib/async/zone.dart 1618:10                                              runUnaryGuarded
  dart-sdk/lib/async/stream_impl.dart 341:11                                        [_sendData]
  dart-sdk/lib/async/stream_impl.dart 271:7                                         [_add]
  dart-sdk/lib/async/stream_controller.dart 774:19                                  [_sendData]
  dart-sdk/lib/async/stream_controller.dart 648:7                                   [_add]
  dart-sdk/lib/async/stream_controller.dart 596:5                                   add
  dart-sdk/lib/async/zone.dart 1618:10                                              runUnaryGuarded
  dart-sdk/lib/async/stream_impl.dart 341:11                                        [_sendData]
  dart-sdk/lib/async/stream_impl.dart 271:7                                         [_add]
  dart-sdk/lib/async/stream_controller.dart 774:19                                  [_sendData]
  dart-sdk/lib/async/stream_controller.dart 648:7                                   [_add]
  dart-sdk/lib/async/stream_controller.dart 596:5                                   add
  dart-sdk/lib/async/stream_controller.dart 867:13                                  add
  dart-sdk/lib/async/zone.dart 1618:10                                              runUnaryGuarded
  dart-sdk/lib/async/stream_impl.dart 341:11                                        [_sendData]
  dart-sdk/lib/async/stream_impl.dart 271:7                                         [_add]
  dart-sdk/lib/async/stream_controller.dart 774:19                                  [_sendData]
  dart-sdk/lib/async/stream_controller.dart 648:7                                   [_add]
  dart-sdk/lib/async/stream_controller.dart 596:5                                   add
  dart-sdk/lib/async/zone.dart 1618:10                                              runUnaryGuarded
  dart-sdk/lib/async/stream_impl.dart 341:11                                        [_sendData]
  dart-sdk/lib/async/stream_impl.dart 271:7                                         [_add]
  dart-sdk/lib/async/stream_controller.dart 774:19                                  [_sendData]
  dart-sdk/lib/async/stream_controller.dart 648:7                                   [_add]
  dart-sdk/lib/async/stream_controller.dart 596:5                                   add
  dart-sdk/lib/async/stream_controller.dart 867:13                                  add
  packages/stream_channel/src/stream_channel_controller.dart.js 1295:24             add
  web_test.dart.test.dart.js 83:31                                                  <fn>
  dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14  _checkAndCall
  dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39  dcall
  dart-sdk/lib/html/dart2js/html_dart2js.dart 37277:58                              <fn>
  
00:02 +0 -1: Some tests failed.

我错过了什么?

代码在 this repository 中可用。

不幸的是,它似乎不受支持。包 test is meant to be run with dart test and not flutter test. See this issue。 在其中,他们建议改为编写集成测试。