Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: matchCatalogResolveResult test case #8309

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: matchCatalogResolveResult test case
  • Loading branch information
btea committed Jul 14, 2024
commit 2e36f91b6462234ce8aa3191dfef682167083418
47 changes: 46 additions & 1 deletion catalogs/resolver/test/resolveFromCatalog.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type WantedDependency, resolveFromCatalog } from '@pnpm/catalogs.resolver'
import { type WantedDependency, resolveFromCatalog, matchCatalogResolveResult } from '@pnpm/catalogs.resolver'
import { type Catalogs } from '@pnpm/catalogs.types'
import { PnpmError } from '@pnpm/error'

describe('default catalog', () => {
const catalogs = {
Expand Down Expand Up @@ -108,3 +109,47 @@ describe('misconfiguration', () => {
.toThrow("The entry for 'bar' in catalog 'foo' declares a dependency using the 'link' protocol. This is not yet supported, but may be in a future version of pnpm.")
})
})

describe('matchCatalogResolveResult', () => {
test('matches found resolution', () => {
const matcher = {
found: jest.fn(),
misconfiguration: jest.fn(),
unused: jest.fn(),
}
const result = { type: 'found', resolution: { catalogName: 'foo', specifier: '1.0.0' } } as const
matchCatalogResolveResult(result, matcher)

expect(matcher.found).toHaveBeenCalledWith(result)
expect(matcher.misconfiguration).not.toHaveBeenCalled()
expect(matcher.unused).not.toHaveBeenCalled()
})

test('matches misconfiguration', () => {
const matcher = {
found: jest.fn(),
misconfiguration: jest.fn(),
unused: jest.fn(),
}
const result = { type: 'misconfiguration', catalogName: 'foo', error: new PnpmError('test', 'info') } as const
matchCatalogResolveResult(result, matcher)

expect(matcher.found).not.toHaveBeenCalled()
expect(matcher.misconfiguration).toHaveBeenCalledWith(result)
expect(matcher.unused).not.toHaveBeenCalled()
})

test('matches unused', () => {
const matcher = {
found: jest.fn(),
misconfiguration: jest.fn(),
unused: jest.fn(),
}
const result = { type: 'unused' } as const
matchCatalogResolveResult(result, matcher)

expect(matcher.found).not.toHaveBeenCalled()
expect(matcher.misconfiguration).not.toHaveBeenCalled()
expect(matcher.unused).toHaveBeenCalledWith(result)
})
})
Loading