MCPcopy Index your code
hub / github.com/nodejs/node / checkCloseError

Function checkCloseError

test/parallel/test-fs-promises-file-handle-close-errors.js:30–57  ·  view source on GitHub ↗
(op)

Source from the content-addressed store, hash-verified

28}
29
30async function checkCloseError(op) {
31 try {
32 const filePath = await createFile();
33 Object.defineProperty(FileHandle.prototype, 'fd', {
34 get: function() {
35 // Close is set by using a setter,
36 // so it needs to be set on the instance.
37 const originalClose = this.close;
38 this.close = async () => {
39 // close the file
40 await originalClose.call(this);
41 const closeError = new Error('CLOSE_ERROR');
42 closeError.code = 456;
43 throw closeError;
44 };
45 return originalFd.get.call(this);
46 }
47 });
48
49 await assert.rejects(op(filePath), {
50 name: 'Error',
51 message: 'CLOSE_ERROR',
52 code: 456,
53 });
54 } finally {
55 Object.defineProperty(FileHandle.prototype, 'fd', originalFd);
56 }
57}
58(async function() {
59 tmpdir.refresh();
60 await checkCloseError((filePath) => truncate(filePath));

Calls 4

createFileFunction · 0.70
opFunction · 0.50
definePropertyMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected