mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-21 21:22:26 -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.
385 lines
7.4 KiB
TypeScript
385 lines
7.4 KiB
TypeScript
import { expect, test } from '@jest/globals'
|
|
|
|
import { graphSequencer } from '../src/index.js'
|
|
|
|
test('graph with three independent self-cycles', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['a']],
|
|
['b', ['b']],
|
|
['c', ['c']],
|
|
]
|
|
))).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['a', 'b', 'c']],
|
|
cycles: [
|
|
['a'], ['b'], ['c'],
|
|
],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with self-cycle. Sequencing a subgraph', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['a']],
|
|
['b', ['b']],
|
|
['c', ['c']],
|
|
|
|
]), ['a', 'b'])).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['a', 'b']],
|
|
cycles: [['a'], ['b']],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with two self-cycles and an edge linking them', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b', 'c']],
|
|
['b', ['b']],
|
|
['c', ['b', 'c']]]
|
|
))).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['b', 'c'], ['a']],
|
|
cycles: [
|
|
['b'], ['c'],
|
|
],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with nodes connected to each other sequentially without forming a cycle', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b', 'c']],
|
|
['b', []],
|
|
['c', ['b']]]
|
|
))).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['b'], ['c'], ['a']],
|
|
cycles: [],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph sequencing with a subset of 3 nodes, ignoring 2 nodes, in a 5-node graph', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b', 'c']],
|
|
['b', []],
|
|
['c', []],
|
|
['d', ['a']],
|
|
['e', ['a', 'b', 'c']]]
|
|
), ['a', 'd', 'e'])).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['a'], ['d', 'e']],
|
|
cycles: [],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with no edges', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', []],
|
|
['b', []],
|
|
['c', []],
|
|
['d', []],
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['a', 'b', 'c', 'd']],
|
|
cycles: [],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph of isolated nodes with no edges, sequencing a subgraph of selected nodes', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', []],
|
|
['b', []],
|
|
['c', []],
|
|
['d', []],
|
|
]), ['a', 'b', 'c'])).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['a', 'b', 'c']],
|
|
cycles: [],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with multiple dependencies on one item', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['d']],
|
|
['b', ['d']],
|
|
['c', []],
|
|
['d', []],
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['c', 'd'], ['a', 'b']],
|
|
cycles: [],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with resolved cycle', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b']],
|
|
['b', ['c']],
|
|
['c', ['d']],
|
|
['d', ['a']],
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: false,
|
|
chunks: [['a', 'b', 'c', 'd']],
|
|
cycles: [['a', 'b', 'c', 'd']],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with a cycle, but sequencing a subgraph that avoids the cycle', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b']],
|
|
['b', ['c']],
|
|
['c', ['d']],
|
|
['d', ['a']],
|
|
]), ['a', 'b', 'c'])).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['c'], ['b'], ['a']],
|
|
cycles: [],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with resolved cycle with multiple unblocked deps', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['d']],
|
|
['b', ['d']],
|
|
['c', ['d']],
|
|
['d', ['a']],
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: false,
|
|
chunks: [
|
|
['a', 'd'],
|
|
['b', 'c'],
|
|
],
|
|
cycles: [['a', 'd']],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with resolved cycle with multiple unblocked deps subgraph', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['d']],
|
|
['b', ['d']],
|
|
['c', ['d']],
|
|
['d', ['a']],
|
|
]), ['a', 'b', 'c'])).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [
|
|
['a', 'b', 'c'],
|
|
],
|
|
cycles: [],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with two cycles', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b']],
|
|
['b', ['a']],
|
|
['c', ['d']],
|
|
['d', ['c']],
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: false,
|
|
chunks: [['a', 'b', 'c', 'd']],
|
|
cycles: [
|
|
['a', 'b'],
|
|
['c', 'd'],
|
|
],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with multiple cycles. case 1', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['c']],
|
|
['b', ['a', 'd']],
|
|
['c', ['b']],
|
|
['d', ['c', 'e']],
|
|
['e', []],
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: false,
|
|
chunks: [['e'], ['a', 'c', 'b'], ['d']],
|
|
cycles: [['a', 'c', 'b']],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with multiple cycles. case 2', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b']],
|
|
['b', ['d']],
|
|
['c', []],
|
|
['d', ['b', 'c']],
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: false,
|
|
chunks: [['c'], ['b', 'd'], ['a']],
|
|
cycles: [['b', 'd']],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with fully connected subgraph and additional connected node', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b', 'c', 'd']],
|
|
['b', ['a', 'c', 'd']],
|
|
['c', ['a', 'b', 'd']],
|
|
['d', ['a', 'b', 'c']],
|
|
['e', ['b']],
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: false,
|
|
chunks: [['a', 'b', 'c', 'd'], ['e']],
|
|
cycles: [
|
|
['a', 'b'],
|
|
['c', 'd'],
|
|
],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with fully connected subgraph. case 1', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b', 'c', 'd']],
|
|
['b', ['a', 'c', 'd']],
|
|
['c', ['a', 'b', 'd']],
|
|
['d', ['a', 'b', 'c']],
|
|
['e', ['b']],
|
|
]), ['b', 'e'])).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['b'], ['e']],
|
|
cycles: [],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with fully connected subgraph. case 2', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b', 'c', 'd']],
|
|
['b', ['a', 'c', 'd']],
|
|
['c', ['a', 'b', 'd']],
|
|
['d', ['a', 'b', 'c']],
|
|
['e', ['b']],
|
|
]), ['a', 'b', 'e'])).toStrictEqual(
|
|
{
|
|
safe: false,
|
|
chunks: [['a', 'b'], ['e']],
|
|
cycles: [['a', 'b']],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with two self-cycles', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b', 'c']],
|
|
['b', ['b']],
|
|
['c', ['c']],
|
|
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['b', 'c'], ['a']],
|
|
cycles: [['b'], ['c']],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with two self-cycles. Sequencing a subgraph', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b', 'c']],
|
|
['b', ['b']],
|
|
['c', ['c']],
|
|
|
|
]), ['b', 'c'])).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['b', 'c']],
|
|
cycles: [['b'], ['c']],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with many nodes', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b', 'c']],
|
|
['b', []],
|
|
['c', []],
|
|
['d', ['a']],
|
|
['e', ['a', 'b', 'c']],
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['b', 'c'], ['a'], ['d', 'e']],
|
|
cycles: [],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with many nodes. Sequencing a subgraph', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b', 'c']],
|
|
['b', []],
|
|
['c', []],
|
|
['d', ['a']],
|
|
['e', ['a', 'b', 'c']],
|
|
]), ['a', 'd', 'e'])).toStrictEqual(
|
|
{
|
|
safe: true,
|
|
chunks: [['a'], ['d', 'e']],
|
|
cycles: [],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with big cycle', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b']],
|
|
['b', ['a', 'c']],
|
|
['c', ['a', 'b']],
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: false,
|
|
chunks: [['a', 'b', 'c']],
|
|
cycles: [['a', 'b', 'c']],
|
|
}
|
|
)
|
|
})
|
|
|
|
test('graph with three cycles', () => {
|
|
expect(graphSequencer(new Map([
|
|
['a', ['b']],
|
|
['b', ['a', 'c']],
|
|
['c', ['a', 'b']],
|
|
['e', ['f']],
|
|
['f', ['e']],
|
|
['g', ['g']],
|
|
]))).toStrictEqual(
|
|
{
|
|
safe: false,
|
|
chunks: [['a', 'b', 'c', 'e', 'f', 'g']],
|
|
cycles: [['a', 'b', 'c'], ['e', 'f'], ['g']],
|
|
}
|
|
)
|
|
})
|