Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 9 additions & 28 deletions bin/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { spawn } from 'node:child_process';
import { execSync, spawn } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import readline from 'node:readline';

import { subscribeSpyTo } from '@hirez_io/observer-spy';
import { sendCtrlC, spawnWithWrapper } from 'ctrlc-wrapper';
import { build } from 'esbuild';
import Rx from 'rxjs';
import { map } from 'rxjs/operators';
import stringArgv from 'string-argv';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { beforeAll, describe, expect, it } from 'vitest';

import { escapeRegExp } from '../lib/utils.js';

Expand All @@ -24,37 +22,20 @@ const createKillMessage = (prefix: string, signal: 'SIGTERM' | 'SIGINT' | string
return new RegExp(`${escapeRegExp(prefix)} exited with code ${map[signal] ?? signal}`);
};

let tmpDir: string;

beforeAll(async () => {
// Build 'concurrently' and store it in a temporary directory
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'concurrently-'));
await build({
entryPoints: [path.join(__dirname, 'index.ts')],
platform: 'node',
bundle: true,
// it doesn't seem like esbuild is able to change a CJS module to ESM, so target CJS instead.
// https://github.com/evanw/esbuild/issues/1921
format: 'cjs',
outfile: path.join(tmpDir, 'concurrently.cjs'),
});
fs.copyFileSync(path.join(__dirname, '..', 'package.json'), path.join(tmpDir, 'package.json'));
}, 8000);

afterAll(() => {
// Remove the temporary directory where 'concurrently' was stored
if (tmpDir) {
fs.rmSync(tmpDir, { recursive: true });
}
});
const concurrentlyBin = path.join(__dirname, '..', 'dist', 'bin', 'index.js');

// Build once, then spawn the real CLI without a shell (see open-cli-tools/concurrently#346).
beforeAll(() => {
execSync('pnpm run build', { cwd: path.join(__dirname, '..'), stdio: 'pipe' });
}, 20_000);

/**
* Creates a child process running 'concurrently' with the given args.
* Returns observables for its combined stdout + stderr output, close events, pid, and stdin stream.
*/
const run = (args: string, ctrlcWrapper?: boolean) => {
const spawnFn = ctrlcWrapper ? spawnWithWrapper : spawn;
const child = spawnFn('node', [path.join(tmpDir, 'concurrently.cjs'), ...stringArgv(args)], {
const child = spawnFn('node', [concurrentlyBin, ...stringArgv(args)], {
cwd: __dirname,
env: {
...process.env,
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"shell-quote": "1.8.4",
"supports-color": "10.2.2",
"tree-kill": "1.2.2",
"yargs": "17.7.2"
"yargs": "18.0.0"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
Expand All @@ -67,7 +67,6 @@
"@vitest/coverage-v8": "^4.1.6",
"@vitest/eslint-plugin": "^1.6.17",
"ctrlc-wrapper": "^0.0.5",
"esbuild": "~0.28.0",
"eslint": "^10.4.0",
"eslint-config-flat-gitignore": "^2.3.0",
"eslint-config-prettier": "^10.1.8",
Expand Down
Loading
Loading