mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-20 12:42:38 -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.
67 lines
2.4 KiB
TypeScript
67 lines
2.4 KiB
TypeScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
import { expect } from '@jest/globals'
|
|
import { StoreIndex, storeIndexKey } from '@pnpm/store.index'
|
|
import { getIntegrity, REGISTRY_MOCK_PORT } from '@pnpm/testing.registry-mock'
|
|
|
|
export interface StoreAssertions {
|
|
getPkgIndexFilePath: (pkgName: string, version: string) => string
|
|
cafsHas: (pkgName: string, version: string) => void
|
|
cafsHasNot: (pkgName: string, version: string) => void
|
|
storeHas: (pkgName: string, version?: string) => void
|
|
storeHasNot: (pkgName: string, version?: string) => void
|
|
resolve: (pkgName: string, version?: string, relativePath?: string) => string
|
|
}
|
|
|
|
export function assertStore (
|
|
storePath: string,
|
|
encodedRegistryName?: string
|
|
): StoreAssertions {
|
|
// eslint-disable-next-line
|
|
const ok = (value: any) => expect(value).toBeTruthy()
|
|
// eslint-disable-next-line
|
|
const notOk = (value: any) => expect(value).toBeFalsy()
|
|
const ern = encodedRegistryName ?? `localhost+${REGISTRY_MOCK_PORT}`
|
|
const store = {
|
|
getPkgIndexFilePath (pkgName: string, version: string): string {
|
|
const integrity = getIntegrity(pkgName, version)
|
|
return storeIndexKey(integrity, `${pkgName}@${version}`)
|
|
},
|
|
cafsHas (pkgName: string, version: string): void {
|
|
const pathToCheck = store.getPkgIndexFilePath(pkgName, version)
|
|
const storeIndex = new StoreIndex(storePath)
|
|
try {
|
|
ok(storeIndex.get(pathToCheck) != null)
|
|
} finally {
|
|
storeIndex.close()
|
|
}
|
|
},
|
|
cafsHasNot (pkgName: string, version: string): void {
|
|
const pathToCheck = store.getPkgIndexFilePath(pkgName, version)
|
|
const storeIndex = new StoreIndex(storePath)
|
|
try {
|
|
notOk(storeIndex.get(pathToCheck) != null)
|
|
} finally {
|
|
storeIndex.close()
|
|
}
|
|
},
|
|
storeHas (pkgName: string, version?: string): void {
|
|
const pathToCheck = store.resolve(pkgName, version)
|
|
ok(fs.existsSync(pathToCheck))
|
|
},
|
|
storeHasNot (pkgName: string, version?: string): void {
|
|
const pathToCheck = store.resolve(pkgName, version)
|
|
notOk(fs.existsSync(pathToCheck))
|
|
},
|
|
resolve (pkgName: string, version?: string, relativePath?: string): string {
|
|
const pkgFolder = version ? path.join(ern, pkgName, version) : pkgName
|
|
if (relativePath) {
|
|
return path.join(storePath, pkgFolder, relativePath)
|
|
}
|
|
return path.join(storePath, pkgFolder)
|
|
},
|
|
}
|
|
return store
|
|
}
|