Skip to content

Commit 184515e

Browse files
committed
add suitePath getter for retrieving the package relative path of the current suite
1 parent 9a2d155 commit 184515e

File tree

14 files changed

+93
-13
lines changed

14 files changed

+93
-13
lines changed

pkgs/test/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Fix dart2wasm tests on windows.
44
* Increase SDK constraint to ^3.5.0-311.0.dev.
55
* Support running Node.js tests compiled with dart2wasm.
6+
* Add `suitePath` getter, which can return the package root relative path to
7+
the current test suite being ran, if available
68

79
## 1.25.8
810

pkgs/test_api/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Increase SDK constraint to ^3.5.0-311.0.dev.
44
* Support running Node.js tests compiled with dart2wasm.
5+
* Add `suitePath` getter, which can return the package root relative path to
6+
the current test suite being ran, if available.
57

68
## 0.7.3
79

pkgs/test_api/dart_test.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ tags:
1818
browser:
1919
timeout: 2x
2020

21-
# Browsers can sometimes randomly time out while starting, especially on
22-
# Travis which is pretty slow. Don't retry locally because it makes
23-
# debugging more annoying.
24-
presets: {travis: {retry: 3}}
25-
2621
dart2js:
2722
add_tags: [browser]
2823
timeout: 2x

pkgs/test_api/lib/scaffolding.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ export 'src/scaffolding/spawn_hybrid.dart' show spawnHybridCode, spawnHybridUri;
2020
export 'src/scaffolding/test_structure.dart'
2121
show addTearDown, group, setUp, setUpAll, tearDown, tearDownAll, test;
2222
export 'src/scaffolding/utils.dart'
23-
show markTestSkipped, printOnFailure, pumpEventQueue, registerException;
23+
show
24+
markTestSkipped,
25+
printOnFailure,
26+
pumpEventQueue,
27+
registerException,
28+
suitePath;

pkgs/test_api/lib/src/backend/remote_listener.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,26 @@ final class RemoteListener {
119119

120120
await declarer.declare(main);
121121

122+
final path = message['path'] as String;
122123
var suite = Suite(
123124
declarer.build(),
124125
SuitePlatform.deserialize(message['platform'] as Object),
125-
path: message['path'] as String,
126+
path: path,
126127
ignoreTimeouts: message['ignoreTimeouts'] as bool? ?? false,
127128
);
128129

129130
runZoned(() {
130131
Invoker.guard(
131132
() => RemoteListener._(suite, printZone)._listen(channel));
132-
},
133-
// Make the declarer visible to running tests so that they'll throw
134-
// useful errors when calling `test()` and `group()` within a test,
135-
// and so they can add to the declarer's `tearDownAll()` list.
136-
zoneValues: {#test.declarer: declarer});
133+
}, zoneValues: {
134+
// Make the declarer visible to running tests so that they'll throw
135+
// useful errors when calling `test()` and `group()` within a test,
136+
// and so they can add to the declarer's `tearDownAll()` list.
137+
#test.declarer: declarer,
138+
// Make the test suite path visible to running tests so that they can
139+
// ask for it, if available.
140+
#test.suitePath: path,
141+
});
137142
}, (error, stackTrace) {
138143
_sendError(channel, error, stackTrace, verboseChain);
139144
}, zoneSpecification: spec);

pkgs/test_api/lib/src/scaffolding/utils.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ void printOnFailure(String message) {
4444
/// test body after marking it as skipped.
4545
void markTestSkipped(String message) => _currentInvoker..skip(message);
4646

47+
/// The relative path from the package root to the current test suite, if known.
48+
String? get suitePath => Zone.current[#test.suitePath] as String?;
49+
4750
Invoker get _currentInvoker =>
4851
Invoker.current ??
4952
(throw StateError(

pkgs/test_api/mono_pkg.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ stages:
1313
- dev
1414
- unit_test:
1515
- group:
16-
- command: dart test --preset travis -x browser
16+
- command: dart test -p vm,chrome -c dart2js,dart2wasm,exe,kernel,source
1717
os:
1818
- linux
1919
- windows

pkgs/test_api/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies:
1212
async: ^2.5.0
1313
boolean_selector: ^2.1.0
1414
collection: ^1.15.0
15+
http: ^1.2.2
1516
meta: ^1.14.0
1617
source_span: ^1.8.0
1718
stack_trace: ^1.10.0

pkgs/test_api/test/import_restrictions_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
@TestOn('vm && !exe')
6+
library;
7+
58
import 'dart:async';
69
import 'dart:io';
710
import 'dart:isolate';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello

0 commit comments

Comments
 (0)