env.js
This file
Path
test/arguments/env.js
32 lines · 1.2 KiB · JavaScript
Last changed by
Upgrade xo (#980)ehmickybefore adoptionccfa412
History of this fileTake it
Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 1–3why, one step back1import process from 'node:process';2import test from 'ava';3import {execa} from '../../index.js';Upgrade xo (#980)ehmickybefore adoptionccfa412
line 4why, one step back4import {setFixtureDirectory, PATH_KEY} from '../helpers/fixtures-directory.js';Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
line 5why, one step back5Upgrade xo (#980)ehmickybefore adoptionccfa412
line 6why, one step back6setFixtureDirectory();Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 7–32why, one step back7process.env.FOO = 'foo';89const isWindows = process.platform === 'win32';1011test('use environment variables by default', async t => {12 const {stdout} = await execa('environment.js');13 t.deepEqual(stdout.split('\n'), ['foo', 'undefined']);14});1516test('extend environment variables by default', async t => {17 const {stdout} = await execa('environment.js', [], {env: {BAR: 'bar', [PATH_KEY]: process.env[PATH_KEY]}});18 t.deepEqual(stdout.split('\n'), ['foo', 'bar']);19});2021test('do not extend environment with `extendEnv: false`', async t => {22 const {stdout} = await execa('environment.js', [], {env: {BAR: 'bar', [PATH_KEY]: process.env[PATH_KEY]}, extendEnv: false});23 t.deepEqual(stdout.split('\n'), ['undefined', 'bar']);24});2526test('use extend environment with `extendEnv: true` and `shell: true`', async t => {27 process.env.TEST = 'test';28 const command = isWindows ? 'echo %TEST%' : 'echo $TEST';29 const {stdout} = await execa(command, {shell: true, env: {}, extendEnv: true});30 t.is(stdout, 'test');31 delete process.env.TEST;32});