From 41dc031a67cecfe7b861c7e40ba16842b0abd96b Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Sat, 21 Mar 2026 18:21:04 -0400 Subject: [PATCH] test: use `resolution-mode=highest` in tests (#10989) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: configure default resolution-mode to highest in pkg-manager/core * test: update catalog tests for resolution-mode=highest * test: fix `--fix-lockfile` test for new resolution-mode default ``` ● fix broken lockfile with --fix-lockfile expect(received).toBeTruthy() Received: undefined 55 | const lockfile: LockfileFile = readYamlFileSync(WANTED_LOCKFILE) 56 | expect(Object.keys(lockfile.packages as PackageSnapshots)).toHaveLength(2) > 57 | expect(lockfile.packages?.['@types/semver@5.3.31']).toBeTruthy() | ^ 58 | expect(lockfile.packages?.['@types/semver@5.3.31']?.resolution).toEqual({ 59 | integrity: 'sha512-WBv5F9HrWTyG800cB9M3veCVkFahqXN7KA7c3VUCYZm/xhNzzIFiXiq+rZmj75j7GvWelN3YNrLX7FjtqBvhMw==', 60 | }) at Object. (test/install/fixLockfile.ts:57:55) ``` * test: fix lockfile conflict test ● a lockfile v6 with merge conflicts is autofixed expect(received).toHaveProperty(path, value) Expected path: "version" Expected value: "100.1.0" Received value: "101.0.0" 1284 | 1285 | const lockfile = project.readLockfile() > 1286 | expect(lockfile.importers?.['.'].dependencies?.['@pnpm.e2e/dep-of-pkg-with-1-dep']).toHaveProperty('version', '100.1.0') | ^ 1287 | }) 1288 | 1289 | test('a lockfile with duplicate keys is fixed', async () => { at Object. (test/lockfile.ts:1286:87) * test: fix deploy shared lockfile test ● deploy with a shared lockfile that has peer dependencies suffix in workspace package dependency paths expect(received).toMatchObject(expected) - Expected - 6 + Received + 1 @@ -1,11 +1,11 @@ Object { "importers": Object { "packages/project-0": Object { "dependencies": Object { "project-1": Object { - "version": "file:packages/project-1(is-negative@1.0.0)(project-2@file:packages/project-2(is-positive@1.0.0))", + "version": "file:packages/project-1(is-negative@2.1.0)(project-2@file:packages/project-2(is-positive@1.0.0))", }, "project-2": Object { "version": "file:packages/project-2(is-positive@1.0.0)", }, }, @@ -31,13 +31,8 @@ "type": "directory", }, }, }, "snapshots": Object { - "project-1@file:packages/project-1(is-negative@1.0.0)(project-2@file:packages/project-2(is-positive@1.0.0))": Object { - "dependencies": Object { - "project-2": "file:packages/project-2(is-positive@1.0.0)", - }, - }, "project-2@file:packages/project-2(is-positive@1.0.0)": Object {}, }, } 950 | workspaceDir: process.cwd(), 951 | }) > 952 | expect(assertProject('.').readLockfile()).toMatchObject({ | ^ 953 | importers: { 954 | 'packages/project-0': { 955 | dependencies: { at Object. (test/shared-lockfile.test.ts:952:45) * test: fix injectLocalPackages test --- .changeset/wide-hotels-study.md | 5 ++ .../src/install/extendInstallOptions.ts | 2 +- installing/deps-installer/test/catalogs.ts | 56 +++++++++---------- .../test/install/fixLockfile.ts | 8 +-- .../test/install/injectLocalPackages.ts | 6 +- installing/deps-installer/test/lockfile.ts | 1 + .../test/deploy/shared-lockfile.test.ts | 4 +- 7 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 .changeset/wide-hotels-study.md diff --git a/.changeset/wide-hotels-study.md b/.changeset/wide-hotels-study.md new file mode 100644 index 0000000000..b328b827fe --- /dev/null +++ b/.changeset/wide-hotels-study.md @@ -0,0 +1,5 @@ +--- +"@pnpm/core": patch +--- + +The `resolutionMode` option for `mutateModules` now defaults to `highest` to match the default in `@pnpm/config`. It previously defaulted to `lowest-direct`. diff --git a/installing/deps-installer/src/install/extendInstallOptions.ts b/installing/deps-installer/src/install/extendInstallOptions.ts index c0a3770880..6dc2ede533 100644 --- a/installing/deps-installer/src/install/extendInstallOptions.ts +++ b/installing/deps-installer/src/install/extendInstallOptions.ts @@ -243,7 +243,7 @@ const defaults = (opts: InstallOptions): StrictInstallOptions => { pruneStore: false, rawConfig: {}, registries: DEFAULT_REGISTRIES, - resolutionMode: 'lowest-direct', + resolutionMode: 'highest', saveWorkspaceProtocol: 'rolling', scriptsPrependNodePath: false, shamefullyHoist: false, diff --git a/installing/deps-installer/test/catalogs.ts b/installing/deps-installer/test/catalogs.ts index 0f4e1a3143..7f401b7f53 100644 --- a/installing/deps-installer/test/catalogs.ts +++ b/installing/deps-installer/test/catalogs.ts @@ -178,13 +178,13 @@ test('lockfile contains catalog snapshots', async () => { { name: 'project1', dependencies: { - 'is-positive': 'catalog:', + '@pnpm.e2e/bar': 'catalog:', }, }, { name: 'project2', dependencies: { - 'is-negative': 'catalog:', + '@pnpm.e2e/foo': 'catalog:', }, }, ]) @@ -194,8 +194,8 @@ test('lockfile contains catalog snapshots', async () => { lockfileOnly: true, catalogs: { default: { - 'is-positive': '^1.0.0', - 'is-negative': '^1.0.0', + '@pnpm.e2e/bar': '^100.0.0', + '@pnpm.e2e/foo': '^100.0.0', }, }, }) @@ -203,8 +203,8 @@ test('lockfile contains catalog snapshots', async () => { const lockfile = readLockfile() expect(lockfile.catalogs).toStrictEqual({ default: { - 'is-positive': { specifier: '^1.0.0', version: '1.0.0' }, - 'is-negative': { specifier: '^1.0.0', version: '1.0.0' }, + '@pnpm.e2e/bar': { specifier: '^100.0.0', version: '100.1.0' }, + '@pnpm.e2e/foo': { specifier: '^100.0.0', version: '100.1.0' }, }, }) }) @@ -306,13 +306,13 @@ test('lockfile catalog snapshots retain existing entries on --filter', async () { name: 'project1', dependencies: { - 'is-negative': 'catalog:', + '@pnpm.e2e/bar': 'catalog:', }, }, { name: 'project2', dependencies: { - 'is-positive': 'catalog:', + '@pnpm.e2e/foo': 'catalog:', }, }, ]) @@ -322,16 +322,16 @@ test('lockfile catalog snapshots retain existing entries on --filter', async () lockfileOnly: true, catalogs: { default: { - 'is-positive': '^1.0.0', - 'is-negative': '^1.0.0', + '@pnpm.e2e/bar': '^100.0.0', + '@pnpm.e2e/foo': '^1.0.0', }, }, }) expect(readLockfile().catalogs).toStrictEqual({ default: { - 'is-negative': { specifier: '^1.0.0', version: '1.0.0' }, - 'is-positive': { specifier: '^1.0.0', version: '1.0.0' }, + '@pnpm.e2e/bar': { specifier: '^100.0.0', version: '100.1.0' }, + '@pnpm.e2e/foo': { specifier: '^1.0.0', version: '1.3.0' }, }, }) @@ -341,19 +341,19 @@ test('lockfile catalog snapshots retain existing entries on --filter', async () lockfileOnly: true, catalogs: { default: { - 'is-positive': '=3.1.0', - 'is-negative': '^1.0.0', + '@pnpm.e2e/bar': '^100.0.0', + '@pnpm.e2e/foo': '=100.0.0', }, }, }) expect(readLockfile().catalogs).toStrictEqual({ default: { - // The is-negative snapshot should be carried from the previous install, + // The @pnpm.e2e/bar snapshot should be carried from the previous install, // despite the current filtered install not using it. - 'is-negative': { specifier: '^1.0.0', version: '1.0.0' }, + '@pnpm.e2e/bar': { specifier: '^100.0.0', version: '100.1.0' }, - 'is-positive': { specifier: '=3.1.0', version: '3.1.0' }, + '@pnpm.e2e/foo': { specifier: '=100.0.0', version: '100.0.0' }, }, }) }) @@ -513,28 +513,28 @@ test('--fix-lockfile with --filter does not erase catalog snapshots', async () = { name: 'project1', dependencies: { - 'is-negative': 'catalog:', + '@pnpm.e2e/bar': 'catalog:', }, }, { name: 'project2', dependencies: { - 'is-positive': 'catalog:', + '@pnpm.e2e/foo': 'catalog:', }, }, ]) const catalogs = { default: { - 'is-positive': '^1.0.0', - 'is-negative': '^1.0.0', + '@pnpm.e2e/bar': '^100.0.0', + '@pnpm.e2e/foo': '^100.0.0', }, } const expectedCatalogsSnapshot: CatalogSnapshots = { default: { - 'is-negative': { specifier: '^1.0.0', version: '1.0.0' }, - 'is-positive': { specifier: '^1.0.0', version: '1.0.0' }, + '@pnpm.e2e/bar': { specifier: '^100.0.0', version: '100.1.0' }, + '@pnpm.e2e/foo': { specifier: '^100.0.0', version: '100.1.0' }, }, } @@ -1210,7 +1210,7 @@ describe('add', () => { ]) const catalogs = { - default: { '@pnpm.e2e/foo': '^100.0.0' }, + default: { '@pnpm.e2e/foo': '^100.1.0' }, } await mutateModules(installProjects(projects), { @@ -1238,12 +1238,12 @@ describe('add', () => { // Sanity check that the rest of the lockfile has expected contents. expect(readLockfile()).toMatchObject({ - catalogs: { default: { '@pnpm.e2e/foo': { specifier: '^100.0.0', version: '100.0.0' } } }, + catalogs: { default: { '@pnpm.e2e/foo': { specifier: '^100.1.0', version: '100.1.0' } } }, importers: { - project1: { dependencies: { '@pnpm.e2e/foo': { specifier: 'catalog:', version: '100.0.0' } } }, - project2: { dependencies: { '@pnpm.e2e/foo': { specifier: 'catalog:', version: '100.0.0' } } }, + project1: { dependencies: { '@pnpm.e2e/foo': { specifier: 'catalog:', version: '100.1.0' } } }, + project2: { dependencies: { '@pnpm.e2e/foo': { specifier: 'catalog:', version: '100.1.0' } } }, }, - packages: { '@pnpm.e2e/foo@100.0.0': expect.any(Object) }, + packages: { '@pnpm.e2e/foo@100.1.0': expect.any(Object) }, }) }) diff --git a/installing/deps-installer/test/install/fixLockfile.ts b/installing/deps-installer/test/install/fixLockfile.ts index 6806ad0b5b..4333d305cb 100644 --- a/installing/deps-installer/test/install/fixLockfile.ts +++ b/installing/deps-installer/test/install/fixLockfile.ts @@ -16,13 +16,13 @@ test('fix broken lockfile with --fix-lockfile', async () => { writeYamlFileSync(WANTED_LOCKFILE, { dependencies: { '@types/semver': { - specifier: '^5.3.31', + specifier: '5.3.31', version: '5.3.31', }, }, devDependencies: { fsevents: { - specifier: '^2.3.2', + specifier: '2.3.2', version: '2.3.2', }, }, @@ -44,10 +44,10 @@ test('fix broken lockfile with --fix-lockfile', async () => { await install({ dependencies: { - '@types/semver': '^5.3.31', + '@types/semver': '5.3.31', }, devDependencies: { - 'core-js-pure': '^3.16.2', + 'core-js-pure': '3.16.2', }, }, testDefaults({ fixLockfile: true })) diff --git a/installing/deps-installer/test/install/injectLocalPackages.ts b/installing/deps-installer/test/install/injectLocalPackages.ts index b22ee38b07..23ba71be2d 100644 --- a/installing/deps-installer/test/install/injectLocalPackages.ts +++ b/installing/deps-installer/test/install/injectLocalPackages.ts @@ -1802,7 +1802,7 @@ test('injected local packages are deduped', async () => { 'project-1': 'workspace:1.0.0', }, devDependencies: { - 'is-positive': '1.0.0', + 'is-positive': '2.0.0', }, dependenciesMeta: { 'project-1': { @@ -1954,9 +1954,9 @@ test('injected local packages are deduped', async () => { }, }) expect(lockfile.packages['project-1@file:project-1(is-positive@1.0.0)']).toBeFalsy() - expect(lockfile.snapshots['project-2@file:project-2(is-positive@2.0.0)']).toEqual({ + expect(lockfile.snapshots['project-2@file:project-2(is-positive@1.0.0)']).toEqual({ dependencies: { - 'project-1': 'file:project-1(is-positive@2.0.0)', + 'project-1': 'file:project-1(is-positive@1.0.0)', }, transitivePeerDependencies: ['is-positive'], }) diff --git a/installing/deps-installer/test/lockfile.ts b/installing/deps-installer/test/lockfile.ts index 14390e49e1..132767d362 100644 --- a/installing/deps-installer/test/lockfile.ts +++ b/installing/deps-installer/test/lockfile.ts @@ -1244,6 +1244,7 @@ packages: test('a lockfile v6 with merge conflicts is autofixed', async () => { const project = prepareEmpty() + await addDistTag({ package: '@pnpm.e2e/dep-of-pkg-with-1-dep', version: '100.1.0', distTag: 'latest' }) fs.writeFileSync(WANTED_LOCKFILE, `\ lockfileVersion: '${LOCKFILE_VERSION}' diff --git a/releasing/commands/test/deploy/shared-lockfile.test.ts b/releasing/commands/test/deploy/shared-lockfile.test.ts index 450954cc73..ab4af31334 100644 --- a/releasing/commands/test/deploy/shared-lockfile.test.ts +++ b/releasing/commands/test/deploy/shared-lockfile.test.ts @@ -899,7 +899,7 @@ test('deploy with a shared lockfile that has peer dependencies suffix in workspa 'project-2': 'workspace:*', }, peerDependencies: { - 'is-negative': '>=1.0.0', + 'is-negative': '1.0.0', 'project-2': '*', }, }, @@ -907,7 +907,7 @@ test('deploy with a shared lockfile that has peer dependencies suffix in workspa name: 'project-2', version: '0.0.0', peerDependencies: { - 'is-positive': '>=1.0.0', + 'is-positive': '1.0.0', }, }, }