From 2234833a9fc38730f55688db6f7994f99a699c40 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 28 Jan 2025 19:12:00 +0100 Subject: [PATCH 1/2] test(nuxi): update module add command to use latest content version --- package.json | 2 ++ packages/nuxi/test/unit/commands/module/add.spec.ts | 11 +++++++++-- pnpm-lock.yaml | 6 ++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 20bf2472d..5ffa9dbe4 100644 --- a/package.json +++ b/package.json @@ -25,11 +25,13 @@ "@antfu/eslint-config": "^4.1.0", "@nuxt/eslint-config": "^0.7.5", "@types/node": "^22.10.10", + "@types/semver": "^7.5.8", "@vitest/coverage-v8": "^3.0.4", "changelogen": "^0.5.7", "eslint": "^9.19.0", "knip": "^5.43.3", "pkg-pr-new": "^0.0.39", + "semver": "^7.6.3", "std-env": "^3.8.0", "tinyexec": "^0.3.2", "typescript": "^5.7.3", diff --git a/packages/nuxi/test/unit/commands/module/add.spec.ts b/packages/nuxi/test/unit/commands/module/add.spec.ts index ccc4d9189..909470676 100644 --- a/packages/nuxi/test/unit/commands/module/add.spec.ts +++ b/packages/nuxi/test/unit/commands/module/add.spec.ts @@ -1,4 +1,6 @@ -import { describe, expect, it, vi } from 'vitest' +import { satisfies } from 'semver' +import { beforeAll, describe, expect, it, vi } from 'vitest' + import commands from '../../../../src/commands/module' import * as utils from '../../../../src/commands/module/_utils' import * as runCommands from '../../../../src/run' @@ -37,6 +39,11 @@ function applyMocks() { }) } describe('module add', () => { + let v3: string + beforeAll(async () => { + const versions = await fetch('https://registry.npmjs.org/@nuxt/content').then(r => r.json()).then(r => Object.keys(r.versions).reverse()) + v3 = versions.find(v => satisfies(v, '^3.0.0'))! + }) applyMocks() vi.spyOn(runCommands, 'runCommand').mockImplementation(vi.fn()) vi.spyOn(utils, 'getNuxtVersion').mockResolvedValue('3.0.0') @@ -76,7 +83,7 @@ describe('module add', () => { }, }) - expect(addDependency).toHaveBeenCalledWith(['@nuxt/content@3.0.0'], { + expect(addDependency).toHaveBeenCalledWith([`@nuxt/content@${v3}`], { cwd: '/fake-dir', dev: true, installPeerDependencies: true, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8207dee62..082a392a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,6 +25,9 @@ importers: '@types/node': specifier: ^22.10.10 version: 22.10.10 + '@types/semver': + specifier: ^7.5.8 + version: 7.5.8 '@vitest/coverage-v8': specifier: ^3.0.4 version: 3.0.4(vitest@3.0.4(@types/debug@4.1.12)(@types/node@22.10.10)(jiti@2.4.2)(terser@5.37.0)(yaml@2.7.0)) @@ -40,6 +43,9 @@ importers: pkg-pr-new: specifier: ^0.0.39 version: 0.0.39 + semver: + specifier: ^7.6.3 + version: 7.6.3 std-env: specifier: ^3.8.0 version: 3.8.0 From d34f6e9655d1e1c05498b5fad32cdb52d65c429c Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 28 Jan 2025 19:13:41 +0100 Subject: [PATCH 2/2] fix: use latest tag instead --- package.json | 2 -- packages/nuxi/test/unit/commands/module/add.spec.ts | 6 +++--- pnpm-lock.yaml | 6 ------ 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 5ffa9dbe4..20bf2472d 100644 --- a/package.json +++ b/package.json @@ -25,13 +25,11 @@ "@antfu/eslint-config": "^4.1.0", "@nuxt/eslint-config": "^0.7.5", "@types/node": "^22.10.10", - "@types/semver": "^7.5.8", "@vitest/coverage-v8": "^3.0.4", "changelogen": "^0.5.7", "eslint": "^9.19.0", "knip": "^5.43.3", "pkg-pr-new": "^0.0.39", - "semver": "^7.6.3", "std-env": "^3.8.0", "tinyexec": "^0.3.2", "typescript": "^5.7.3", diff --git a/packages/nuxi/test/unit/commands/module/add.spec.ts b/packages/nuxi/test/unit/commands/module/add.spec.ts index 909470676..12f7199c0 100644 --- a/packages/nuxi/test/unit/commands/module/add.spec.ts +++ b/packages/nuxi/test/unit/commands/module/add.spec.ts @@ -1,4 +1,3 @@ -import { satisfies } from 'semver' import { beforeAll, describe, expect, it, vi } from 'vitest' import commands from '../../../../src/commands/module' @@ -41,8 +40,9 @@ function applyMocks() { describe('module add', () => { let v3: string beforeAll(async () => { - const versions = await fetch('https://registry.npmjs.org/@nuxt/content').then(r => r.json()).then(r => Object.keys(r.versions).reverse()) - v3 = versions.find(v => satisfies(v, '^3.0.0'))! + v3 = await fetch('https://registry.npmjs.org/@nuxt/content') + .then(r => r.json()) + .then(r => r['dist-tags'].latest) }) applyMocks() vi.spyOn(runCommands, 'runCommand').mockImplementation(vi.fn()) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 082a392a8..8207dee62 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,9 +25,6 @@ importers: '@types/node': specifier: ^22.10.10 version: 22.10.10 - '@types/semver': - specifier: ^7.5.8 - version: 7.5.8 '@vitest/coverage-v8': specifier: ^3.0.4 version: 3.0.4(vitest@3.0.4(@types/debug@4.1.12)(@types/node@22.10.10)(jiti@2.4.2)(terser@5.37.0)(yaml@2.7.0)) @@ -43,9 +40,6 @@ importers: pkg-pr-new: specifier: ^0.0.39 version: 0.0.39 - semver: - specifier: ^7.6.3 - version: 7.6.3 std-env: specifier: ^3.8.0 version: 3.8.0