Skip to content

Commit

Permalink
Consider test fails if node doesn't connect
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Aug 24, 2024
1 parent 618a1d3 commit 048ee5d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
5 changes: 4 additions & 1 deletion integration_tests/wasm/dart_test.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
platforms: [chrome, firefox, node]
platforms: [chrome, firefox]
# Node doesn't work because the version available in the current Ubuntu GitHub runners is too
# old to support WASM+GC, which would be required to run Dart tests.
#platforms: [chrome, firefox, node]
compilers: [dart2wasm]
15 changes: 14 additions & 1 deletion pkgs/test/lib/src/runner/node/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:test_api/backend.dart'
import 'package:test_core/src/runner/application_exception.dart'; // ignore: implementation_imports
import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
import 'package:test_core/src/runner/dart2js_compiler_pool.dart'; // ignore: implementation_imports
import 'package:test_core/src/runner/load_exception.dart'; // ignore: implementation_imports
import 'package:test_core/src/runner/package_version.dart'; // ignore: implementation_imports
import 'package:test_core/src/runner/platform.dart'; // ignore: implementation_imports
import 'package:test_core/src/runner/plugin/customizable_platform.dart'; // ignore: implementation_imports
Expand Down Expand Up @@ -110,7 +111,19 @@ class NodePlatform extends PlatformPlugin
process.stdout.transform(lineSplitter).listen(print);
process.stderr.transform(lineSplitter).listen(print);

var socket = await StreamGroup.merge(servers).first;
// Wait for the first connection (either over ipv4 or v6). If the proccess
// exits before it connects, throw instead of waiting for a connection
// indefinitely.
var socket = await Future.any([
StreamGroup.merge(servers).first,
process.exitCode.then((_) => null),
]);

if (socket == null) {
throw LoadException(
path, 'Node exited before connecting to the test channel.');
}

var channel = StreamChannel(socket.cast<List<int>>(), socket)
.transform(StreamChannelTransformer.fromCodec(utf8))
.transform(_chunksToLines)
Expand Down
41 changes: 41 additions & 0 deletions pkgs/test/test/runner/node/runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ String? skipBelowMajorNodeVersion(int minimumMajorVersion) {
return null;
}

String? skipAboveMajorNodeVersion(int maximumMajorVersion) {
final (:major, :full) = _nodeVersion ??= _readNodeVersion();
if (major > maximumMajorVersion) {
return 'This test requires Node $maximumMajorVersion.x or older, '
'but is running on $full';
}

return null;
}

void main() {
setUpAll(precompileTestExecutable);

Expand Down Expand Up @@ -227,6 +237,37 @@ void main() {
await test.shouldExit(1);
}, skip: skipBelowMajorNodeVersion(22));

test(
'gracefully handles wasm errors on old node versions',
() async {
// Old Node.JS versions can't read the WebAssembly modules emitted by
// dart2wasm. The node process exits before connecting to the server
// opened by the test runner, leading to timeouts. So, this is a
// regression test for https://github.com/dart-lang/test/pull/2259#issuecomment-2307868442
await d.file('test.dart', '''
import 'package:test/test.dart';
void main() {
test("test", () {
// Should pass on newer node versions
});
}
''').create();

var test = await runTest(['-p', 'node', '-c', 'dart2wasm', 'test.dart']);
expect(
test.stdout,
emitsInOrder([
emitsThrough(
contains('Node exited before connecting to the test channel.')),
emitsThrough(contains('-1: Some tests failed.')),
]),
);
await test.shouldExit(1);
},
skip: skipAboveMajorNodeVersion(21),
);

test('forwards prints from the Node test', () async {
await d.file('test.dart', '''
import 'dart:async';
Expand Down

0 comments on commit 048ee5d

Please sign in to comment.