From 1b1d984eec2cffda3d923190ebdc393889c49ca3 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sun, 18 Jan 2026 19:33:34 +0100 Subject: [PATCH] test: improve publish test isolation --- .../test/publish.ts | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/releasing/plugin-commands-publishing/test/publish.ts b/releasing/plugin-commands-publishing/test/publish.ts index fa62423c4c..bfa6a221d8 100644 --- a/releasing/plugin-commands-publishing/test/publish.ts +++ b/releasing/plugin-commands-publishing/test/publish.ts @@ -1,5 +1,6 @@ import fs from 'fs' import path from 'path' +import { temporaryDirectory } from 'tempy' import execa from 'execa' import { isCI } from 'ci-info' import isWindows from 'is-windows' @@ -126,16 +127,23 @@ skipOnWindowsCI('pack packages with workspace LICENSE if no own LICENSE is prese workspaceDir, }) - process.chdir('../target') + // Create a target directory outside the workspace to avoid workspace interference + const externalTarget = temporaryDirectory() + fs.writeFileSync(path.join(externalTarget, 'package.json'), JSON.stringify({ name: 'target', version: '1.0.0' })) - crossSpawn.sync(pnpmBin, ['add', '../project-1/project-1-1.0.0.tgz', '../project-2/project-2-1.0.0.tgz']) + // Get absolute paths to tarballs (relative to workspaceDir) + const tarball1 = path.join(workspaceDir, 'project-1/project-1-1.0.0.tgz') + const tarball2 = path.join(workspaceDir, 'project-2/project-2-1.0.0.tgz') + + process.chdir(externalTarget) + crossSpawn.sync(pnpmBin, ['add', tarball1, tarball2]) expect(fs.existsSync('node_modules/project-1/LICENSE')).toBeTruthy() expect(fs.readFileSync('node_modules/project-1/LICENSE', 'utf8')).toBe('workspace license') expect(fs.existsSync('node_modules/project-2/LICENSE')).toBeTruthy() expect(fs.readFileSync('node_modules/project-2/LICENSE', 'utf8')).toBe('project-2 license') - process.chdir('..') + process.chdir(workspaceDir) expect(fs.existsSync('project-1/LICENSE')).toBeFalsy() expect(fs.existsSync('project-2/LICENSE')).toBeTruthy() }) @@ -177,14 +185,17 @@ test('publish packages with workspace LICENSE if no own LICENSE is present', asy workspaceDir, }, []) - process.chdir('../target') + // Create a target directory outside the workspace to avoid workspace interference + const externalTarget = temporaryDirectory() + fs.writeFileSync(path.join(externalTarget, 'package.json'), JSON.stringify({ name: 'target', version: '1.0.0' })) - crossSpawn.sync(pnpmBin, ['add', 'project-100', 'project-200', '--no-link-workspace-packages', `--registry=http://localhost:${REGISTRY_MOCK_PORT}`]) + process.chdir(externalTarget) + crossSpawn.sync(pnpmBin, ['add', 'project-100', 'project-200', `--registry=http://localhost:${REGISTRY_MOCK_PORT}`]) expect(fs.readFileSync('node_modules/project-100/LICENSE', 'utf8')).toBe('workspace license') expect(fs.readFileSync('node_modules/project-200/LICENSE', 'utf8')).toBe('project-200 license') - process.chdir('..') + process.chdir(workspaceDir) expect(fs.existsSync('project-100/LICENSE')).toBeFalsy() expect(fs.existsSync('project-200/LICENSE')).toBeTruthy() })