1+ import fs from 'node:fs/promises' ;
2+ import path from 'node:path' ;
13import test from 'ava' ;
24import { shellEnv , shellEnvSync } from './index.js' ;
35
@@ -17,6 +19,32 @@ test('sync', t => {
1719 t . is ( env . ZSH_TMUX_AUTOSTART , 'false' ) ;
1820} ) ;
1921
22+ test ( 'sync - ignores env alias' , async t => {
23+ const temporaryDirectoryPrefix = path . join ( process . cwd ( ) , 'temporary-shell-env-' ) ;
24+ const temporaryDirectory = await fs . mkdtemp ( temporaryDirectoryPrefix ) ;
25+
26+ try {
27+ const bashConfigurationPath = path . join ( temporaryDirectory , '.bashrc' ) ;
28+ const bashWrapperPath = path . join ( temporaryDirectory , 'bash-wrapper.sh' ) ;
29+ const bashWrapperContents = [
30+ '#!/bin/sh' ,
31+ `HOME="${ temporaryDirectory } "` ,
32+ 'export HOME' ,
33+ 'exec /bin/bash "$@"' ,
34+ '' ,
35+ ] . join ( '\n' ) ;
36+
37+ await fs . writeFile ( bashConfigurationPath , 'alias env="printf no"\n' ) ;
38+ await fs . writeFile ( bashWrapperPath , bashWrapperContents ) ;
39+ await fs . chmod ( bashWrapperPath , 0o755 ) ;
40+
41+ const env = shellEnvSync ( bashWrapperPath ) ;
42+ t . is ( env . HOME , temporaryDirectory ) ;
43+ } finally {
44+ await fs . rm ( temporaryDirectory , { recursive : true , force : true } ) ;
45+ }
46+ } ) ;
47+
2048test ( 'async - with custom shell' , async t => {
2149 const shell = '/bin/bash' ;
2250 const env = await shellEnv ( shell ) ;
0 commit comments