From 5a36454dc14403d4d7025dd183dd399b83b6e718 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 1 Oct 2023 13:42:34 -0400 Subject: [PATCH] forgot to add the test --- test/parallel/test-runner-cli-concurrency.js | 45 ++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/parallel/test-runner-cli-concurrency.js diff --git a/test/parallel/test-runner-cli-concurrency.js b/test/parallel/test-runner-cli-concurrency.js new file mode 100644 index 00000000000000..9d8dd4f8ce2f82 --- /dev/null +++ b/test/parallel/test-runner-cli-concurrency.js @@ -0,0 +1,45 @@ +'use strict'; +const common = require('../common'); +const tmpdir = require('../common/tmpdir'); +const { deepStrictEqual, strictEqual } = require('node:assert'); +const { spawnSync } = require('node:child_process'); +const { readdirSync, writeFileSync } = require('node:fs'); +const { join } = require('node:path'); +const { beforeEach, test } = require('node:test'); + +function createTestFile(name) { + writeFileSync(join(tmpdir.path, name), ` + const fs = require('node:fs'); + + fs.unlinkSync(__filename); + setTimeout(() => {}, 1_000_000_000); + `); +} + +beforeEach(() => { + tmpdir.refresh(); + createTestFile('test-1.js'); + createTestFile('test-2.js'); +}); + +test('concurrency of one', () => { + const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=1'], { + cwd: tmpdir.path, + timeout: common.platformTimeout(1000), + }); + + strictEqual(cp.stderr.toString(), ''); + strictEqual(cp.error.code, 'ETIMEDOUT'); + deepStrictEqual(readdirSync(tmpdir.path), ['test-2.js']); +}); + +test('concurrency of two', () => { + const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=2'], { + cwd: tmpdir.path, + timeout: common.platformTimeout(1000), + }); + + strictEqual(cp.stderr.toString(), ''); + strictEqual(cp.error.code, 'ETIMEDOUT'); + deepStrictEqual(readdirSync(tmpdir.path), []); +});