Skip to content

Commit 6d60be9

Browse files
committed
test(fslib): add more tests (#4474)
1 parent 6cf5ad3 commit 6d60be9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ package.tgz
3737
/vscode-case-study
3838

3939
.idea
40+
41+
coverage

packages/yarnpkg-fslib/tests/ZipFS.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,4 +865,40 @@ describe(`ZipFS`, () => {
865865

866866
zipFs.discardAndClose();
867867
});
868+
869+
it(`should throw ENOTDIR when trying to stat a file as a directory`, () => {
870+
const zipFs = new ZipFS(null, {libzip: getLibzipSync()});
871+
872+
zipFs.writeFileSync(`/foo.txt` as PortablePath, ``);
873+
expect(() => zipFs.statSync(`/foo.txt/` as PortablePath)).toThrowError(`ENOTDIR`);
874+
875+
zipFs.symlinkSync(`/foo.txt` as PortablePath, `/bar.txt` as PortablePath);
876+
expect(() => zipFs.lstatSync(`/bar.txt/` as PortablePath)).toThrowError(`ENOTDIR`);
877+
878+
zipFs.discardAndClose();
879+
});
880+
881+
it(`should throw ENOTDIR when trying to create a file when the dirname is a file`, () => {
882+
const zipFs = new ZipFS(null, {libzip: getLibzipSync()});
883+
884+
zipFs.writeFileSync(`/foo.txt` as PortablePath, ``);
885+
expect(() => zipFs.writeFileSync(`/foo.txt/bar.txt` as PortablePath, ``)).toThrowError(`ENOTDIR`);
886+
887+
zipFs.symlinkSync(`/foo.txt` as PortablePath, `/bar.txt` as PortablePath);
888+
expect(() => zipFs.writeFileSync(`/bar.txt/baz.txt` as PortablePath, ``)).toThrowError(`ENOTDIR`);
889+
890+
zipFs.discardAndClose();
891+
});
892+
893+
it(`should throw ENOENT when reading a file that doesn't exist`, () => {
894+
const zipFs = new ZipFS(null, {libzip: getLibzipSync()});
895+
896+
// File doesn't exist
897+
expect(() => zipFs.readFileSync(`/foo` as PortablePath, ``)).toThrowError(`ENOENT`);
898+
899+
// Parent entry doesn't exist
900+
expect(() => zipFs.readFileSync(`/foo/bar` as PortablePath, ``)).toThrowError(`ENOENT`);
901+
902+
zipFs.discardAndClose();
903+
});
868904
});

0 commit comments

Comments
 (0)