mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-31 12:10:49 -04:00
Replace the external `@pnpm/registry-mock` (Verdaccio) test dependency with an in-repo, in-process registry that serves package fixtures to **both** the pacquet Rust tests and the pnpm CLI (Jest) tests. No separately managed registry process is needed. ### How it works - **Fixtures** live at `registry/.fixtures/packages/<name>/<version>/…`, moved verbatim from [`pnpm/registry-mock`](https://github.com/pnpm/registry-mock) (keyed by each `package.json`'s `name`+`version`). - **`pnpm-registry-fixtures`** builds verdaccio-shaped storage from those fixtures; the in-tree **`pnpm-registry`** crate serves it. - Files whose names differ only by case (`@pnpm.e2e/with-same-file-in-different-cases`) and `bundleDependencies` trees are composed **in memory** by the builder, since neither can be committed to the working tree. - **pacquet**: `pacquet-testing-utils`' `TestRegistry` starts the server lazily (once per process) in proxy mode, serving `@pnpm.e2e` fixtures locally and falling through to the npm uplink for real packages (`is-positive`, `is-negative`, …) — matching how registry-mock behaved. - **pnpm CLI**: the `with-registry` Jest `globalSetup` builds storage from the fixtures via the new `pnpm-registry-prepare` binary (built from source in the Test CI job) and serves it with `pnpm-registry`. `REGISTRY_MOCK_PORT` / `REGISTRY_MOCK_CREDENTIALS` / `getIntegrity` now come from `@pnpm/testing.registry-mock`. ### Result `@pnpm/registry-mock` is removed from every manifest, the catalog, and `packageExtensions`; `cargo test` / `cargo nextest run` / `just test` and the pnpm CLI Jest suites all run registry-backed tests without launching Verdaccio.
118 lines
3.1 KiB
TypeScript
118 lines
3.1 KiB
TypeScript
import path from 'node:path'
|
|
|
|
import { beforeEach, describe, expect, test } from '@jest/globals'
|
|
import { cache } from '@pnpm/cache.commands'
|
|
import { prepare } from '@pnpm/prepare'
|
|
import { REGISTRY_MOCK_PORT } from '@pnpm/testing.registry-mock'
|
|
import { rimrafSync } from '@zkochan/rimraf'
|
|
import { safeExeca as execa } from 'execa'
|
|
|
|
const pnpmBin = path.join(import.meta.dirname, '../../../pnpm/bin/pnpm.mjs')
|
|
const REGISTRY = `http://localhost:${REGISTRY_MOCK_PORT}/`
|
|
|
|
describe('cache view', () => {
|
|
let cacheDir: string
|
|
let storeDir: string
|
|
beforeEach(async () => {
|
|
prepare()
|
|
cacheDir = path.resolve('cache')
|
|
storeDir = path.resolve('store')
|
|
|
|
await execa('node', [
|
|
pnpmBin,
|
|
'add',
|
|
'is-negative@2.1.0',
|
|
`--store-dir=${storeDir}`,
|
|
`--cache-dir=${cacheDir}`,
|
|
'--config.resolution-mode=highest',
|
|
`--registry=${REGISTRY}`,
|
|
])
|
|
rimrafSync('node_modules')
|
|
rimrafSync('pnpm-lock.yaml')
|
|
await execa('node', [
|
|
pnpmBin,
|
|
'add',
|
|
'is-negative@2.1.0',
|
|
`--store-dir=${storeDir}`,
|
|
`--cache-dir=${cacheDir}`,
|
|
'--config.resolution-mode=highest',
|
|
])
|
|
})
|
|
test('lists all metadata for requested package', async () => {
|
|
const result = await cache.handler({
|
|
cacheDir,
|
|
cliOptions: {},
|
|
pnpmHomeDir: process.cwd(),
|
|
storeDir,
|
|
}, ['view', 'is-negative'])
|
|
|
|
expect(JSON.parse(result!)).toMatchObject({
|
|
[`localhost:${REGISTRY_MOCK_PORT}`]: {
|
|
cachedVersions: ['2.1.0'],
|
|
nonCachedVersions: [
|
|
'1.0.0',
|
|
'1.0.1',
|
|
'2.0.0',
|
|
'2.0.1',
|
|
'2.0.2',
|
|
],
|
|
},
|
|
'registry.npmjs.org': {
|
|
cachedVersions: ['2.1.0'],
|
|
nonCachedVersions: [
|
|
'1.0.0',
|
|
'1.0.1',
|
|
'2.0.0',
|
|
'2.0.1',
|
|
'2.0.2',
|
|
],
|
|
},
|
|
})
|
|
})
|
|
test('lists metadata for requested package from specified registry', async () => {
|
|
const result = await cache.handler({
|
|
cacheDir,
|
|
cliOptions: {
|
|
registry: 'https://registry.npmjs.org/',
|
|
},
|
|
pnpmHomeDir: process.cwd(),
|
|
storeDir,
|
|
}, ['view', 'is-negative'])
|
|
|
|
expect(JSON.parse(result!)).toMatchObject({
|
|
'registry.npmjs.org': {
|
|
cachedVersions: ['2.1.0'],
|
|
nonCachedVersions: [
|
|
'1.0.0',
|
|
'1.0.1',
|
|
'2.0.0',
|
|
'2.0.1',
|
|
'2.0.2',
|
|
],
|
|
},
|
|
})
|
|
})
|
|
|
|
test('lists all metadata for requested package should specify a package name', async () => {
|
|
await expect(
|
|
cache.handler({
|
|
cacheDir,
|
|
cliOptions: {},
|
|
pnpmHomeDir: process.cwd(),
|
|
storeDir,
|
|
}, ['view'])
|
|
).rejects.toThrow('`pnpm cache view` requires the package name')
|
|
})
|
|
|
|
test('lists all metadata for requested package should not accept more than one package name', async () => {
|
|
await expect(
|
|
cache.handler({
|
|
cacheDir,
|
|
cliOptions: {},
|
|
pnpmHomeDir: process.cwd(),
|
|
storeDir,
|
|
}, ['view', 'is-negative', 'is-positive'])
|
|
).rejects.toThrow('`pnpm cache view` only accepts one package name')
|
|
})
|
|
})
|