Skip to content

Commit 1a0f1ad

Browse files
committed
Skip wasm tests on old node versions
1 parent cd173bc commit 1a0f1ad

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

pkgs/test/test/runner/node/runner_test.dart

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
@Tags(['node'])
77
library;
88

9+
import 'dart:convert';
10+
import 'dart:io';
11+
12+
import 'package:test/src/runner/executable_settings.dart';
913
import 'package:test/test.dart';
1014
import 'package:test_core/src/util/io.dart';
1115
import 'package:test_descriptor/test_descriptor.dart' as d;
@@ -28,6 +32,37 @@ final _failure = '''
2832
}
2933
''';
3034

35+
({int major, String full})? _nodeVersion;
36+
37+
({int major, String full}) _readNodeVersion() {
38+
final process = Process.runSync(
39+
ExecutableSettings(
40+
linuxExecutable: 'node',
41+
macOSExecutable: 'node',
42+
windowsExecutable: 'node.exe',
43+
).executable,
44+
['--version'],
45+
stdoutEncoding: utf8,
46+
);
47+
if (process.exitCode != 0) {
48+
throw const OSError('Could not run node --version');
49+
}
50+
51+
final version = RegExp(r'v(\d+)\..*');
52+
final parsed = version.firstMatch(process.stdout as String)!;
53+
return (major: int.parse(parsed.group(1)!), full: process.stdout);
54+
}
55+
56+
String? skipBelowMajorNodeVersion(int minimumMajorVersion) {
57+
final (:major, :full) = _nodeVersion ??= _readNodeVersion();
58+
if (major < minimumMajorVersion) {
59+
return 'This test requires Node $minimumMajorVersion.x or later, '
60+
'but is running on $full';
61+
}
62+
63+
return null;
64+
}
65+
3166
void main() {
3267
setUpAll(precompileTestExecutable);
3368

@@ -124,7 +159,7 @@ void main() {
124159

125160
expect(test.stdout, emitsThrough(contains('+1: All tests passed!')));
126161
await test.shouldExit(0);
127-
});
162+
}, skip: skipBelowMajorNodeVersion(22));
128163
});
129164

130165
test('defines a node environment constant', () async {
@@ -157,6 +192,26 @@ void main() {
157192
}
158193
''').create();
159194

195+
var test =
196+
await runTest(['-p', 'node', '-p', 'vm', '-c', 'dart2js', 'test.dart']);
197+
expect(test.stdout, emitsThrough(contains('+1 -1: Some tests failed.')));
198+
await test.shouldExit(1);
199+
});
200+
201+
test('runs failing tests that fail only on node (with dart2wasm)', () async {
202+
await d.file('test.dart', '''
203+
import 'package:path/path.dart' as p;
204+
import 'package:test/test.dart';
205+
206+
void main() {
207+
test("test", () {
208+
if (const bool.fromEnvironment("node")) {
209+
throw TestFailure("oh no");
210+
}
211+
});
212+
}
213+
''').create();
214+
160215
var test = await runTest([
161216
'-p',
162217
'node',
@@ -170,7 +225,7 @@ void main() {
170225
]);
171226
expect(test.stdout, emitsThrough(contains('+1 -2: Some tests failed.')));
172227
await test.shouldExit(1);
173-
});
228+
}, skip: skipBelowMajorNodeVersion(22));
174229

175230
test('forwards prints from the Node test', () async {
176231
await d.file('test.dart', '''

0 commit comments

Comments
 (0)