Skip to content

Commit

Permalink
fix: set node env
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed May 15, 2024
1 parent f03be3f commit f6eb5e3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const RECORD_OPTIONS: CaptureOptions = {
}

const originals = {
NODE_ENV: process.env.NODE_ENV,
stderr: process.stderr.write,
stdout: process.stdout.write,
}
Expand Down Expand Up @@ -61,6 +62,7 @@ function mockedStderr(
const restore = (): void => {
process.stderr.write = originals.stderr
process.stdout.write = originals.stdout
process.env.NODE_ENV = originals.NODE_ENV
}

const reset = (): void => {
Expand Down Expand Up @@ -113,6 +115,7 @@ export async function captureOutput<T>(
RECORD_OPTIONS.stripAnsi = opts?.stripAnsi ?? true
process.stderr.write = mockedStderr
process.stdout.write = mockedStdout
process.env.NODE_ENV = 'test'

try {
const result = await fn()
Expand Down Expand Up @@ -150,7 +153,7 @@ export async function runCommand<T>(
const [id, ...rest] = argsArray
const finalArgs = id === '.' ? rest : argsArray

debug('loadOpts: %O', loadOpts)
debug('loadOpts: %O', loadOptions)
debug('args: %O', finalArgs)

return captureOutput<T>(async () => run(finalArgs, loadOptions), captureOpts)
Expand All @@ -169,7 +172,7 @@ export async function runHook<T>(
}> {
const loadOptions = makeLoadOptions(loadOpts)

debug('loadOpts: %O', loadOpts)
debug('loadOpts: %O', loadOptions)

return captureOutput<T>(async () => {
const config = await Config.load(loadOptions)
Expand Down

0 comments on commit f6eb5e3

Please sign in to comment.