diff --git a/README.md b/README.md index 73791dc..b5e3fbd 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ See the [V4 Migration Guide](./MIGRATION.md) if you are migrating from v3 or old - `print` - Print everything that goes to stdout and stderr. - `stripAnsi` - Strip ansi codes from everything that goes to stdout and stderr. Defaults to true. +- `testNodeEnv` - Sets the `NODE_ENV` value when capturing output. Defaults to `'test'`. See the [tests](./test/capture-output.test.ts) for example usage. diff --git a/src/index.ts b/src/index.ts index 8ae63e6..66da1d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ const debug = makeDebug('oclif-test') type CaptureOptions = { print?: boolean stripAnsi?: boolean + testNodeEnv?: string } type CaptureResult = { @@ -77,6 +78,7 @@ function splitString(str: string): string[] { export async function captureOutput(fn: () => Promise, opts?: CaptureOptions): Promise> { const print = opts?.print ?? false const stripAnsi = opts?.stripAnsi ?? true + const testNodeEnv = opts?.testNodeEnv || 'test' const originals = { NODE_ENV: process.env.NODE_ENV, @@ -112,7 +114,7 @@ export async function captureOutput(fn: () => Promise, opts?: Captur process.stdout.write = mock('stdout') process.stderr.write = mock('stderr') - process.env.NODE_ENV = 'test' + process.env.NODE_ENV = testNodeEnv try { const result = await fn()