Skip to content

Commit

Permalink
DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Jun 24, 2023
1 parent 63e564c commit 42a73b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions test/helpers/stubNpmView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/workspaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 42a73b4

Please sign in to comment.