Skip to content

Commit

Permalink
fix: throw when expected file is ENOENT (#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 3, 2023
1 parent 2001a0b commit ad3f441
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/resolve/treeContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export class NodeFSTreeContainer extends TreeContainer {
}

public stream(fsPath: SourcePath): Readable {
if (!this.exists(fsPath)) {
throw new Error(`File not found: ${fsPath}`);
}
return createReadStream(fsPath);
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/resolve/treeContainers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ describe('Tree Containers', () => {

it('should use expected Node API for stream', () => {
const readable = new Readable();
const createReadStreamStub = env.stub(fs, 'createReadStream');
// @ts-ignore wants ReadStream but Readable works for testing
createReadStreamStub.withArgs(path).returns(readable);
env.stub(fs, 'createReadStream').returns(readable);
env.stub(fs, 'existsSync').returns(true);
expect(tree.stream(path)).to.deep.equal(readable);
});
});
Expand Down

0 comments on commit ad3f441

Please sign in to comment.