Files
pnpm/pkg-manager/core/test/utils/testDefaults.ts
Brandon Cheng 1a5b5beea2 build: replace ts-jest with simple transformer (#10579)
* test: use `import type` in more places

Several tests are failing because a module isn't being mocked. This is
due to the mocked module being imported before the mock being set up.

Switching to `import type` should elide the import fully.

* build: replace ts-jest with simple transformer

* chore: remove `ts-jest`

* chore: remove babel dependencies from root project

* ci: use Node.js 22.13.0 (instead of 22.12.0)

Node.js 22.13.0 introduces the `stripTypeScriptTypes` function

* fix: copilot feedback
2026-02-09 11:35:22 +01:00

59 lines
1.4 KiB
TypeScript

import { createTempStore } from '@pnpm/testing.temp-store'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import type { StoreController } from '@pnpm/store-controller-types'
import type { Registries } from '@pnpm/types'
import type { InstallOptions } from '@pnpm/core'
import type { CustomResolver } from '@pnpm/hooks.types'
const registry = `http://localhost:${REGISTRY_MOCK_PORT}/`
export function testDefaults<T> (
opts?: T & {
fastUnpack?: boolean
storeDir?: string
prefix?: string
registries?: Registries
customResolvers?: CustomResolver[]
},
resolveOpts?: any, // eslint-disable-line
fetchOpts?: any, // eslint-disable-line
storeOpts?: any // eslint-disable-line
): InstallOptions &
{
cacheDir: string
registries: Registries
storeController: StoreController
storeDir: string
} &
T {
const { storeController, storeDir, cacheDir } = createTempStore({
...opts,
clientOptions: {
...(opts?.registries != null ? { registries: opts.registries } : {}),
customResolvers: opts?.customResolvers,
...resolveOpts,
...fetchOpts,
},
storeOptions: storeOpts,
})
const result = {
cacheDir,
registries: {
default: registry,
},
storeController,
storeDir,
...opts,
} as (
InstallOptions &
{
cacheDir: string
registries: Registries
storeController: StoreController
storeDir: string
} &
T
)
return result
}