|  | 
|  | 1 | +'use strict'; | 
|  | 2 | +const common = require('../common'); | 
|  | 3 | +const tmpdir = require('../common/tmpdir'); | 
|  | 4 | +const { deepStrictEqual, strictEqual } = require('node:assert'); | 
|  | 5 | +const { spawnSync } = require('node:child_process'); | 
|  | 6 | +const { readdirSync, writeFileSync } = require('node:fs'); | 
|  | 7 | +const { join } = require('node:path'); | 
|  | 8 | +const { beforeEach, test } = require('node:test'); | 
|  | 9 | + | 
|  | 10 | +function createTestFile(name) { | 
|  | 11 | +  writeFileSync(join(tmpdir.path, name), ` | 
|  | 12 | +    const fs = require('node:fs'); | 
|  | 13 | +
 | 
|  | 14 | +    fs.unlinkSync(__filename); | 
|  | 15 | +    setTimeout(() => {}, 1_000_000_000); | 
|  | 16 | +  `); | 
|  | 17 | +} | 
|  | 18 | + | 
|  | 19 | +beforeEach(() => { | 
|  | 20 | +  tmpdir.refresh(); | 
|  | 21 | +  createTestFile('test-1.js'); | 
|  | 22 | +  createTestFile('test-2.js'); | 
|  | 23 | +}); | 
|  | 24 | + | 
|  | 25 | +test('concurrency of one', () => { | 
|  | 26 | +  const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=1'], { | 
|  | 27 | +    cwd: tmpdir.path, | 
|  | 28 | +    timeout: common.platformTimeout(1000), | 
|  | 29 | +  }); | 
|  | 30 | + | 
|  | 31 | +  strictEqual(cp.stderr.toString(), ''); | 
|  | 32 | +  strictEqual(cp.error.code, 'ETIMEDOUT'); | 
|  | 33 | +  deepStrictEqual(readdirSync(tmpdir.path), ['test-2.js']); | 
|  | 34 | +}); | 
|  | 35 | + | 
|  | 36 | +test('concurrency of two', () => { | 
|  | 37 | +  const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=2'], { | 
|  | 38 | +    cwd: tmpdir.path, | 
|  | 39 | +    timeout: common.platformTimeout(1000), | 
|  | 40 | +  }); | 
|  | 41 | + | 
|  | 42 | +  strictEqual(cp.stderr.toString(), ''); | 
|  | 43 | +  strictEqual(cp.error.code, 'ETIMEDOUT'); | 
|  | 44 | +  deepStrictEqual(readdirSync(tmpdir.path), []); | 
|  | 45 | +}); | 
0 commit comments