(op)
| 28 | } |
| 29 | |
| 30 | async 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)); |
no test coverage detected