Skip to content

Commit 3cee978

Browse files
committed
test: update fs.stat AbortSignal test
1 parent 84b971f commit 3cee978

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/parallel/test-fs-stat-abort-test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ const assert = require('node:assert');
66
const fs = require('node:fs');
77
const tmpdir = require('../common/tmpdir');
88

9-
test('fs.stat should throw AbortError when abort signal is triggered', async () => {
9+
test('fs.stat should throw AbortError when called with an already aborted AbortSignal', async () => {
10+
// This test verifies that fs.stat immediately throws an AbortError if the provided AbortSignal
11+
// has already been aborted. This approach is used because attempting to abort an fs.stat call in-flight
12+
// is unreliable given that file system operations tend to complete very quickly on many platforms.
1013
tmpdir.refresh();
1114

1215
const filePath = tmpdir.resolve('temp.txt');
1316
fs.writeFileSync(filePath, 'Test');
17+
18+
// Create an already aborted AbortSignal.
1419
const signal = AbortSignal.abort();
1520

1621
const { promise, resolve, reject } = Promise.withResolvers();
@@ -21,6 +26,7 @@ test('fs.stat should throw AbortError when abort signal is triggered', async ()
2126
resolve(stats);
2227
});
2328

29+
// Assert that the promise is rejected with an AbortError.
2430
await assert.rejects(promise, { name: 'AbortError' });
2531

2632
fs.unlinkSync(filePath);

0 commit comments

Comments
 (0)