From 42a73b4eedfc493279bb2cfce32958114e3d04bc Mon Sep 17 00:00:00 2001 From: Raine Revere Date: Sat, 24 Jun 2023 14:33:46 +0000 Subject: [PATCH] DEBUG --- test/helpers/stubNpmView.ts | 12 ++++++++++-- test/workspaces.test.ts | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test/helpers/stubNpmView.ts b/test/helpers/stubNpmView.ts index dd56dd94..33b4d103 100644 --- a/test/helpers/stubNpmView.ts +++ b/test/helpers/stubNpmView.ts @@ -4,14 +4,22 @@ import { MockedVersions } from '../../src/types/MockedVersions' /** Stubs the npmView function from package-managers/npm. Returns the stub object. Call stub.restore() after assertions to restore the original function. Set spawn:true to stub ncu spawned as a child process. */ const stubNpmView = (mockReturnedVersions: MockedVersions, { spawn }: { spawn?: boolean } = {}) => { + if (spawn) { + console.log('stubNpmView', mockReturnedVersions) + console.trace() + if (process.env.STUB_NPM_VIEW) { + throw new Error('STUB_NPM_VIEW already set. Did you forget to call restore during test cleanup?') + } + } + // stub child process // the only way to stub functionality in spawned child processes is to pass data through process.env and stub internally if (spawn) { process.env.STUB_NPM_VIEW = JSON.stringify(mockReturnedVersions) return { restore: () => { - // eslint-disable-next-line fp/no-delete - delete process.env.STUB_NPM_VIEW + console.log('stubNpmView: restore') + process.env.STUB_NPM_VIEW = '' }, } } diff --git a/test/workspaces.test.ts b/test/workspaces.test.ts index 5afcc802..420493c5 100644 --- a/test/workspaces.test.ts +++ b/test/workspaces.test.ts @@ -449,7 +449,8 @@ describe('stubbed', () => { // TODO: Move npm config reading to init method describe('not stubbed', () => { // TODO: Find a less fragile way to test npm config than comparing exact verbose output - it('merge local npm config with pnpm workspace npm config', async () => { + it.only('merge local npm config with pnpm workspace npm config', async () => { + console.log('STUB_NPM_VIEW', process.env.STUB_NPM_VIEW) const tempDir = await setup(['packages/**'], { pnpm: true }) try { await fs.writeFile(path.join(tempDir, '.npmrc'), 'ncutest=root')