From 201d88eeeee4342cdfd749ced7d88e45e5e0888f Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 9 Sep 2024 19:00:49 +0800 Subject: [PATCH] test: matchCatalogResolveResult test case (#8309) --- .../resolver/test/resolveFromCatalog.test.ts | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/catalogs/resolver/test/resolveFromCatalog.test.ts b/catalogs/resolver/test/resolveFromCatalog.test.ts index e9fbd66d42..91274f16fa 100644 --- a/catalogs/resolver/test/resolveFromCatalog.test.ts +++ b/catalogs/resolver/test/resolveFromCatalog.test.ts @@ -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 = { @@ -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) + }) +})