Skip to content

Commit

Permalink
Test: Minor clean up to /test/cli/cli-watch.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Nov 24, 2024
1 parent c5ee904 commit 81730d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
41 changes: 13 additions & 28 deletions test/cli/cli-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,14 @@ const fs = require('fs');
const path = require('path');
const fixturify = require('fixturify');

const expectedWatchOutput = require('./fixtures/expected/watch-tap-outputs');
const { execute } = require('./helpers/execute');

// Executes the provided command from within the fixtures directory
function executeIpc (command, hook) {
return execute(command, { stdio: [null, null, null, 'ipc'] }, hook);
}
const expectedWatchOutput = require('./fixtures/expected/watch-tap-outputs.js');
const { executeIpc } = require('./helpers/execute.js');

const fixturePath = path.join(__dirname, 'fixtures', 'watching');

// Kills the provided executing process, handling differences in platforms
function kill (execution, signal) {
const sig = signal || 'SIGINT';

process.kill(execution.pid, sig);
}
const isWindows = (process.platform === 'win32');

// TODO: Make watch tests work on Windows. https://github.com/qunitjs/qunit/issues/1359
if (process.platform === 'win32') {
return;
}

QUnit.module('CLI Watch', function (hooks) {
QUnit.module.if('CLI Watch', !isWindows, function (hooks) {
hooks.before(function () {
fs.rmSync(fixturePath, { recursive: true, force: true });
});
Expand All @@ -53,7 +38,7 @@ QUnit.module('CLI Watch', function (hooks) {
execution => {
execution.on('message', data => {
assert.step(data);
kill(execution, 'SIGTERM');
process.kill(execution.pid, 'SIGTERM');
});
}
);
Expand All @@ -75,7 +60,7 @@ QUnit.module('CLI Watch', function (hooks) {
execution => {
execution.on('message', data => {
assert.step(data);
kill(execution);
process.kill(execution.pid);
});
}
);
Expand Down Expand Up @@ -103,7 +88,7 @@ QUnit.module('CLI Watch', function (hooks) {

execution.once('message', data => {
assert.step(data);
kill(execution);
process.kill(execution.pid);
});
});
}
Expand Down Expand Up @@ -132,7 +117,7 @@ QUnit.module('CLI Watch', function (hooks) {

execution.once('message', data => {
assert.step(data);
kill(execution);
process.kill(execution.pid);
});
});
}
Expand Down Expand Up @@ -165,7 +150,7 @@ QUnit.module('CLI Watch', function (hooks) {

execution.once('message', data => {
assert.step(data);
kill(execution);
process.kill(execution.pid);
});
});
}
Expand Down Expand Up @@ -214,7 +199,7 @@ QUnit.module('CLI Watch', function (hooks) {
execution.once('message', data => {
// Ignore other re-runs
if (data === 'runEnd2') {
kill(execution);
process.kill(execution.pid);
}
});
});
Expand Down Expand Up @@ -253,7 +238,7 @@ QUnit.module('CLI Watch', function (hooks) {
});

execution.once('message', () => {
kill(execution);
process.kill(execution.pid);
});
});
}
Expand Down Expand Up @@ -311,7 +296,7 @@ QUnit.module('CLI Watch', function (hooks) {
assert.step(data);

if (data === 'runEnd') {
kill(execution);
process.kill(execution.pid);
}
});
}
Expand Down Expand Up @@ -386,7 +371,7 @@ QUnit.module('CLI Watch', function (hooks) {
}

if (count === 3) {
kill(execution);
process.kill(execution.pid);
}
}
});
Expand Down
10 changes: 10 additions & 0 deletions test/cli/helpers/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ async function execute (command, options = {}, hook) {
return await getProcessResult(spawned);
}

/**
* Execute the provided command with IPC enabled, from within the fixtures directory
*
* @see #execute()
*/
async function executeIpc (command, hook) {
return await execute(command, { stdio: [null, null, null, 'ipc'] }, hook);
}

/**
* Executes the provided command from within the fixtures directory.
*
Expand Down Expand Up @@ -240,6 +249,7 @@ function concurrentMapKeys (input, concurrency, asyncFn) {
module.exports = {
normalize,
execute,
executeIpc,
executeRaw,
concurrentMap,
concurrentMapKeys
Expand Down
4 changes: 2 additions & 2 deletions test/cli/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');

const { getIgnoreList } = require('../../src/cli/utils');
const { normalize, concurrentMap, concurrentMapKeys } = require('./helpers/execute');
const { getIgnoreList } = require('../../src/cli/utils.js');
const { normalize, concurrentMap, concurrentMapKeys } = require('./helpers/execute.js');

QUnit.module('CLI utils', function () {
QUnit.test('getIgnoreList()', function (assert) {
Expand Down

0 comments on commit 81730d8

Please sign in to comment.