@@ -62,10 +62,18 @@ async function runWithConcurrencyLimit(
6262 }
6363}
6464
65+ function expandHome ( p : string ) : string {
66+ return p . startsWith ( '~' ) ? path . join ( homedir ( ) , p . slice ( 1 ) ) : p ;
67+ }
68+
6569export async function snapTest ( ) {
66- const { positionals } = parseArgs ( {
70+ const { positionals, values } = parseArgs ( {
6771 allowPositionals : true ,
6872 args : process . argv . slice ( 3 ) ,
73+ options : {
74+ dir : { type : 'string' } ,
75+ 'bin-dir' : { type : 'string' } ,
76+ } ,
6977 } ) ;
7078
7179 const filter = positionals [ 0 ] ?? '' ; // Optional filter to run specific test cases
@@ -115,15 +123,15 @@ export async function snapTest() {
115123 // Clean up the temporary directory on exit
116124 process . on ( 'exit' , ( ) => fs . rmSync ( tempTmpDir , { recursive : true , force : true } ) ) ;
117125
118- const casesDir = path . resolve ( process . env . SNAP_TEST_DIR || 'snap-tests' ) ;
126+ const casesDir = path . resolve ( values . dir || 'snap-tests' ) ;
119127
120128 const taskFunctions : ( ( ) => Promise < void > ) [ ] = [ ] ;
121129 for ( const caseName of fs . readdirSync ( casesDir ) ) {
122130 if ( caseName . startsWith ( '.' ) ) {
123131 continue ;
124132 } // Skip hidden files like .DS_Store
125133 if ( caseName . includes ( filter ) ) {
126- taskFunctions . push ( ( ) => runTestCase ( caseName , tempTmpDir , casesDir ) ) ;
134+ taskFunctions . push ( ( ) => runTestCase ( caseName , tempTmpDir , casesDir , values [ 'bin-dir' ] ) ) ;
127135 }
128136 }
129137
@@ -165,7 +173,7 @@ interface Steps {
165173 after ?: string [ ] ;
166174}
167175
168- async function runTestCase ( name : string , tempTmpDir : string , casesDir : string ) {
176+ async function runTestCase ( name : string , tempTmpDir : string , casesDir : string , binDir ?: string ) {
169177 const steps : Steps = JSON . parse (
170178 await fsPromises . readFile ( `${ casesDir } /${ name } /steps.json` , 'utf-8' ) ,
171179 ) ;
@@ -210,9 +218,9 @@ async function runTestCase(name: string, tempTmpDir: string, casesDir: string) {
210218 }
211219 env [ 'PATH' ] = [
212220 // Extend PATH to include the package's bin directory
213- // SNAP_TEST_BIN_DIR overrides the default for cases like global CLI tests
221+ // --bin-dir overrides the default for cases like global CLI tests
214222 // where vp should resolve to the Rust binary instead of the Node.js script
215- path . resolve ( process . env . SNAP_TEST_BIN_DIR || 'bin' ) ,
223+ path . resolve ( expandHome ( binDir || 'bin' ) ) ,
216224 ...env [ 'PATH' ] . split ( path . delimiter ) ,
217225 ] . join ( path . delimiter ) ;
218226
0 commit comments