Skip to content

Commit

Permalink
test: ensure symlink zips work
Browse files Browse the repository at this point in the history
  • Loading branch information
thatsmydoing committed Nov 17, 2024
1 parent 97ba101 commit 870da46
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ describe(`Commands`, () => {
}),
);

tests.testIf(
() => process.platform !== `win32`,
`it should install from zips that are symlinks`,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);

const allFiles = await xfs.readdirPromise(ppath.join(path, `.yarn/cache`));
const zipFiles = allFiles.filter(file => file.endsWith(`.zip`));

await xfs.mkdirPromise(ppath.join(path, `store`));
for (const filename of zipFiles) {
const zipFile = ppath.join(path, `.yarn/cache`, filename);
const storePath = ppath.join(path, `store`, filename);
await xfs.movePromise(zipFile, storePath);
await xfs.symlinkPromise(storePath, zipFile);
}

await xfs.removePromise(ppath.join(path, Filename.pnpCjs));

await run(`install`, `--immutable`);
}),
);

test(
`it should refuse to create a lockfile when using --immutable`,
makeTemporaryEnv({
Expand Down
27 changes: 27 additions & 0 deletions packages/acceptance-tests/pkg-tests-specs/sources/pnp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2253,4 +2253,31 @@ describe(`Plug'n'Play`, () => {
});
}),
);

testIf(
() => process.platform !== `win32`,
`it can resolve files from zips that are symlinks`,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);

const allFiles = await xfs.readdirPromise(ppath.join(path, `.yarn/cache`));
const zipFiles = allFiles.filter(file => file.endsWith(`.zip`));

await xfs.mkdirPromise(ppath.join(path, `store`));
for (const filename of zipFiles) {
const zipFile = ppath.join(path, `.yarn/cache`, filename);
const storePath = ppath.join(path, `store`, filename);
await xfs.movePromise(zipFile, storePath);
await xfs.symlinkPromise(storePath, zipFile);
}

await expect(
source(`require('no-deps')`),
).resolves.toEqual({name: `no-deps`, version: `1.0.0`});
}),
);
});
13 changes: 13 additions & 0 deletions packages/yarnpkg-libzip/tests/ZipOpenFS.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ export const ZIP_DIR3 = ppath.join(
npath.toPortablePath(__dirname),
`fixtures/foo.hiddenzip` as Filename,
);
export const ZIP_DIR4 = ppath.join(
npath.toPortablePath(__dirname),
`fixtures/symlink.zip` as Filename,
);

export const ZIP_FILE1 = ppath.join(ZIP_DIR1, `foo.txt`);
export const ZIP_FILE2 = ppath.join(ZIP_DIR2, `foo.txt`);
export const ZIP_FILE3 = ppath.join(ZIP_DIR3, `foo.txt`);
export const ZIP_FILE4 = ppath.join(ZIP_DIR4, `foo.txt`);

afterEach(() => {
jest.useRealTimers();
Expand Down Expand Up @@ -81,6 +86,14 @@ describe(`ZipOpenFS`, () => {
fs.discardAndClose();
});

it(`can read from a zip file that's a symlink`, () => {
const fs = new ZipOpenFS();

expect(fs.readFileSync(ZIP_FILE4, `utf8`)).toEqual(`foo\n`);

fs.discardAndClose();
});

it(`doesn't close a ZipFS instance with open handles`, () => {
const fs = new ZipOpenFS({maxOpenFiles: 1});

Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions packages/yarnpkg-libzip/tests/fixtures/symlink.zip

0 comments on commit 870da46

Please sign in to comment.