11const t = require ( 'tap' )
2+ const fs = require ( 'fs' )
3+ const os = require ( 'os' )
24const path = require ( 'path' )
35const which = require ( 'which' )
4- const { execSync } = require ( 'child_process' )
6+ const { execSync, spawnSync } = require ( 'child_process' )
57
68const originalDir = process . cwd ( )
9+ const osTempDir = fs . realpathSync ( os . tmpdir ( ) )
710
811const node = path . resolve ( which . sync ( 'node' ) ) // /opt/homebrew/node
912const dotenvx = `${ node } ${ path . join ( originalDir , 'src/cli/dotenvx.js' ) } `
@@ -15,6 +18,19 @@ function execShell (commands) {
1518 } ) . trim ( )
1619}
1720
21+ function runCommand ( command , cwd ) {
22+ const result = spawnSync ( command , {
23+ encoding : 'utf8' ,
24+ shell : true ,
25+ cwd
26+ } )
27+
28+ return {
29+ exitCode : result . status ,
30+ output : `${ result . stdout || '' } ${ result . stderr || '' } ` . trim ( )
31+ }
32+ }
33+
1834t . test ( 'ext' , ct => {
1935 const output = execShell ( `${ dotenvx } ext` )
2036
@@ -42,3 +58,29 @@ t.test('ext vault', ct => {
4258
4359 ct . end ( )
4460} )
61+
62+ t . test ( 'deprecated precommit forwards a string directory to ext action' , ct => {
63+ const tempDir = fs . mkdtempSync ( path . join ( osTempDir , 'dotenvx-ext-precommit-' ) )
64+ fs . writeFileSync ( path . join ( tempDir , '.gitignore' ) , '' )
65+
66+ const result = runCommand ( `${ dotenvx } precommit` , tempDir )
67+
68+ ct . equal ( result . exitCode , 0 , 'precommit exits successfully' )
69+ ct . notMatch ( result . output , / p a t h s \[ 0 \] / , 'does not fail with paths[0] type error' )
70+ ct . match ( result . output , / D E P R E C A T I O N N O T I C E : \[ p r e c o m m i t \] / , 'shows deprecation notice' )
71+
72+ ct . end ( )
73+ } )
74+
75+ t . test ( 'deprecated prebuild forwards a string directory to ext action' , ct => {
76+ const tempDir = fs . mkdtempSync ( path . join ( osTempDir , 'dotenvx-ext-prebuild-' ) )
77+ fs . writeFileSync ( path . join ( tempDir , '.dockerignore' ) , '' )
78+
79+ const result = runCommand ( `${ dotenvx } prebuild` , tempDir )
80+
81+ ct . equal ( result . exitCode , 0 , 'prebuild exits successfully' )
82+ ct . notMatch ( result . output , / p a t h s \[ 0 \] / , 'does not fail with paths[0] type error' )
83+ ct . match ( result . output , / D E P R E C A T I O N N O T I C E : \[ p r e b u i l d \] / , 'shows deprecation notice' )
84+
85+ ct . end ( )
86+ } )
0 commit comments