Skip to content

Commit

Permalink
fix: check if upgrade ignored due to engines fails due to usage of ra…
Browse files Browse the repository at this point in the history
…nges
  • Loading branch information
rbnayax committed Aug 11, 2024
1 parent 20ebfc1 commit 472db67
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 10 deletions.
67 changes: 62 additions & 5 deletions test/getIgnoredUpgradesDueToPeerDeps.test.ts
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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()
})
})
2 changes: 1 addition & 1 deletion test/getPeerDependenciesFromRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
94 changes: 92 additions & 2 deletions test/peer.test.ts
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -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()
})
})
2 changes: 1 addition & 1 deletion test/test-data/peer-post-upgrade-no-upgrades/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion test/test-data/peer-post-upgrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 472db67

Please sign in to comment.