Skip to content

Commit

Permalink
chore: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
fireairforce committed Oct 25, 2023
1 parent b862428 commit 822845b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
Expand Up @@ -76,8 +76,8 @@ export function getUpdateChoices (outdatedPkgsOfProjects: OutdatedPackage[], wor
}
})

// To filter out selected "dependencies" or "devDependencies" in the final output,
// we rename it here to "[dependencies]" or "[devDependencies]",
// To filter out selected "dependencies", "devDependencies", "packageManager" in the final output,
// we rename it here to "[dependencies]", "[devDependencies]" and "packageManager"
// which will be filtered out in the format function of the prompt.
finalChoices.push({ name: `[${depGroup}]`, choices, message: depGroup })

Expand Down
5 changes: 3 additions & 2 deletions pkg-manager/plugin-commands-installation/src/update/index.ts
Expand Up @@ -268,8 +268,9 @@ async function interactiveUpdate (
} as any) as any // eslint-disable-line @typescript-eslint/no-explicit-any

updateDependencies = (updateDependencies as ChoiceRow[]).filter(dep => !(dep.path && dep.path.startsWith('[packageManager]')))
if (opts.save !== false) {
const packageManagerManifest = outdatedPkgsOfProjects[0].filter(pkg => pkg.belongsTo === 'packageManager')
const packageManagerManifest = outdatedPkgsOfProjects[0].filter(pkg => pkg.belongsTo === 'packageManager')

if (opts.save !== false && packageManagerManifest.length) {
await updateProjectCorepackConfig({
...opts,
updatedVersion: packageManagerManifest[0].wanted,
Expand Down
Expand Up @@ -6,7 +6,7 @@ test('getUpdateChoices()', () => {
getUpdateChoices([
{
alias: 'foo',
belongsTo: 'dependencies' as const,
belongsTo: 'dependencies',
current: '1.0.0',
latestManifest: {
name: 'foo',
Expand All @@ -18,7 +18,7 @@ test('getUpdateChoices()', () => {
},
{
alias: 'foo',
belongsTo: 'devDependencies' as const,
belongsTo: 'devDependencies',
current: '1.0.0',
latestManifest: {
name: 'foo',
Expand All @@ -32,7 +32,7 @@ test('getUpdateChoices()', () => {
},
{
alias: 'qar',
belongsTo: 'devDependencies' as const,
belongsTo: 'devDependencies',
current: '1.0.0',
latestManifest: {
name: 'qar',
Expand All @@ -43,7 +43,7 @@ test('getUpdateChoices()', () => {
},
{
alias: 'zoo',
belongsTo: 'devDependencies' as const,
belongsTo: 'devDependencies',
current: '1.1.0',
latestManifest: {
name: 'zoo',
Expand All @@ -54,7 +54,7 @@ test('getUpdateChoices()', () => {
},
{
alias: 'qaz',
belongsTo: 'optionalDependencies' as const,
belongsTo: 'optionalDependencies',
current: '1.0.1',
latestManifest: {
name: 'qaz',
Expand All @@ -65,7 +65,7 @@ test('getUpdateChoices()', () => {
},
{
alias: 'qaz',
belongsTo: 'devDependencies' as const,
belongsTo: 'devDependencies',
current: '1.0.1',
latestManifest: {
name: 'qaz',
Expand All @@ -74,6 +74,17 @@ test('getUpdateChoices()', () => {
packageName: 'foo',
wanted: '1.0.1',
},
{
alias: 'pnpm',
belongsTo: 'packageManager',
current: '7.9.1',
latestManifest: {
name: 'pnpm',
version: '7.9.2',
},
packageName: 'pnpm',
wanted: '7.9.1',
},
], false))
.toStrictEqual([
{
Expand Down Expand Up @@ -137,5 +148,22 @@ test('getUpdateChoices()', () => {
},
],
},
{
name: '[packageManager]',
message: 'packageManager',
choices: [
{
name: 'Package Current Target URL ',
disabled: true,
hint: '',
value: '',
},
{
message: chalk`pnpm 7.9.1 ❯ 7.9.{greenBright.bold 2} `,
name: 'pnpm',
value: 'pnpm',
},
],
},
])
})
Expand Up @@ -358,7 +358,7 @@ test('interactively update should ignore dependencies from the ignoreDependencie
test('interactively update should update corepack config', async () => {
prepare({
name: 'project-1',
packageManager: 'foo@0.0.6',
packageManager: 'pnpm@8.7.0',
})

const storeDir = path.resolve('pnpm-store')
Expand All @@ -379,14 +379,14 @@ test('interactively update should update corepack config', async () => {
save: false,
storeDir,
},
['foo@0.0.7']
['pnpm@8.9.2']
)

prompt.mockResolvedValue({
updateDependencies: [
{
value: 'foo',
name: chalk`foo 0.0.60.0.{greenBright.bold 7} https://pnpm.io/ `,
value: 'pnpm',
name: chalk`pnpm 8.7.08.9.2 https://pnpm.io/ `,
},
],
})
Expand All @@ -407,9 +407,9 @@ test('interactively update should update corepack config', async () => {
choices: [
headerChoice,
{
message: chalk`foo 0.0.60.0.7 `,
value: 'foo',
name: 'foo',
message: chalk`pnpm 8.7.08.9.2 `,
value: 'pnpm',
name: 'pnpm',
},
],
name: '[packageManager]',
Expand Down
2 changes: 1 addition & 1 deletion reviewing/outdated/src/outdated.ts
Expand Up @@ -59,7 +59,7 @@ export async function outdated (
const currentLockfile = opts.currentLockfile ?? { importers: { [importerId]: {} } }

const outdated: OutdatedPackage[] = []
if (typeof opts.manifest?.packageManager === 'string') {
if (typeof opts.manifest?.packageManager === 'string' && opts.manifest?.packageManager.startsWith('pnpm@')) {
const [pkgManager, pkgManagerVersion] = opts.manifest.packageManager.split('@')
const latestPkgManifest = await opts.getLatestManifest(pkgManager, 'latest')

Expand Down

0 comments on commit 822845b

Please sign in to comment.