diff --git a/test/getIgnoredUpgradesDueToPeerDeps.test.ts b/test/getIgnoredUpgradesDueToPeerDeps.test.ts index eef1bf81..758a46c0 100644 --- a/test/getIgnoredUpgradesDueToPeerDeps.test.ts +++ b/test/getIgnoredUpgradesDueToPeerDeps.test.ts @@ -1,5 +1,7 @@ import getIgnoredUpgradesDueToPeerDeps from '../src/lib/getIgnoredUpgradesDueToPeerDeps' +import { Packument } from '../src/types/Packument' import chaiSetup from './helpers/chaiSetup' +import stubVersions from './helpers/stubVersions' chaiSetup() @@ -32,13 +34,67 @@ describe('getIgnoredUpgradesDueToPeerDeps', function () { }) }) it('ignored peer after upgrade', async () => { + const stub = stubVersions({ + '@vitest/ui': { + version: '1.6.0', + versions: { + '1.3.1': { + version: '1.3.1', + } as Packument, + '1.6.0': { + version: '1.6.0', + } as Packument, + }, + }, + vitest: { + version: '1.6.0', + versions: { + '1.3.1': { + version: '1.3.1', + } as Packument, + '1.6.0': { + version: '1.6.0', + } as Packument, + }, + }, + eslint: { + version: '9.0.0', + versions: { + '8.57.0': { + version: '8.57.0', + } as Packument, + '9.0.0': { + version: '9.0.0', + } as Packument, + }, + }, + 'eslint-plugin-import': { + version: '2.29.1', + versions: { + '2.29.1': { + version: '2.29.1', + } as Packument, + }, + }, + 'eslint-plugin-unused-imports': { + version: '4.0.0', + versions: { + '4.0.0': { + version: '4.0.0', + } as Packument, + '3.0.0': { + version: '3.0.0', + } as Packument, + }, + }, + }) const data = await getIgnoredUpgradesDueToPeerDeps( { '@vitest/ui': '1.3.1', vitest: '1.3.1', eslint: '8.57.0', 'eslint-plugin-import': '2.29.1', - 'eslint-plugin-unused-imports': '^3', + 'eslint-plugin-unused-imports': '3.0.0', }, { '@vitest/ui': '1.6.0', @@ -67,18 +123,19 @@ describe('getIgnoredUpgradesDueToPeerDeps', function () { }, { target: packageName => { - return packageName === 'eslint-plugin-unused-imports' ? 'latest' : 'minor' + return packageName === 'eslint-plugin-unused-imports' ? 'greatest' : 'minor' }, }, ) data.should.deep.equal({ 'eslint-plugin-unused-imports': { - from: '^3', + from: '3.0.0', reason: { - 'eslint-plugin-unused-imports': 'eslint ^9.0.0', + 'eslint-plugin-unused-imports': 'eslint 9', }, - to: '^4', + to: '4.0.0', }, }) + stub.restore() }) }) diff --git a/test/getPeerDependenciesFromRegistry.test.ts b/test/getPeerDependenciesFromRegistry.test.ts index 5d713447..0060726e 100644 --- a/test/getPeerDependenciesFromRegistry.test.ts +++ b/test/getPeerDependenciesFromRegistry.test.ts @@ -17,7 +17,7 @@ describe('getPeerDependenciesFromRegistry', function () { it('single package with range', async () => { await chalkInit() - const data = await getPeerDependenciesFromRegistry({ 'eslint-plugin-unused-imports': '^4' }, {}) + const data = await getPeerDependenciesFromRegistry({ 'eslint-plugin-unused-imports': '~4.0.0' }, {}) data.should.deep.equal({ 'eslint-plugin-unused-imports': { '@typescript-eslint/eslint-plugin': '^8.0.0-0', diff --git a/test/peer.test.ts b/test/peer.test.ts index 72780404..6070af94 100644 --- a/test/peer.test.ts +++ b/test/peer.test.ts @@ -1,6 +1,8 @@ import path from 'path' import ncu from '../src/' +import { Packument } from '../src/types/Packument' import chaiSetup from './helpers/chaiSetup' +import stubVersions from './helpers/stubVersions' chaiSetup() @@ -77,26 +79,114 @@ describe('peer dependencies', function () { }) it('ignores if post upgrade peers are unmet', async () => { + const stub = stubVersions({ + '@vitest/ui': { + version: '1.6.0', + versions: { + '1.3.1': { + version: '1.3.1', + } as Packument, + '1.6.0': { + version: '1.6.0', + } as Packument, + }, + }, + vitest: { + version: '1.6.0', + versions: { + '1.3.1': { + version: '1.3.1', + } as Packument, + '1.6.0': { + version: '1.6.0', + } as Packument, + }, + }, + eslint: { + version: '9.0.0', + versions: { + '8.57.0': { + version: '8.57.0', + } as Packument, + '9.0.0': { + version: '9.0.0', + } as Packument, + }, + }, + 'eslint-plugin-import': { + version: '2.29.1', + versions: { + '2.29.1': { + version: '2.29.1', + } as Packument, + }, + }, + 'eslint-plugin-unused-imports': { + version: '4.0.0', + versions: { + '4.0.0': { + version: '4.0.0', + } as Packument, + '3.0.0': { + version: '3.0.0', + } as Packument, + }, + }, + }) const cwd = path.join(__dirname, 'test-data/peer-post-upgrade/') const upgrades = await ncu({ cwd, peer: true, target: packageName => { - return packageName === 'eslint-plugin-unused-imports' ? 'latest' : 'minor' + return packageName === 'eslint-plugin-unused-imports' ? 'greatest' : 'minor' }, }) upgrades!.should.have.all.keys('@vitest/ui', 'vitest') + stub.restore() }) it('ignores if post upgrade peers are unmet - no upgrades', async () => { + const stub = stubVersions({ + eslint: { + version: '9.0.0', + versions: { + '8.57.0': { + version: '8.57.0', + } as Packument, + '9.0.0': { + version: '9.0.0', + } as Packument, + }, + }, + 'eslint-plugin-import': { + version: '2.29.1', + versions: { + '2.29.1': { + version: '2.29.1', + } as Packument, + }, + }, + 'eslint-plugin-unused-imports': { + version: '4.0.0', + versions: { + '4.0.0': { + version: '4.0.0', + } as Packument, + '3.0.0': { + version: '3.0.0', + } as Packument, + }, + }, + }) const cwd = path.join(__dirname, 'test-data/peer-post-upgrade-no-upgrades/') const upgrades = await ncu({ cwd, peer: true, target: packageName => { - return packageName === 'eslint-plugin-unused-imports' ? 'latest' : 'minor' + return packageName === 'eslint-plugin-unused-imports' ? 'greatest' : 'minor' }, }) upgrades!.should.deep.equal({}) + stub.restore() }) }) diff --git a/test/test-data/peer-post-upgrade-no-upgrades/package.json b/test/test-data/peer-post-upgrade-no-upgrades/package.json index 35883f82..334cdde9 100644 --- a/test/test-data/peer-post-upgrade-no-upgrades/package.json +++ b/test/test-data/peer-post-upgrade-no-upgrades/package.json @@ -3,6 +3,6 @@ "dependencies": { "eslint": "8.57.0", "eslint-plugin-import": "2.29.1", - "eslint-plugin-unused-imports": "^3" + "eslint-plugin-unused-imports": "3.0.0" } } diff --git a/test/test-data/peer-post-upgrade/package.json b/test/test-data/peer-post-upgrade/package.json index baca6684..2ee53fb1 100644 --- a/test/test-data/peer-post-upgrade/package.json +++ b/test/test-data/peer-post-upgrade/package.json @@ -5,6 +5,6 @@ "vitest": "1.3.1", "eslint": "8.57.0", "eslint-plugin-import": "2.29.1", - "eslint-plugin-unused-imports": "^3" + "eslint-plugin-unused-imports": "3.0.0" } }