From c7a339c53a09caf1d6ed28f6e6e3c6e25eb26fec Mon Sep 17 00:00:00 2001 From: Raine Revere Date: Fri, 23 Jun 2023 23:34:12 +0000 Subject: [PATCH] rc-config: Add before/after to describe block. Related to the workspaces test failure on Node v20 on Github Actions. --- src/package-managers/npm.ts | 2 +- test/helpers/stubNpmView.ts | 3 +-- test/rc-config.test.ts | 9 +++++---- test/workspaces.test.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/package-managers/npm.ts b/src/package-managers/npm.ts index 7b003ec4..6f6cc3b5 100644 --- a/src/package-managers/npm.ts +++ b/src/package-managers/npm.ts @@ -388,7 +388,7 @@ async function viewMany( } if (npmConfigProject && Object.keys(npmConfigProject).length > 0) { - print(options, `\npm config (project: ${npmConfigProjectPath}):`, 'verbose') + print(options, `\nnpm config (project: ${npmConfigProjectPath}):`, 'verbose') print(options, omit(npmConfigProject, 'cache'), 'verbose') } diff --git a/test/helpers/stubNpmView.ts b/test/helpers/stubNpmView.ts index dd56dd94..569db341 100644 --- a/test/helpers/stubNpmView.ts +++ b/test/helpers/stubNpmView.ts @@ -10,8 +10,7 @@ const stubNpmView = (mockReturnedVersions: MockedVersions, { spawn }: { spawn?: process.env.STUB_NPM_VIEW = JSON.stringify(mockReturnedVersions) return { restore: () => { - // eslint-disable-next-line fp/no-delete - delete process.env.STUB_NPM_VIEW + process.env.STUB_NPM_VIEW = '' }, } } diff --git a/test/rc-config.test.ts b/test/rc-config.test.ts index 756beb9d..75409a4f 100644 --- a/test/rc-config.test.ts +++ b/test/rc-config.test.ts @@ -15,11 +15,12 @@ process.env.NCU_TESTS = 'true' const bin = path.join(__dirname, '../build/src/bin/cli.js') -let stub: { restore: () => void } -before(() => (stub = stubNpmView('99.9.9', { spawn: true }))) -after(() => stub.restore()) - describe('rc-config', () => { + // before/after must be placed within the describe block, otherwise they will apply to tests in other files + let stub: { restore: () => void } + before(() => (stub = stubNpmView('99.9.9', { spawn: true }))) + after(() => stub.restore()) + it('print rcConfigPath when there is a non-empty rc config file', async () => { const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-')) const tempConfigFile = path.join(tempDir, '.ncurc.json') diff --git a/test/workspaces.test.ts b/test/workspaces.test.ts index 8043bd7b..5afcc802 100644 --- a/test/workspaces.test.ts +++ b/test/workspaces.test.ts @@ -429,7 +429,7 @@ describe('stubbed', () => { }) describe('pnpm', () => { - it('read packages from pnpm-workspaces.yaml', async () => { + it('read packages from pnpm-workspace.yaml', async () => { const tempDir = await setup(['packages/**'], { pnpm: true }) try { const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse)