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.
119 lines
4.2 KiB
TypeScript
119 lines
4.2 KiB
TypeScript
/// <reference path="../../../__typings__/index.d.ts" />
|
|
import path from 'node:path'
|
|
|
|
import { expect, test } from '@jest/globals'
|
|
import { assertProject } from '@pnpm/assert-project'
|
|
import { importCommand } from '@pnpm/installing.commands'
|
|
import { fixtures } from '@pnpm/test-fixtures'
|
|
import { REGISTRY_MOCK_PORT } from '@pnpm/testing.registry-mock'
|
|
import { filterProjectsBySelectorObjectsFromDir } from '@pnpm/workspace.projects-filter'
|
|
import { temporaryDirectory } from 'tempy'
|
|
|
|
const f = fixtures(import.meta.dirname)
|
|
const REGISTRY = `http://localhost:${REGISTRY_MOCK_PORT}`
|
|
const TMP = temporaryDirectory()
|
|
|
|
const DEFAULT_OPTS = {
|
|
ca: undefined,
|
|
cacheDir: path.join(TMP, 'cache'),
|
|
cert: undefined,
|
|
fetchRetries: 2,
|
|
fetchRetryFactor: 90,
|
|
fetchRetryMaxtimeout: 90,
|
|
fetchRetryMintimeout: 10,
|
|
httpsProxy: undefined,
|
|
key: undefined,
|
|
localAddress: undefined,
|
|
lock: false,
|
|
lockStaleDuration: 90,
|
|
minimumReleaseAge: 0,
|
|
networkConcurrency: 16,
|
|
offline: false,
|
|
preferWorkspacePackages: true,
|
|
proxy: undefined,
|
|
pnpmHomeDir: '',
|
|
configByUri: {},
|
|
registries: { default: REGISTRY },
|
|
registry: REGISTRY,
|
|
rootProjectManifestDir: '',
|
|
storeDir: path.join(TMP, 'store'),
|
|
strictSsl: false,
|
|
userAgent: 'pnpm',
|
|
userConfig: {},
|
|
useRunningStoreServer: false,
|
|
useStoreServer: false,
|
|
virtualStoreDirMaxLength: process.platform === 'win32' ? 60 : 120,
|
|
}
|
|
|
|
test('import from shared yarn.lock of monorepo', async () => {
|
|
f.prepare('workspace-has-shared-yarn-lock')
|
|
const { allProjects, allProjectsGraph, selectedProjectsGraph } = await filterProjectsBySelectorObjectsFromDir(process.cwd(), [])
|
|
await importCommand.handler({
|
|
...DEFAULT_OPTS,
|
|
allProjects: allProjects as any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
allProjectsGraph,
|
|
selectedProjectsGraph,
|
|
workspaceDir: process.cwd(),
|
|
lockfileDir: process.cwd(),
|
|
dir: process.cwd(),
|
|
resolutionMode: 'highest', // TODO: this should work with the default resolution mode (TODOv8)
|
|
}, [])
|
|
|
|
const project = assertProject(process.cwd())
|
|
const lockfile = project.readLockfile()
|
|
expect(lockfile.packages).toHaveProperty(['is-positive@1.0.0'])
|
|
expect(lockfile.packages).toHaveProperty(['is-negative@1.0.1'])
|
|
|
|
// node_modules is not created
|
|
project.hasNot('is-positive')
|
|
project.hasNot('is-negative')
|
|
})
|
|
|
|
test('import from shared package-lock.json of monorepo', async () => {
|
|
f.prepare('workspace-has-shared-package-lock-json')
|
|
const { allProjects, allProjectsGraph, selectedProjectsGraph } = await filterProjectsBySelectorObjectsFromDir(process.cwd(), [])
|
|
await importCommand.handler({
|
|
...DEFAULT_OPTS,
|
|
allProjects: allProjects as any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
allProjectsGraph,
|
|
selectedProjectsGraph,
|
|
workspaceDir: process.cwd(),
|
|
lockfileDir: process.cwd(),
|
|
dir: process.cwd(),
|
|
resolutionMode: 'highest', // TODO: this should work with the default resolution mode (TODOv8)
|
|
}, [])
|
|
|
|
const project = assertProject(process.cwd())
|
|
const lockfile = project.readLockfile()
|
|
expect(lockfile.packages).toHaveProperty(['is-positive@1.0.0'])
|
|
expect(lockfile.packages).toHaveProperty(['is-negative@1.0.1'])
|
|
|
|
// node_modules is not created
|
|
project.hasNot('is-positive')
|
|
project.hasNot('is-negative')
|
|
})
|
|
|
|
test('import from shared npm-shrinkwrap.json of monorepo', async () => {
|
|
f.prepare('workspace-has-shared-npm-shrinkwrap-json')
|
|
const { allProjects, allProjectsGraph, selectedProjectsGraph } = await filterProjectsBySelectorObjectsFromDir(process.cwd(), [])
|
|
await importCommand.handler({
|
|
...DEFAULT_OPTS,
|
|
allProjects: allProjects as any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
allProjectsGraph,
|
|
selectedProjectsGraph,
|
|
workspaceDir: process.cwd(),
|
|
lockfileDir: process.cwd(),
|
|
dir: process.cwd(),
|
|
resolutionMode: 'highest', // TODO: this should work with the default resolution mode (TODOv8)
|
|
}, [])
|
|
|
|
const project = assertProject(process.cwd())
|
|
const lockfile = project.readLockfile()
|
|
expect(lockfile.packages).toHaveProperty(['is-positive@1.0.0'])
|
|
expect(lockfile.packages).toHaveProperty(['is-negative@1.0.1'])
|
|
|
|
// node_modules is not created
|
|
project.hasNot('is-positive')
|
|
project.hasNot('is-negative')
|
|
})
|