|
| 1 | +import {xfs, ppath} from '@yarnpkg/fslib'; |
| 2 | + |
| 3 | +const { |
| 4 | + fs: {FsLinkType, determineLinkType}, |
| 5 | +} = require(`pkg-tests-core`); |
| 6 | + |
| 7 | +const customStoreFolderName = `.customStore`; |
| 8 | + |
| 9 | +describe(`Features`, () => { |
| 10 | + describe(`pnpmStoreLocation`, () => { |
| 11 | + test( |
| 12 | + `it should create the store at custom path and symlink all files to the custom store location`, |
| 13 | + makeTemporaryEnv( |
| 14 | + { |
| 15 | + dependencies: {[`no-deps`]: `1.0.0`}, |
| 16 | + }, |
| 17 | + { |
| 18 | + nodeLinker: `pnpm`, |
| 19 | + pnpmStoreFolder: customStoreFolderName, |
| 20 | + winLinkType: `symlinks`, |
| 21 | + }, |
| 22 | + async ({path, run, source}) => { |
| 23 | + await run(`install`); |
| 24 | + |
| 25 | + // Ensure that the customized folder is created |
| 26 | + const absolutePnpmStorePath = ppath.join(path, customStoreFolderName); |
| 27 | + expect(xfs.existsSync(absolutePnpmStorePath)).toEqual(true); |
| 28 | + |
| 29 | + // Ensure that the default node_modules/.store folder is not created |
| 30 | + expect(xfs.existsSync(ppath.join(path, `node_modules`, `.store`))).toEqual(false); |
| 31 | + |
| 32 | + // Ensure that the installed package is a symbolic link |
| 33 | + const installedPackagePath = ppath.join(path, `node_modules`, `no-deps`); |
| 34 | + expect(await determineLinkType(installedPackagePath)).toEqual(FsLinkType.SYMBOLIC); |
| 35 | + |
| 36 | + // Ensure that the link target is a relative path |
| 37 | + const installedPackageLinkTarget = await xfs.readlinkPromise(installedPackagePath); |
| 38 | + expect(ppath.isAbsolute(installedPackageLinkTarget)).toBeFalsy(); |
| 39 | + |
| 40 | + // Ensure that the resolved link target is within the customized pnpmStoreFolder. |
| 41 | + const resolvedPackageLinkTarget = ppath.join(ppath.dirname(installedPackagePath), installedPackageLinkTarget); |
| 42 | + expect(ppath.contains(absolutePnpmStorePath, resolvedPackageLinkTarget)).toBeTruthy(); |
| 43 | + }, |
| 44 | + ), |
| 45 | + ); |
| 46 | + }); |
| 47 | +}); |
0 commit comments