mirror of
https://github.com/pnpm/pnpm.git
synced 2026-06-28 18:05:29 -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.
80 lines
2.3 KiB
TypeScript
80 lines
2.3 KiB
TypeScript
import path from 'node:path'
|
|
|
|
import type { HeadlessOptions } from '@pnpm/installing.deps-restorer'
|
|
import { readProjectsContext } from '@pnpm/installing.read-projects-context'
|
|
import { safeReadPackageJsonFromDir } from '@pnpm/pkg-manifest.reader'
|
|
import { getStorePath } from '@pnpm/store.path'
|
|
import { REGISTRY_MOCK_PORT } from '@pnpm/testing.registry-mock'
|
|
import { createTempStore } from '@pnpm/testing.temp-store'
|
|
import { temporaryDirectory } from 'tempy'
|
|
|
|
const registry = `http://localhost:${REGISTRY_MOCK_PORT}/`
|
|
|
|
export async function testDefaults (
|
|
opts?: any, // eslint-disable-line
|
|
resolveOpts?: any, // eslint-disable-line
|
|
fetchOpts?: any, // eslint-disable-line
|
|
storeOpts?: any, // eslint-disable-line
|
|
): Promise<HeadlessOptions> {
|
|
const tmp = temporaryDirectory()
|
|
let storeDir = opts?.storeDir ?? path.join(tmp, 'store')
|
|
const lockfileDir = opts?.lockfileDir ?? process.cwd()
|
|
const { include, pendingBuilds, projects } = await readProjectsContext(
|
|
opts.projects
|
|
? opts.projects.map((rootDir: string) => ({ rootDir }))
|
|
: [
|
|
{
|
|
rootDir: lockfileDir,
|
|
},
|
|
],
|
|
{ lockfileDir }
|
|
)
|
|
storeDir = await getStorePath({
|
|
pkgRoot: lockfileDir,
|
|
storePath: storeDir,
|
|
pnpmHomeDir: '',
|
|
})
|
|
const { storeController } = createTempStore(
|
|
{
|
|
storeDir,
|
|
clientOptions: {
|
|
...resolveOpts,
|
|
...fetchOpts,
|
|
},
|
|
storeOptions: storeOpts,
|
|
}
|
|
)
|
|
return {
|
|
currentEngine: {
|
|
nodeVersion: process.version,
|
|
pnpmVersion: '2.0.0',
|
|
},
|
|
engineStrict: false,
|
|
force: false,
|
|
hoistedDependencies: {},
|
|
hoistPattern: ['*'],
|
|
include,
|
|
lockfileDir,
|
|
packageManager: {
|
|
name: 'pnpm',
|
|
version: '1.0.0',
|
|
},
|
|
pendingBuilds,
|
|
selectedProjectDirs: opts.selectedProjectDirs ?? projects.map((project) => project.rootDir),
|
|
allProjects: Object.fromEntries(
|
|
await Promise.all(projects.map(async (project) => [project.rootDir, { ...project, manifest: await safeReadPackageJsonFromDir(project.rootDir) }]))
|
|
),
|
|
authConfig: {},
|
|
registries: {
|
|
default: registry,
|
|
},
|
|
sideEffectsCache: true,
|
|
skipped: new Set<string>(),
|
|
storeController,
|
|
storeDir,
|
|
unsafePerm: true,
|
|
verifyStoreIntegrity: true,
|
|
...opts,
|
|
}
|
|
}
|