From b93a1f2bc23dad6270d5389ba7c576fc7a382ec9 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Thu, 11 Jul 2024 23:57:12 -0400 Subject: [PATCH] test: add test for pnpm deploy when using catalogs --- .../test/deploy.test.ts | 50 +++++++++++++++++++ .../test/deployCatalogHook.ts | 33 ++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 releasing/plugin-commands-deploy/test/deployCatalogHook.ts diff --git a/releasing/plugin-commands-deploy/test/deploy.test.ts b/releasing/plugin-commands-deploy/test/deploy.test.ts index 37adfaa2901..15378613dd2 100644 --- a/releasing/plugin-commands-deploy/test/deploy.test.ts +++ b/releasing/plugin-commands-deploy/test/deploy.test.ts @@ -213,3 +213,53 @@ test('deploy with dedupePeerDependents=true ignores the value of dedupePeerDepen project.has('is-positive') expect(fs.existsSync('sub-dir/deploy')).toBe(false) }) + +// Regresion test for https://github.com/pnpm/pnpm/issues/8297 (pnpm deploy doesn't replace catalog: protocol) +test('deploy works when workspace packages use catalog protocol', async () => { + preparePackages([ + { + name: 'project-1', + dependencies: { + 'project-2': 'workspace:*', + 'is-positive': 'catalog:', + }, + }, + { + name: 'project-2', + dependencies: { + 'project-3': 'workspace:*', + 'is-positive': 'catalog:', + }, + }, + { + name: 'project-3', + dependencies: { + 'project-3': 'workspace:*', + 'is-positive': 'catalog:', + }, + }, + ]) + + const { allProjects, selectedProjectsGraph } = await filterPackagesFromDir(process.cwd(), [{ namePattern: 'project-1' }]) + + await deploy.handler({ + ...DEFAULT_OPTS, + allProjects, + catalogs: { + default: { + 'is-positive': '1.0.0', + }, + }, + dir: process.cwd(), + dev: false, + production: true, + recursive: true, + selectedProjectsGraph, + sharedWorkspaceLockfile: true, + lockfileDir: process.cwd(), + workspaceDir: process.cwd(), + }, ['deploy']) + + // Make sure the is-postive cataloged dependency was actually installed. + expect(fs.existsSync('deploy/node_modules/.pnpm/project-3@file+project-3/node_modules/is-positive')).toBeTruthy() +}) diff --git a/releasing/plugin-commands-deploy/test/deployCatalogHook.ts b/releasing/plugin-commands-deploy/test/deployCatalogHook.ts new file mode 100644 index 00000000000..aab267644b5 --- /dev/null +++ b/releasing/plugin-commands-deploy/test/deployCatalogHook.ts @@ -0,0 +1,33 @@ +import { deployCatalogHook } from '../src/deployCatalogHook' + +test('deployCatalogHook()', () => { + const catalogs = { + default: { + a: '^1.0.0', + b: '^2.0.0', + c: '^3.0.0', + }, + } + + expect(deployCatalogHook(catalogs, { + dependencies: { + a: 'catalog:', + }, + devDependencies: { + b: 'catalog:foo', + }, + optionalDependencies: { + c: 'catalog:bar', + }, + })).toStrictEqual({ + dependencies: { + a: '^1.0.0', + }, + devDependencies: { + b: '^2.0.0', + }, + optionalDependencies: { + c: '^3.0.0', + }, + }) +})