From 81730d89b803c67911b6b8dbd7e107b8b04cc30d Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sun, 24 Nov 2024 15:57:51 +0000 Subject: [PATCH] Test: Minor clean up to `/test/cli/cli-watch.js` --- test/cli/cli-watch.js | 41 ++++++++++++------------------------- test/cli/helpers/execute.js | 10 +++++++++ test/cli/utils.js | 4 ++-- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/test/cli/cli-watch.js b/test/cli/cli-watch.js index 7050eed8a..707fc1d21 100644 --- a/test/cli/cli-watch.js +++ b/test/cli/cli-watch.js @@ -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 }); }); @@ -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'); }); } ); @@ -75,7 +60,7 @@ QUnit.module('CLI Watch', function (hooks) { execution => { execution.on('message', data => { assert.step(data); - kill(execution); + process.kill(execution.pid); }); } ); @@ -103,7 +88,7 @@ QUnit.module('CLI Watch', function (hooks) { execution.once('message', data => { assert.step(data); - kill(execution); + process.kill(execution.pid); }); }); } @@ -132,7 +117,7 @@ QUnit.module('CLI Watch', function (hooks) { execution.once('message', data => { assert.step(data); - kill(execution); + process.kill(execution.pid); }); }); } @@ -165,7 +150,7 @@ QUnit.module('CLI Watch', function (hooks) { execution.once('message', data => { assert.step(data); - kill(execution); + process.kill(execution.pid); }); }); } @@ -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); } }); }); @@ -253,7 +238,7 @@ QUnit.module('CLI Watch', function (hooks) { }); execution.once('message', () => { - kill(execution); + process.kill(execution.pid); }); }); } @@ -311,7 +296,7 @@ QUnit.module('CLI Watch', function (hooks) { assert.step(data); if (data === 'runEnd') { - kill(execution); + process.kill(execution.pid); } }); } @@ -386,7 +371,7 @@ QUnit.module('CLI Watch', function (hooks) { } if (count === 3) { - kill(execution); + process.kill(execution.pid); } } }); diff --git a/test/cli/helpers/execute.js b/test/cli/helpers/execute.js index 37aa88dbd..176afbcc8 100644 --- a/test/cli/helpers/execute.js +++ b/test/cli/helpers/execute.js @@ -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. * @@ -240,6 +249,7 @@ function concurrentMapKeys (input, concurrency, asyncFn) { module.exports = { normalize, execute, + executeIpc, executeRaw, concurrentMap, concurrentMapKeys diff --git a/test/cli/utils.js b/test/cli/utils.js index 113b57c2d..b50c54d95 100644 --- a/test/cli/utils.js +++ b/test/cli/utils.js @@ -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) {