6
6
@Tags (['node' ])
7
7
library ;
8
8
9
+ import 'dart:convert' ;
10
+ import 'dart:io' ;
11
+
12
+ import 'package:test/src/runner/executable_settings.dart' ;
9
13
import 'package:test/test.dart' ;
10
14
import 'package:test_core/src/util/io.dart' ;
11
15
import 'package:test_descriptor/test_descriptor.dart' as d;
@@ -28,6 +32,37 @@ final _failure = '''
28
32
}
29
33
''' ;
30
34
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
+
31
66
void main () {
32
67
setUpAll (precompileTestExecutable);
33
68
@@ -124,7 +159,7 @@ void main() {
124
159
125
160
expect (test.stdout, emitsThrough (contains ('+1: All tests passed!' )));
126
161
await test.shouldExit (0 );
127
- });
162
+ }, skip : skipBelowMajorNodeVersion ( 22 ) );
128
163
});
129
164
130
165
test ('defines a node environment constant' , () async {
@@ -157,6 +192,26 @@ void main() {
157
192
}
158
193
''' ).create ();
159
194
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
+
160
215
var test = await runTest ([
161
216
'-p' ,
162
217
'node' ,
@@ -170,7 +225,7 @@ void main() {
170
225
]);
171
226
expect (test.stdout, emitsThrough (contains ('+1 -2: Some tests failed.' )));
172
227
await test.shouldExit (1 );
173
- });
228
+ }, skip : skipBelowMajorNodeVersion ( 22 ) );
174
229
175
230
test ('forwards prints from the Node test' , () async {
176
231
await d.file ('test.dart' , '''
0 commit comments