From 184515e46d05dffd0ed63d2975b352cc742366a7 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Wed, 11 Sep 2024 21:08:30 +0000 Subject: [PATCH 1/3] add suitePath getter for retrieving the package relative path of the current suite --- pkgs/test/CHANGELOG.md | 2 ++ pkgs/test_api/CHANGELOG.md | 2 ++ pkgs/test_api/dart_test.yaml | 5 ---- pkgs/test_api/lib/scaffolding.dart | 7 +++++- .../lib/src/backend/remote_listener.dart | 17 +++++++++----- pkgs/test_api/lib/src/scaffolding/utils.dart | 3 +++ pkgs/test_api/mono_pkg.yaml | 2 +- pkgs/test_api/pubspec.yaml | 1 + .../test/import_restrictions_test.dart | 3 +++ pkgs/test_api/test/scaffolding/test_data.txt | 1 + .../test_api/test/scaffolding/utils_test.dart | 16 +++++++++++++ .../test/scaffolding/utils_test_browser.dart | 23 +++++++++++++++++++ .../test/scaffolding/utils_test_io.dart | 22 ++++++++++++++++++ pkgs/test_core/CHANGELOG.md | 2 ++ 14 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 pkgs/test_api/test/scaffolding/test_data.txt create mode 100644 pkgs/test_api/test/scaffolding/utils_test.dart create mode 100644 pkgs/test_api/test/scaffolding/utils_test_browser.dart create mode 100644 pkgs/test_api/test/scaffolding/utils_test_io.dart 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..7421e0706 100644 --- a/pkgs/test_api/pubspec.yaml +++ b/pkgs/test_api/pubspec.yaml @@ -12,6 +12,7 @@ dependencies: async: ^2.5.0 boolean_selector: ^2.1.0 collection: ^1.15.0 + http: ^1.2.2 meta: ^1.14.0 source_span: ^1.8.0 stack_trace: ^1.10.0 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 From c1614bea41f0b7045a4ef3abdeec92df1f800cf2 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Wed, 11 Sep 2024 21:10:03 +0000 Subject: [PATCH 2/3] run test_api tests on all platforms and compilers --- .github/workflows/dart.yml | 12 ++++++------ tool/ci.sh | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) 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/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 .' From ebe0b1237f874f6c5160a6931868e69303fdd318 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Wed, 11 Sep 2024 21:18:14 +0000 Subject: [PATCH 3/3] move http to dev dependency --- pkgs/test_api/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/test_api/pubspec.yaml b/pkgs/test_api/pubspec.yaml index 7421e0706..2dba69b23 100644 --- a/pkgs/test_api/pubspec.yaml +++ b/pkgs/test_api/pubspec.yaml @@ -12,7 +12,6 @@ dependencies: async: ^2.5.0 boolean_selector: ^2.1.0 collection: ^1.15.0 - http: ^1.2.2 meta: ^1.14.0 source_span: ^1.8.0 stack_trace: ^1.10.0 @@ -25,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