Debian Codegraph @

node-manten/tests/specs/abort-signal.ts

raw symbols SCIP
1 import { createFixture } from 'fs-fixture';
2 import { installMantenscip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/installManten., nodescip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/node. } from '../utils/spec-helpers.ts'scip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/;
3 import {
4 describe, test, expect, onTestFail,
5 } from 'manten';
6
7 describe('abort signal', () => {
8 test('signal provided to test callback', async () => {
9 await using fixture = await createFixture({
10 'index.mjs'scip-typescript npm manten 2.0.0 tests/specs/`abort-signal.ts`/`'index.mjs'0`:: `
11 import { describe, test } from 'manten';
12
13 describe('abort signal', () => {
14 test('signal is AbortSignal', ({ signal }) => {
15 if (!(signal instanceof AbortSignal)) {
16 throw new Error('signal is not AbortSignal');
17 }
18 if (signal.aborted) {
19 throw new Error('signal should not be aborted initially');
20 }
21 });
22 });
23 `,
24 ...installMantenscip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/installManten.,
25 });
26
27 const testProcess = await nodescip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/node.(fixture.getPath('index.mjs'));
28
29 onTestFail(() => {
30 consolescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/console..logscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Console#log().(testProcess);
31 });
32
33 expect('exitCode' in testProcess).toBe(false);
34 expect(testProcess.stdout).toMatch('1 passed');
35 });
36
37 test('signal aborted on timeout', async () => {
38 await using fixture = await createFixture({
39 'index.mjs'scip-typescript npm manten 2.0.0 tests/specs/`abort-signal.ts`/`'index.mjs'1`:: `
40 import { describe, test } from 'manten';
41
42 describe('abort signal', () => {
43 test('signal aborted on timeout', async ({ signal }) => {
44 let aborted = false;
45 signal.addEventListener('abort', () => {
46 aborted = true;
47 });
48
49 // Hang forever - only way out is timeout
50 await new Promise(() => {});
51
52 if (!aborted) {
53 throw new Error('signal was not aborted');
54 }
55 }, { timeout: 50 });
56 });
57 `,
58 ...installMantenscip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/installManten.,
59 });
60
61 const testProcess = await nodescip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/node.(fixture.getPath('index.mjs'));
62
63 onTestFail(() => {
64 consolescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/console..logscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Console#log().(testProcess);
65 });
66
67 expect('exitCode' in testProcess).toBe(true);
68 expect(testProcess.stderr).toMatch('Timeout: 50ms');
69 expect(testProcess.stdout).toMatch('1 failed');
70 });
71
72 test('signal enables graceful cleanup', async () => {
73 await using fixture = await createFixture({
74 'index.mjs'scip-typescript npm manten 2.0.0 tests/specs/`abort-signal.ts`/`'index.mjs'2`:: `
75 import { setTimeout } from 'node:timers/promises';
76 import { describe, test } from 'manten';
77
78 describe('abort signal', () => {
79 test('graceful cleanup on timeout', async ({ signal }) => {
80 let cleaned = false;
81
82 signal.addEventListener('abort', () => {
83 cleaned = true;
84 });
85
86 try {
87 await setTimeout(1000, null, { signal });
88 } finally {
89 // Write cleanup status to stdout for verification
90 console.log('CLEANUP:', cleaned);
91 }
92 }, { timeout: 50 });
93 });
94 `,
95 ...installMantenscip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/installManten.,
96 });
97
98 const testProcess = await nodescip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/node.(fixture.getPath('index.mjs'));
99
100 onTestFail(() => {
101 consolescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/console..logscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Console#log().(testProcess);
102 });
103
104 expect('exitCode' in testProcess).toBe(true);
105 expect(testProcess.stderr).toMatch('Timeout: 50ms');
106 expect(testProcess.stdout).toMatch('CLEANUP: true');
107 expect(testProcess.stdout).toMatch('1 failed');
108 });
109
110 test('signal not aborted when test completes', async () => {
111 await using fixture = await createFixture({
112 'index.mjs'scip-typescript npm manten 2.0.0 tests/specs/`abort-signal.ts`/`'index.mjs'3`:: `
113 import { describe, test } from 'manten';
114
115 describe('abort signal', () => {
116 test('signal not aborted on success', async ({ signal }) => {
117 let aborted = false;
118 signal.addEventListener('abort', () => {
119 aborted = true;
120 });
121
122 // Complete immediately - well within timeout
123 await new Promise(resolve => setImmediate(resolve));
124
125 if (aborted) {
126 throw new Error('signal should not be aborted');
127 }
128 }, { timeout: 100 });
129 });
130 `,
131 ...installMantenscip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/installManten.,
132 });
133
134 const testProcess = await nodescip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/node.(fixture.getPath('index.mjs'));
135
136 onTestFail(() => {
137 consolescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/console..logscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Console#log().(testProcess);
138 });
139
140 expect('exitCode' in testProcess).toBe(false);
141 expect(testProcess.stdout).toMatch('1 passed');
142 });
143
144 test('new signal created per retry attempt', async () => {
145 await using fixture = await createFixture({
146 'index.mjs'scip-typescript npm manten 2.0.0 tests/specs/`abort-signal.ts`/`'index.mjs'4`:: `
147 import { setTimeout } from 'node:timers/promises';
148 import { describe, test } from 'manten';
149
150 describe('abort signal', () => {
151 let attempt = 0;
152 const signals = [];
153
154 test('new signal per retry', async ({ signal }) => {
155 attempt += 1;
156 signals.push(signal);
157
158 // Check signals are different instances
159 if (attempt === 2 && signals[0] === signals[1]) {
160 throw new Error('signals should be different instances');
161 }
162
163 // Check previous signal was aborted
164 if (attempt === 2 && !signals[0].aborted) {
165 throw new Error('previous signal should be aborted');
166 }
167
168 // Current signal should not be aborted
169 if (signal.aborted) {
170 throw new Error('current signal should not be aborted');
171 }
172
173 if (attempt < 2) {
174 // Hang forever - forces timeout to kill first attempt
175 await new Promise(() => {});
176 }
177 }, {
178 retry: 2,
179 timeout: 50,
180 });
181 });
182 `,
183 ...installMantenscip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/installManten.,
184 });
185
186 const testProcess = await nodescip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/node.(fixture.getPath('index.mjs'));
187
188 onTestFail(() => {
189 consolescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/console..logscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Console#log().(testProcess);
190 });
191
192 expect('exitCode' in testProcess).toBe(false);
193 expect(testProcess.stdout).toMatch('(2/2)');
194 expect(testProcess.stdout).toMatch('1 passed');
195 });
196
197 test('signal works without timeout', async () => {
198 await using fixture = await createFixture({
199 'index.mjs'scip-typescript npm manten 2.0.0 tests/specs/`abort-signal.ts`/`'index.mjs'5`:: `
200 import { describe, test } from 'manten';
201
202 describe('abort signal', () => {
203 test('signal provided without timeout', ({ signal }) => {
204 if (!(signal instanceof AbortSignal)) {
205 throw new Error('signal is not AbortSignal');
206 }
207 if (signal.aborted) {
208 throw new Error('signal should not be aborted');
209 }
210 });
211 });
212 `,
213 ...installMantenscip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/installManten.,
214 });
215
216 const testProcess = await nodescip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/node.(fixture.getPath('index.mjs'));
217
218 onTestFail(() => {
219 consolescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/console..logscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Console#log().(testProcess);
220 });
221
222 expect('exitCode' in testProcess).toBe(false);
223 expect(testProcess.stdout).toMatch('1 passed');
224 });
225
226 test('signal aborted on success', async () => {
227 await using fixture = await createFixture({
228 'index.mjs'scip-typescript npm manten 2.0.0 tests/specs/`abort-signal.ts`/`'index.mjs'6`:: `
229 import { setTimeout } from 'node:timers/promises';
230 import { describe, test, onTestFinish } from 'manten';
231
232 describe('abort signal', () => {
233 test('signal aborted after test completes', async ({ signal }) => {
234 let cleaned = false;
235
236 signal.addEventListener('abort', () => {
237 cleaned = true;
238 });
239
240 onTestFinish(() => {
241 // Verify cleanup happened after test completed
242 if (!cleaned) {
243 throw new Error('Signal should have been aborted after test finished');
244 }
245 console.log('CLEANUP_VERIFIED: true');
246 });
247
248 // Test passes immediately
249 await new Promise(resolve => setImmediate(resolve));
250 }, { timeout: 1000 });
251 });
252 `,
253 ...installMantenscip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/installManten.,
254 });
255
256 const testProcess = await nodescip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/node.(fixture.getPath('index.mjs'));
257
258 onTestFail(() => {
259 consolescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/console..logscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Console#log().(testProcess);
260 });
261
262 expect('exitCode' in testProcess).toBe(false);
263 expect(testProcess.stdout).toMatch('CLEANUP_VERIFIED: true');
264 expect(testProcess.stdout).toMatch('1 passed');
265 });
266
267 test('abort reason contains timeout error', async () => {
268 await using fixture = await createFixture({
269 'index.mjs'scip-typescript npm manten 2.0.0 tests/specs/`abort-signal.ts`/`'index.mjs'7`:: `
270 import { describe, test } from 'manten';
271
272 describe('abort signal', () => {
273 test('abort reason on timeout', async ({ signal }) => {
274 signal.addEventListener('abort', () => {
275 // Write reason to stdout for verification
276 console.log('ABORT_REASON:', signal.reason?.message || 'undefined');
277 });
278
279 // Hang forever - only way out is timeout
280 await new Promise(() => {});
281 }, { timeout: 50 });
282 });
283 `,
284 ...installMantenscip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/installManten.,
285 });
286
287 const testProcess = await nodescip-typescript npm manten 2.0.0 tests/utils/`spec-helpers.ts`/node.(fixture.getPath('index.mjs'));
288
289 onTestFail(() => {
290 consolescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/console..logscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Console#log().(testProcess);
291 });
292
293 expect('exitCode' in testProcess).toBe(true);
294 expect(testProcess.stdout).toMatch('ABORT_REASON: Timeout: 50ms');
295 expect(testProcess.stderr).toMatch('Timeout: 50ms');
296 expect(testProcess.stdout).toMatch('1 failed');
297 });
298 });