mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-29 00:47:13 -04:00
* chore: upgrade @typescript/native-preview to 7.0.0-dev.20260421.2
- Add explicit `types: ["node"]` to the shared tsconfig because tsgo
20260421 no longer auto-acquires `@types/*` from `node_modules`.
- Refactor test files to explicitly import jest globals (`describe`,
`it`, `test`, `expect`, `beforeEach`, etc.) from `@jest/globals`
instead of relying on `@types/jest` ambient declarations. Under the
new tsgo build, `import { jest } from '@jest/globals'` shadows the
ambient `jest` namespace, breaking `@types/jest`'s `declare var
describe: jest.Describe;` globals.
- Add `@jest/globals` to each package's devDependencies where tests
now import from it, and add `@types/node` to packages that need it
but were relying on hoisted resolution.
- Replace `fail()` calls with `throw new Error(...)` since `fail` is
no longer globally available.
* chore: fix remaining tsgo type-strictness errors
- Strip `as <PnpmType>` casts on objects passed to toMatchObject /
toStrictEqual / toEqual; @jest/globals rejects the typed objects
(which include AsymmetricMatchers) vs. the repo-specific type.
- Type `jest.fn<...>()` explicitly where the mock's signature matters
for toHaveBeenCalledWith.
- Replace `beforeEach(() => X)` with `beforeEach(() => { X })` so the
return value is void, as the stricter jest typing requires.
- Use `expect.objectContaining({...})` in one place where the full
expected object triggered stricter type resolution.
- Cast `prompt.mock.calls` arg through `as unknown as Record<...>[]`
for patch.test.ts's nested-array matchers.
- Fix off-by-one `<reference path>` in pnpm/test/getConfig.test.ts
that only surfaced now.
- Move `@jest/globals` from devDependencies to dependencies in the
two `__utils__` packages that import it from `src/`.
- Clean up unused imports from the @jest/globals migration.
* chore: address Copilot review on #11332
- Move misplaced `@jest/globals` imports to the top import block in
checkEngine, run.ts, and workspace/root-finder tests where the
script dropped them below executable code.
- Replace `try { await x(); throw new Error('should have thrown') } catch`
in bins/linker, lockfile/fs, and resolving/local-resolver tests with
`await expect(x()).rejects.toMatchObject({...})`. The old pattern
swallowed an unrelated `throw` if the under-test call silently
succeeded, which would fail on the catch-block assertion with a
misleading message.
277 lines
7.4 KiB
TypeScript
277 lines
7.4 KiB
TypeScript
import { afterEach, beforeEach, expect, test } from '@jest/globals'
|
|
import { LOCKFILE_VERSION, WANTED_LOCKFILE } from '@pnpm/constants'
|
|
import { addDependenciesToPackage, install } from '@pnpm/installing.deps-installer'
|
|
import { prepareEmpty } from '@pnpm/prepare'
|
|
import { getIntegrity } from '@pnpm/registry-mock'
|
|
import { getMockAgent, setupMockAgent, teardownMockAgent } from '@pnpm/testing.mock-agent'
|
|
import { rimrafSync } from '@zkochan/rimraf'
|
|
import { writeYamlFileSync } from 'write-yaml-file'
|
|
|
|
import { testDefaults } from '../utils/index.js'
|
|
|
|
beforeEach(async () => {
|
|
await setupMockAgent()
|
|
getMockAgent().enableNetConnect()
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await teardownMockAgent()
|
|
})
|
|
|
|
const RESOLUTIONS = [
|
|
{
|
|
targets: [
|
|
{
|
|
os: 'darwin',
|
|
cpu: 'arm64',
|
|
},
|
|
],
|
|
resolution: {
|
|
type: 'binary',
|
|
archive: 'zip',
|
|
url: 'https://github.com/denoland/deno/releases/download/v2.4.2/deno-aarch64-apple-darwin.zip',
|
|
integrity: 'sha256-cy885Q3GSmOXLKTvtIZ5KZwBZjzpGPcQ1pWmjOX0yTY=',
|
|
bin: 'deno',
|
|
},
|
|
},
|
|
{
|
|
targets: [
|
|
{
|
|
os: 'linux',
|
|
cpu: 'arm64',
|
|
},
|
|
],
|
|
resolution: {
|
|
type: 'binary',
|
|
archive: 'zip',
|
|
url: 'https://github.com/denoland/deno/releases/download/v2.4.2/deno-aarch64-unknown-linux-gnu.zip',
|
|
integrity: 'sha256-SjIY48qZ8qu8QdIGkbynlC0Y68sB22tDicu5HqvxBV8=',
|
|
bin: 'deno',
|
|
},
|
|
},
|
|
{
|
|
targets: [
|
|
{
|
|
os: 'darwin',
|
|
cpu: 'x64',
|
|
},
|
|
],
|
|
resolution: {
|
|
type: 'binary',
|
|
archive: 'zip',
|
|
url: 'https://github.com/denoland/deno/releases/download/v2.4.2/deno-x86_64-apple-darwin.zip',
|
|
integrity: 'sha256-+kfrcrjR80maf7Pmx7vNOx5kBxErsD+v1AqoA4pUuT4=',
|
|
bin: 'deno',
|
|
},
|
|
},
|
|
{
|
|
targets: [
|
|
{
|
|
os: 'win32',
|
|
cpu: 'x64',
|
|
},
|
|
{
|
|
os: 'win32',
|
|
cpu: 'arm64',
|
|
},
|
|
],
|
|
resolution: {
|
|
type: 'binary',
|
|
archive: 'zip',
|
|
url: 'https://github.com/denoland/deno/releases/download/v2.4.2/deno-x86_64-pc-windows-msvc.zip',
|
|
integrity: 'sha256-WoyBb25yA3inTCVnZ5uip5nIFbjC/8BrDnHabCqb8Yk=',
|
|
bin: 'deno.exe',
|
|
},
|
|
},
|
|
{
|
|
targets: [
|
|
{
|
|
os: 'linux',
|
|
cpu: 'x64',
|
|
},
|
|
],
|
|
resolution: {
|
|
type: 'binary',
|
|
archive: 'zip',
|
|
url: 'https://github.com/denoland/deno/releases/download/v2.4.2/deno-x86_64-unknown-linux-gnu.zip',
|
|
integrity: 'sha256-2Ed4YzIVt8uTz3aQhg1iQfYysIe9KhneEs1BDmsuFXo=',
|
|
bin: 'deno',
|
|
},
|
|
},
|
|
]
|
|
|
|
const PLATFORM_HEX_DIGESTS = Object.fromEntries(
|
|
RESOLUTIONS.map(({ resolution }) => {
|
|
const platform = resolution.url.match(/deno-(.+)\.zip$/)![1]
|
|
const hex = Buffer.from(resolution.integrity.replace('sha256-', ''), 'base64').toString('hex')
|
|
return [platform, hex]
|
|
})
|
|
)
|
|
|
|
test('installing Deno runtime', async () => {
|
|
// Mock GitHub API to avoid network flakiness
|
|
const assetNames = Object.keys(PLATFORM_HEX_DIGESTS).map((platform) => `deno-${platform}`)
|
|
const githubApiPool = getMockAgent().get('https://api.github.com')
|
|
githubApiPool
|
|
.intercept({ path: '/repos/denoland/deno/releases/tags/v2.4.2', method: 'GET' })
|
|
.reply(200, {
|
|
assets: assetNames.map((name) => ({
|
|
name: `${name}.zip.sha256sum`,
|
|
browser_download_url: `https://github.com/denoland/deno/releases/download/v2.4.2/${name}.zip.sha256sum`,
|
|
})),
|
|
})
|
|
const githubPool = getMockAgent().get('https://github.com')
|
|
for (const [platform, hex] of Object.entries(PLATFORM_HEX_DIGESTS)) {
|
|
const name = `deno-${platform}`
|
|
githubPool
|
|
.intercept({ path: `/denoland/deno/releases/download/v2.4.2/${name}.zip.sha256sum`, method: 'GET' })
|
|
.reply(200, `${hex} ${name}.zip`)
|
|
}
|
|
|
|
const project = prepareEmpty()
|
|
const { updatedManifest: manifest } = await addDependenciesToPackage({}, ['deno@runtime:2.4.2'], testDefaults({ fastUnpack: false }))
|
|
|
|
project.isExecutable('.bin/deno')
|
|
expect(project.readLockfile()).toStrictEqual({
|
|
settings: {
|
|
autoInstallPeers: true,
|
|
excludeLinksFromLockfile: false,
|
|
},
|
|
importers: {
|
|
'.': {
|
|
dependencies: {
|
|
deno: {
|
|
specifier: 'runtime:2.4.2',
|
|
version: 'runtime:2.4.2',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
lockfileVersion: LOCKFILE_VERSION,
|
|
packages: {
|
|
'deno@runtime:2.4.2': {
|
|
hasBin: true,
|
|
resolution: {
|
|
type: 'variations',
|
|
variants: RESOLUTIONS,
|
|
},
|
|
version: '2.4.2',
|
|
},
|
|
},
|
|
snapshots: {
|
|
'deno@runtime:2.4.2': {},
|
|
},
|
|
})
|
|
|
|
rimrafSync('node_modules')
|
|
await install(manifest, testDefaults({ frozenLockfile: true }, {
|
|
offline: true, // We want to verify that Deno is resolved from cache.
|
|
}))
|
|
project.isExecutable('.bin/deno')
|
|
|
|
await addDependenciesToPackage(manifest, ['@pnpm.e2e/dep-of-pkg-with-1-dep@100.1.0'], testDefaults({ fastUnpack: false }))
|
|
project.has('@pnpm.e2e/dep-of-pkg-with-1-dep')
|
|
|
|
expect(project.readLockfile()).toStrictEqual({
|
|
settings: {
|
|
autoInstallPeers: true,
|
|
excludeLinksFromLockfile: false,
|
|
},
|
|
importers: {
|
|
'.': {
|
|
dependencies: {
|
|
deno: {
|
|
specifier: 'runtime:2.4.2',
|
|
version: 'runtime:2.4.2',
|
|
},
|
|
'@pnpm.e2e/dep-of-pkg-with-1-dep': {
|
|
specifier: '100.1.0',
|
|
version: '100.1.0',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
lockfileVersion: LOCKFILE_VERSION,
|
|
packages: {
|
|
'deno@runtime:2.4.2': {
|
|
hasBin: true,
|
|
resolution: {
|
|
type: 'variations',
|
|
variants: RESOLUTIONS,
|
|
},
|
|
version: '2.4.2',
|
|
},
|
|
'@pnpm.e2e/dep-of-pkg-with-1-dep@100.1.0': {
|
|
resolution: {
|
|
integrity: getIntegrity('@pnpm.e2e/dep-of-pkg-with-1-dep', '100.1.0'),
|
|
},
|
|
},
|
|
},
|
|
snapshots: {
|
|
'deno@runtime:2.4.2': {},
|
|
'@pnpm.e2e/dep-of-pkg-with-1-dep@100.1.0': {},
|
|
},
|
|
})
|
|
})
|
|
|
|
test('installing Deno runtime fails if offline mode is used and Deno not found locally', async () => {
|
|
prepareEmpty()
|
|
await expect(
|
|
addDependenciesToPackage({}, ['deno@runtime:2.4.2'], testDefaults({ fastUnpack: false }, { offline: true }))
|
|
).rejects.toThrow(/Failed to resolve deno@2.4.2 in package mirror/)
|
|
})
|
|
|
|
test('installing Deno runtime fails if integrity check fails', async () => {
|
|
prepareEmpty()
|
|
|
|
writeYamlFileSync(WANTED_LOCKFILE, {
|
|
settings: {
|
|
autoInstallPeers: true,
|
|
excludeLinksFromLockfile: false,
|
|
},
|
|
importers: {
|
|
'.': {
|
|
devDependencies: {
|
|
deno: {
|
|
specifier: 'runtime:2.4.2',
|
|
version: 'runtime:2.4.2',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
lockfileVersion: LOCKFILE_VERSION,
|
|
packages: {
|
|
'deno@runtime:2.4.2': {
|
|
hasBin: true,
|
|
resolution: {
|
|
type: 'variations',
|
|
variants: RESOLUTIONS.map((resolutionVariant) => ({
|
|
...resolutionVariant,
|
|
resolution: {
|
|
...resolutionVariant.resolution,
|
|
integrity: 'sha256-0000000000000000000000000000000000000000000=',
|
|
},
|
|
})),
|
|
},
|
|
version: '2.4.2',
|
|
},
|
|
},
|
|
snapshots: {
|
|
'deno@runtime:2.4.2': {},
|
|
},
|
|
}, {
|
|
lineWidth: -1,
|
|
})
|
|
|
|
const manifest = {
|
|
devDependencies: {
|
|
deno: 'runtime:2.4.2',
|
|
},
|
|
}
|
|
await expect(install(manifest, testDefaults({ frozenLockfile: true }, {
|
|
retry: {
|
|
retries: 0,
|
|
},
|
|
}))).rejects.toThrow(/Got unexpected checksum for/)
|
|
})
|