Skip to content

Commit 0bf3eef

Browse files
committed
test: Add tests for virtual deduplication
1 parent e5ab340 commit 0bf3eef

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

packages/acceptance-tests/pkg-tests-specs/sources/dragon.test.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,4 +726,111 @@ describe(`Dragon tests`, () => {
726726
},
727727
),
728728
);
729+
730+
test(`it should pass the dragon test 14`,
731+
makeTemporaryEnv(
732+
{
733+
private: true,
734+
workspaces: [
735+
`pkg-a`,
736+
`pkg-b`,
737+
],
738+
},
739+
async ({path, run, source}) => {
740+
// This dragon test represents the following scenario:
741+
//
742+
// .
743+
// ├── pkg-a/
744+
// │ └── (alias-1) [email protected]
745+
// │ └── (peer) does-not-matter
746+
// └── pkg-b/
747+
// └── (alias-2) [email protected]
748+
// └── (peer) does-not-matter
749+
//
750+
// The same package is installed under two different aliases. This test
751+
// checks that the two instances are properly deduplicated despite
752+
// having different idents.
753+
754+
await xfs.mkdirpPromise(`${path}/pkg-a`);
755+
await xfs.writeJsonPromise(`${path}/pkg-a/package.json`, {
756+
name: `a`,
757+
dependencies: {
758+
[`alias-1`]: `npm:[email protected]`,
759+
[`no-deps`]: `1.0.0`,
760+
},
761+
});
762+
763+
await xfs.mkdirpPromise(`${path}/pkg-b`);
764+
await xfs.writeJsonPromise(`${path}/pkg-b/package.json`, {
765+
name: `b`,
766+
dependencies: {
767+
[`alias-2`]: `npm:[email protected]`,
768+
[`no-deps`]: `1.0.0`,
769+
},
770+
});
771+
772+
await expect(run(`install`)).resolves.toBeTruthy();
773+
774+
// The virtual descriptors should be different but the virtual package should be the same
775+
const aPath = npath.fromPortablePath(ppath.join(path, `pkg-a/package.json`));
776+
const bPath = npath.fromPortablePath(ppath.join(path, `pkg-b/package.json`));
777+
await expect(source(`(
778+
createRequire = require('module').createRequire,
779+
createRequire(${JSON.stringify(aPath)}).resolve('alias-1/package.json') === createRequire(${JSON.stringify(bPath)}).resolve('alias-2/package.json')
780+
)`)).resolves.toBe(true);
781+
},
782+
),
783+
);
784+
785+
test(`it should pass the dragon test 15`,
786+
makeTemporaryEnv(
787+
{
788+
private: true,
789+
workspaces: [
790+
`pkg-a`,
791+
`pkg-b`,
792+
],
793+
},
794+
async ({path, run, source}) => {
795+
// This dragon test represents the following scenario:
796+
//
797+
// .
798+
// ├── pkg-a/
799+
// │ └── (alias-1) [email protected]
800+
// │ └── (peer) does-not-matter
801+
// └── pkg-b/
802+
// └── (alias-1) [email protected]
803+
// │ └── (peer) does-not-matter
804+
// └── (alias-2) [email protected]
805+
// └── (peer) does-not-matter
806+
//
807+
// The same package is installed under two different aliases. When
808+
// traversing pkg-b, we deduplicate the virtual package installed under
809+
// alias-1 to the one under pkg-a, but the virtual package is the same
810+
// one installed under alias-2. This test checks that we don't leave
811+
// dangling references to the virtual package that was removed.
812+
813+
await xfs.mkdirpPromise(`${path}/pkg-a`);
814+
await xfs.writeJsonPromise(`${path}/pkg-a/package.json`, {
815+
name: `a`,
816+
dependencies: {
817+
[`alias-1`]: `npm:[email protected]`,
818+
[`no-deps`]: `1.0.0`,
819+
},
820+
});
821+
822+
await xfs.mkdirpPromise(`${path}/pkg-b`);
823+
await xfs.writeJsonPromise(`${path}/pkg-b/package.json`, {
824+
name: `b`,
825+
dependencies: {
826+
[`alias-1`]: `npm:[email protected]`,
827+
[`alias-2`]: `npm:[email protected]`,
828+
[`no-deps`]: `1.0.0`,
829+
},
830+
});
831+
832+
await expect(run(`install`)).resolves.toBeTruthy();
833+
},
834+
),
835+
);
729836
});

0 commit comments

Comments
 (0)