|
1 | 1 | import * as common from '../common/index.mjs';
|
2 | 2 | import { describe, it, beforeEach } from 'node:test';
|
3 |
| -import * as fixtures from '../common/fixtures.mjs'; |
4 | 3 | import { once } from 'node:events';
|
5 | 4 | import assert from 'node:assert';
|
6 | 5 | import { spawn } from 'node:child_process';
|
7 |
| -import { writeFileSync, renameSync, unlinkSync, existsSync, readFileSync } from 'node:fs'; |
| 6 | +import { writeFileSync, renameSync, unlinkSync } from 'node:fs'; |
8 | 7 | import { setTimeout } from 'node:timers/promises';
|
9 | 8 | import tmpdir from '../common/tmpdir.js';
|
10 |
| -import { join } from 'node:path'; |
11 | 9 |
|
12 | 10 | if (common.isIBMi)
|
13 | 11 | common.skip('IBMi does not support `fs.watch()`');
|
14 | 12 |
|
15 | 13 | if (common.isAIX)
|
16 | 14 | common.skip('folder watch capability is limited in AIX.');
|
17 | 15 |
|
18 |
| -const testFixtures = fixtures.path('test-runner'); |
19 |
| - |
20 | 16 | let fixturePaths;
|
21 | 17 |
|
22 | 18 | // This test updates these files repeatedly,
|
@@ -194,101 +190,4 @@ describe('test runner watch mode', () => {
|
194 | 190 | });
|
195 | 191 | });
|
196 | 192 | }
|
197 |
| - |
198 |
| - describe('test runner watch mode with global setup hooks', () => { |
199 |
| - for (const isolation of ['none', 'process']) { |
200 |
| - it(`should run global setup/teardown hooks with each test run in watch mode (isolation: ${isolation})`, async () => { |
201 |
| - const testContent = ` |
202 |
| - const test = require('node:test'); |
203 |
| - |
204 |
| - test('test with global hooks', (t) => { |
205 |
| - t.assert.ok('test passed'); |
206 |
| - }); |
207 |
| - `; |
208 |
| - |
209 |
| - const globalSetupFileFixture = join(testFixtures, 'global-setup-teardown', 'basic-setup-teardown.mjs'); |
210 |
| - const testFilePath = tmpdir.resolve('test-with-hooks.js'); |
211 |
| - const setupFlagPath = tmpdir.resolve('setup-executed-watch.tmp'); |
212 |
| - const teardownFlagPath = tmpdir.resolve('teardown-executed-watch.tmp'); |
213 |
| - |
214 |
| - writeFileSync(testFilePath, testContent); |
215 |
| - |
216 |
| - const ran1 = Promise.withResolvers(); |
217 |
| - const ran2 = Promise.withResolvers(); |
218 |
| - |
219 |
| - const child = spawn(process.execPath, |
220 |
| - [ |
221 |
| - '--watch', |
222 |
| - '--test', |
223 |
| - '--test-reporter=spec', |
224 |
| - `--test-isolation=${isolation}`, |
225 |
| - '--test-global-setup=' + globalSetupFileFixture, |
226 |
| - testFilePath, |
227 |
| - ], |
228 |
| - { |
229 |
| - encoding: 'utf8', |
230 |
| - stdio: 'pipe', |
231 |
| - cwd: tmpdir.path, |
232 |
| - env: { |
233 |
| - ...process.env, |
234 |
| - SETUP_FLAG_PATH: setupFlagPath, |
235 |
| - TEARDOWN_FLAG_PATH: teardownFlagPath |
236 |
| - } |
237 |
| - }); |
238 |
| - |
239 |
| - let stdout = ''; |
240 |
| - let currentRun = ''; |
241 |
| - const runs = []; |
242 |
| - |
243 |
| - child.stdout.on('data', (data) => { |
244 |
| - stdout += data.toString(); |
245 |
| - currentRun += data.toString(); |
246 |
| - const testRuns = stdout.match(/duration_ms\s\d+/g); |
247 |
| - if (testRuns?.length >= 1) ran1.resolve(); |
248 |
| - if (testRuns?.length >= 2) ran2.resolve(); |
249 |
| - }); |
250 |
| - |
251 |
| - await ran1.promise; |
252 |
| - runs.push(currentRun); |
253 |
| - currentRun = ''; |
254 |
| - |
255 |
| - assert.ok(existsSync(setupFlagPath), 'Setup flag file should exist'); |
256 |
| - assert.ok(!existsSync(teardownFlagPath), 'Teardown flag file should not exist'); |
257 |
| - |
258 |
| - // Modify test file to trigger watch |
259 |
| - writeFileSync(testFilePath, testContent + ` |
260 |
| - test('another test', (t) => { |
261 |
| - t.assert.ok('another test passed'); |
262 |
| - }); |
263 |
| - `); |
264 |
| - |
265 |
| - await ran2.promise; |
266 |
| - runs.push(currentRun); |
267 |
| - |
268 |
| - currentRun = ''; |
269 |
| - child.kill(); |
270 |
| - await once(child, 'exit'); |
271 |
| - |
272 |
| - |
273 |
| - // Verify the teardown file was updated |
274 |
| - const secondTeardownContent = readFileSync(teardownFlagPath, 'utf8'); |
275 |
| - assert.strictEqual(secondTeardownContent, 'Teardown was executed'); |
276 |
| - |
277 |
| - assert.match(runs[0], /Global setup executed/); |
278 |
| - assert.match(runs[0], /tests 1/); |
279 |
| - assert.match(runs[0], /pass 1/); |
280 |
| - assert.match(runs[0], /fail 0/); |
281 |
| - |
282 |
| - assert.doesNotMatch(runs[1], /Global setup executed/); |
283 |
| - assert.doesNotMatch(runs[1], /Global teardown executed/); |
284 |
| - assert.match(runs[1], /tests 2/); |
285 |
| - assert.match(runs[1], /pass 2/); |
286 |
| - assert.match(runs[1], /fail 0/); |
287 |
| - |
288 |
| - // Verify stdout after killing the child |
289 |
| - assert.match(currentRun, /Global teardown executed/); |
290 |
| - assert.match(currentRun, /Data from setup: data from setup/); |
291 |
| - }); |
292 |
| - } |
293 |
| - }); |
294 | 193 | });
|
0 commit comments