MCPcopy Create free account
hub / github.com/nodejs/node / testAutoCloseOnFail

Function testAutoCloseOnFail

test/parallel/test-fs-promises-file-handle-writer.js:120–131  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

118// =============================================================================
119
120async function testAutoCloseOnFail() {
121 const filePath = path.join(tmpDir, 'writer-autoclose-fail.txt');
122 const fh = await open(filePath, 'w');
123 const w = fh.writer({ autoClose: true });
124 await w.write(Buffer.from('partial'));
125 w.fail(new Error('test fail'));
126
127 // Handle should be closed
128 await assert.rejects(fh.stat(), { code: 'EBADF' });
129 // Partial data should still be on disk (fail doesn't truncate)
130 assert.strictEqual(fs.readFileSync(filePath, 'utf8'), 'partial');
131}
132
133// =============================================================================
134// start option - write at specified offset

Calls 8

writerMethod · 0.80
openFunction · 0.70
joinMethod · 0.45
writeMethod · 0.45
fromMethod · 0.45
failMethod · 0.45
statMethod · 0.45
readFileSyncMethod · 0.45

Tested by

no test coverage detected