@@ -3,43 +3,56 @@ const common = require('../common');
3
3
const tmpdir = require ( '../common/tmpdir' ) ;
4
4
const { deepStrictEqual, strictEqual } = require ( 'node:assert' ) ;
5
5
const { spawnSync } = require ( 'node:child_process' ) ;
6
- const { readdirSync, writeFileSync } = require ( 'node:fs' ) ;
6
+ const { mkdirSync , readdirSync, writeFileSync } = require ( 'node:fs' ) ;
7
7
const { join } = require ( 'node:path' ) ;
8
- const { beforeEach , test } = require ( 'node:test' ) ;
8
+ const { test } = require ( 'node:test' ) ;
9
9
10
10
function createTestFile ( name ) {
11
- writeFileSync ( join ( tmpdir . path , name ) , `
11
+ const path = join ( tmpdir . path , name ) ;
12
+ writeFileSync ( path , `
12
13
const fs = require('node:fs');
14
+ const { join } = require('node:path');
13
15
14
- fs.unlinkSync(__filename );
16
+ fs.writeFileSync(join(process.cwd(), ' ${ name } .out'), 'x' );
15
17
setTimeout(() => {}, 1_000_000_000);
16
18
` ) ;
19
+ return path ;
17
20
}
18
21
19
- beforeEach ( ( ) => {
20
- tmpdir . refresh ( ) ;
21
- createTestFile ( 'test-1.js' ) ;
22
- createTestFile ( 'test-2.js' ) ;
23
- } ) ;
22
+ let cnt = 0 ;
23
+ function nextDir ( ) {
24
+ const path = join ( tmpdir . path , String ( cnt ) ) ;
25
+ cnt ++ ;
26
+ mkdirSync ( path ) ;
27
+ return path ;
28
+ }
29
+
30
+ tmpdir . refresh ( ) ;
31
+ const test1 = createTestFile ( 'test-1.js' ) ;
32
+ const test2 = createTestFile ( 'test-2.js' ) ;
24
33
25
34
test ( 'concurrency of one' , ( ) => {
26
- const cp = spawnSync ( process . execPath , [ '--test' , '--test-concurrency=1' ] , {
27
- cwd : tmpdir . path ,
35
+ const cwd = nextDir ( ) ;
36
+ const args = [ '--test' , '--test-concurrency=1' , test1 , test2 ] ;
37
+ const cp = spawnSync ( process . execPath , args , {
38
+ cwd,
28
39
timeout : common . platformTimeout ( 1000 ) ,
29
40
} ) ;
30
41
31
42
strictEqual ( cp . stderr . toString ( ) , '' ) ;
32
43
strictEqual ( cp . error . code , 'ETIMEDOUT' ) ;
33
- deepStrictEqual ( readdirSync ( tmpdir . path ) , [ 'test-2 .js' ] ) ;
44
+ deepStrictEqual ( readdirSync ( cwd ) , [ 'test-1 .js.out ' ] ) ;
34
45
} ) ;
35
46
36
47
test ( 'concurrency of two' , ( ) => {
37
- const cp = spawnSync ( process . execPath , [ '--test' , '--test-concurrency=2' ] , {
38
- cwd : tmpdir . path ,
48
+ const cwd = nextDir ( ) ;
49
+ const args = [ '--test' , '--test-concurrency=2' , test1 , test2 ] ;
50
+ const cp = spawnSync ( process . execPath , args , {
51
+ cwd,
39
52
timeout : common . platformTimeout ( 1000 ) ,
40
53
} ) ;
41
54
42
55
strictEqual ( cp . stderr . toString ( ) , '' ) ;
43
56
strictEqual ( cp . error . code , 'ETIMEDOUT' ) ;
44
- deepStrictEqual ( readdirSync ( tmpdir . path ) , [ ] ) ;
57
+ deepStrictEqual ( readdirSync ( cwd ) , [ 'test-1.js.out' , 'test-2.js.out' ] ) ;
45
58
} ) ;
0 commit comments