Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add suitePath getter #2281

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add suitePath getter for retrieving the package relative path of the …
…current suite
  • Loading branch information
jakemac53 committed Sep 11, 2024
commit 184515e46d05dffd0ed63d2975b352cc742366a7
2 changes: 2 additions & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions pkgs/test_api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions pkgs/test_api/dart_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion pkgs/test_api/lib/scaffolding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
17 changes: 11 additions & 6 deletions pkgs/test_api/lib/src/backend/remote_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions pkgs/test_api/lib/src/scaffolding/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test_api/mono_pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions pkgs/test_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkgs/test_api/test/import_restrictions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions pkgs/test_api/test/scaffolding/test_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
16 changes: 16 additions & 0 deletions pkgs/test_api/test/scaffolding/utils_test.dart
Original file line number Diff line number Diff line change
@@ -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();
}
23 changes: 23 additions & 0 deletions pkgs/test_api/test/scaffolding/utils_test_browser.dart
Original file line number Diff line number Diff line change
@@ -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<Response>()
.having((r) => r.statusCode, 'statusCode', 200)
.having((r) => r.body, 'body', 'hello\n'));
});
}
22 changes: 22 additions & 0 deletions pkgs/test_api/test/scaffolding/utils_test_io.dart
Original file line number Diff line number Diff line change
@@ -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');
});
}
2 changes: 2 additions & 0 deletions pkgs/test_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down