diff --git a/src/__tests__/volume.test.ts b/src/__tests__/volume.test.ts index 7c7798d1..eb72a0d7 100644 --- a/src/__tests__/volume.test.ts +++ b/src/__tests__/volume.test.ts @@ -361,6 +361,23 @@ describe('volume', () => { '/good': 'bye', }); }); + it('Open streams should not be affected', async () => { + const vol = new Volume(); + const json = { + '/hello': 'world', + }; + vol.fromJSON(json); + await new Promise((resolve, reject) => { + vol + .createReadStream('/hello') + .on('data', () => null) + .on('close', resolve) + .on('end', () => { + vol.reset(); + }) + .on('error', reject); + }); + }); }); describe('.openSync(path, flags[, mode])', () => { const vol = new Volume(); diff --git a/src/volume.ts b/src/volume.ts index f685f610..e8cbcb4f 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -821,7 +821,9 @@ export class Volume implements FsCallbackApi, FsSynchronousApi { close(fd: number, callback: TCallback) { validateFd(fd); - this.wrapAsync(this.closeSync, [fd], callback); + const file = this.getFileByFdOrThrow(fd, 'close'); + // NOTE: not calling closeSync because we can reset in between close and closeSync + this.wrapAsync(this.closeFile, [file], callback); } private openFileOrGetById(id: TFileId, flagsNum: number, modeNum?: number): File {