diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index d0db67731..7158f96d5 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -656,7 +656,7 @@ jobs: - job_005 - job_006 job_017: - name: "unit_test; linux; Dart 3.5.0-311.0.dev; PKG: pkgs/test_api; `dart test --preset travis -x browser`" + name: "unit_test; linux; Dart 3.5.0-311.0.dev; PKG: pkgs/test_api; `dart test -p vm,chrome -c dart2js,dart2wasm,exe,kernel,source`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -681,8 +681,8 @@ jobs: run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: pkgs/test_api - - name: "pkgs/test_api; dart test --preset travis -x browser" - run: dart test --preset travis -x browser + - name: "pkgs/test_api; dart test -p vm,chrome -c dart2js,dart2wasm,exe,kernel,source" + run: "dart test -p vm,chrome -c dart2js,dart2wasm,exe,kernel,source" if: "always() && steps.pkgs_test_api_pub_upgrade.conclusion == 'success'" working-directory: pkgs/test_api needs: @@ -1063,7 +1063,7 @@ jobs: - job_005 - job_006 job_028: - name: "unit_test; linux; Dart dev; PKG: pkgs/test_api; `dart test --preset travis -x browser`" + name: "unit_test; linux; Dart dev; PKG: pkgs/test_api; `dart test -p vm,chrome -c dart2js,dart2wasm,exe,kernel,source`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies @@ -1088,8 +1088,8 @@ jobs: run: dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" working-directory: pkgs/test_api - - name: "pkgs/test_api; dart test --preset travis -x browser" - run: dart test --preset travis -x browser + - name: "pkgs/test_api; dart test -p vm,chrome -c dart2js,dart2wasm,exe,kernel,source" + run: "dart test -p vm,chrome -c dart2js,dart2wasm,exe,kernel,source" if: "always() && steps.pkgs_test_api_pub_upgrade.conclusion == 'success'" working-directory: pkgs/test_api needs: diff --git a/pkgs/test/CHANGELOG.md b/pkgs/test/CHANGELOG.md index cc228ade6..db1d2dc0d 100644 --- a/pkgs/test/CHANGELOG.md +++ b/pkgs/test/CHANGELOG.md @@ -3,6 +3,8 @@ * Fix dart2wasm tests on windows. * Increase SDK constraint to ^3.5.0-311.0.dev. * Support running Node.js tests compiled with dart2wasm. +* Add `suitePath` getter, which can return the package root relative path to + the current test suite being ran, if available ## 1.25.8 diff --git a/pkgs/test_api/CHANGELOG.md b/pkgs/test_api/CHANGELOG.md index 9fc91d676..7ff6dd26d 100644 --- a/pkgs/test_api/CHANGELOG.md +++ b/pkgs/test_api/CHANGELOG.md @@ -2,6 +2,8 @@ * Increase SDK constraint to ^3.5.0-311.0.dev. * Support running Node.js tests compiled with dart2wasm. +* Add `suitePath` getter, which can return the package root relative path to + the current test suite being ran, if available. ## 0.7.3 diff --git a/pkgs/test_api/dart_test.yaml b/pkgs/test_api/dart_test.yaml index faff3bbbd..004149009 100644 --- a/pkgs/test_api/dart_test.yaml +++ b/pkgs/test_api/dart_test.yaml @@ -18,11 +18,6 @@ tags: browser: timeout: 2x - # Browsers can sometimes randomly time out while starting, especially on - # Travis which is pretty slow. Don't retry locally because it makes - # debugging more annoying. - presets: {travis: {retry: 3}} - dart2js: add_tags: [browser] timeout: 2x diff --git a/pkgs/test_api/lib/scaffolding.dart b/pkgs/test_api/lib/scaffolding.dart index 9d864bbb9..a0c6efdf5 100644 --- a/pkgs/test_api/lib/scaffolding.dart +++ b/pkgs/test_api/lib/scaffolding.dart @@ -20,4 +20,9 @@ export 'src/scaffolding/spawn_hybrid.dart' show spawnHybridCode, spawnHybridUri; export 'src/scaffolding/test_structure.dart' show addTearDown, group, setUp, setUpAll, tearDown, tearDownAll, test; export 'src/scaffolding/utils.dart' - show markTestSkipped, printOnFailure, pumpEventQueue, registerException; + show + markTestSkipped, + printOnFailure, + pumpEventQueue, + registerException, + suitePath; diff --git a/pkgs/test_api/lib/src/backend/remote_listener.dart b/pkgs/test_api/lib/src/backend/remote_listener.dart index 66a081428..673826969 100644 --- a/pkgs/test_api/lib/src/backend/remote_listener.dart +++ b/pkgs/test_api/lib/src/backend/remote_listener.dart @@ -119,21 +119,26 @@ final class RemoteListener { await declarer.declare(main); + final path = message['path'] as String; var suite = Suite( declarer.build(), SuitePlatform.deserialize(message['platform'] as Object), - path: message['path'] as String, + path: path, ignoreTimeouts: message['ignoreTimeouts'] as bool? ?? false, ); runZoned(() { Invoker.guard( () => RemoteListener._(suite, printZone)._listen(channel)); - }, - // Make the declarer visible to running tests so that they'll throw - // useful errors when calling `test()` and `group()` within a test, - // and so they can add to the declarer's `tearDownAll()` list. - zoneValues: {#test.declarer: declarer}); + }, zoneValues: { + // Make the declarer visible to running tests so that they'll throw + // useful errors when calling `test()` and `group()` within a test, + // and so they can add to the declarer's `tearDownAll()` list. + #test.declarer: declarer, + // Make the test suite path visible to running tests so that they can + // ask for it, if available. + #test.suitePath: path, + }); }, (error, stackTrace) { _sendError(channel, error, stackTrace, verboseChain); }, zoneSpecification: spec); diff --git a/pkgs/test_api/lib/src/scaffolding/utils.dart b/pkgs/test_api/lib/src/scaffolding/utils.dart index 134dc497c..dbf7412ea 100644 --- a/pkgs/test_api/lib/src/scaffolding/utils.dart +++ b/pkgs/test_api/lib/src/scaffolding/utils.dart @@ -44,6 +44,9 @@ void printOnFailure(String message) { /// test body after marking it as skipped. void markTestSkipped(String message) => _currentInvoker..skip(message); +/// The relative path from the package root to the current test suite, if known. +String? get suitePath => Zone.current[#test.suitePath] as String?; + Invoker get _currentInvoker => Invoker.current ?? (throw StateError( diff --git a/pkgs/test_api/mono_pkg.yaml b/pkgs/test_api/mono_pkg.yaml index 534d9c3ef..b36633ef1 100644 --- a/pkgs/test_api/mono_pkg.yaml +++ b/pkgs/test_api/mono_pkg.yaml @@ -13,7 +13,7 @@ stages: - dev - unit_test: - group: - - command: dart test --preset travis -x browser + - command: dart test -p vm,chrome -c dart2js,dart2wasm,exe,kernel,source os: - linux - windows diff --git a/pkgs/test_api/pubspec.yaml b/pkgs/test_api/pubspec.yaml index 0b8e712c6..2dba69b23 100644 --- a/pkgs/test_api/pubspec.yaml +++ b/pkgs/test_api/pubspec.yaml @@ -24,6 +24,7 @@ dev_dependencies: fake_async: ^1.2.0 glob: ^2.0.0 graphs: ^2.0.0 + http: ^1.2.2 path: ^1.8.0 test: any test_core: any diff --git a/pkgs/test_api/test/import_restrictions_test.dart b/pkgs/test_api/test/import_restrictions_test.dart index 3fd9ffda4..9468e56ce 100644 --- a/pkgs/test_api/test/import_restrictions_test.dart +++ b/pkgs/test_api/test/import_restrictions_test.dart @@ -2,6 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +@TestOn('vm && !exe') +library; + import 'dart:async'; import 'dart:io'; import 'dart:isolate'; diff --git a/pkgs/test_api/test/scaffolding/test_data.txt b/pkgs/test_api/test/scaffolding/test_data.txt new file mode 100644 index 000000000..ce0136250 --- /dev/null +++ b/pkgs/test_api/test/scaffolding/test_data.txt @@ -0,0 +1 @@ +hello diff --git a/pkgs/test_api/test/scaffolding/utils_test.dart b/pkgs/test_api/test/scaffolding/utils_test.dart new file mode 100644 index 000000000..a90bd3958 --- /dev/null +++ b/pkgs/test_api/test/scaffolding/utils_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:test/test.dart'; + +import 'utils_test_browser.dart' if (dart.library.io) 'utils_test_io.dart'; + +void main() { + test('suitePath is available', () { + expect(suitePath, 'test/scaffolding/utils_test.dart'); + }); + + /// Tests specific to the platform we are running on. + platformTests(); +} diff --git a/pkgs/test_api/test/scaffolding/utils_test_browser.dart b/pkgs/test_api/test/scaffolding/utils_test_browser.dart new file mode 100644 index 000000000..26130cb70 --- /dev/null +++ b/pkgs/test_api/test/scaffolding/utils_test_browser.dart @@ -0,0 +1,23 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:http/http.dart'; +import 'package:test/test.dart'; + +void platformTests() { + test( + 'Suite relative paths should be resolved by using Uri.base in the browser', + () async { + // On the web, suite + final resolved = Uri.base.resolve('test_data.txt'); + expect(resolved.scheme, startsWith('http')); + expect(resolved.isAbsolute, true); + expect(resolved.path, endsWith('test/scaffolding/test_data.txt')); + expect( + await get(resolved), + isA() + .having((r) => r.statusCode, 'statusCode', 200) + .having((r) => r.body, 'body', 'hello\n')); + }); +} diff --git a/pkgs/test_api/test/scaffolding/utils_test_io.dart b/pkgs/test_api/test/scaffolding/utils_test_io.dart new file mode 100644 index 000000000..5815b7096 --- /dev/null +++ b/pkgs/test_api/test/scaffolding/utils_test_io.dart @@ -0,0 +1,22 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:io'; + +import 'package:test/test.dart'; + +void platformTests() { + test( + 'Suite relative paths should be resolved by using Uri.base + suitePath ' + 'on the VM', () { + final resolved = Uri.base.resolve(suitePath!).resolve('test_data.txt'); + expect(resolved.scheme, 'file'); + expect(resolved.isAbsolute, true); + expect(resolved.path, + endsWith('pkgs/test_api/test/scaffolding/test_data.txt')); + final file = File.fromUri(resolved); + expect(file.existsSync(), true); + expect(file.readAsStringSync(), 'hello\n'); + }); +} diff --git a/pkgs/test_core/CHANGELOG.md b/pkgs/test_core/CHANGELOG.md index 610311022..4d1101dbd 100644 --- a/pkgs/test_core/CHANGELOG.md +++ b/pkgs/test_core/CHANGELOG.md @@ -3,6 +3,8 @@ * Fix dart2wasm tests on windows. * Increase SDK constraint to ^3.5.0-311.0.dev. * Allow passing additional arguments to `dart compile wasm`. +* Add `suitePath` getter, which can return the package root relative path to + the current test suite being ran, if available ## 0.6.5 diff --git a/tool/ci.sh b/tool/ci.sh index 040c70df8..8d2f819f9 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -116,8 +116,8 @@ for PKG in ${PKGS}; do dart test --preset travis --total-shards 5 --shard-index 4 || EXIT_CODE=$? ;; command_11) - echo 'dart test --preset travis -x browser' - dart test --preset travis -x browser || EXIT_CODE=$? + echo 'dart test -p vm,chrome -c dart2js,dart2wasm,exe,kernel,source' + dart test -p vm,chrome -c dart2js,dart2wasm,exe,kernel,source || EXIT_CODE=$? ;; format) echo 'dart format --output=none --set-exit-if-changed .'