Skip to content

Commit 19f9d19

Browse files
committed
add test case
1 parent 0e0e31c commit 19f9d19

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

tests/e2e/ext.test.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
const t = require('tap')
2+
const fs = require('fs')
3+
const os = require('os')
24
const path = require('path')
35
const which = require('which')
4-
const { execSync } = require('child_process')
6+
const { execSync, spawnSync } = require('child_process')
57

68
const originalDir = process.cwd()
9+
const osTempDir = fs.realpathSync(os.tmpdir())
710

811
const node = path.resolve(which.sync('node')) // /opt/homebrew/node
912
const 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+
1834
t.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, /paths\[0\]/, 'does not fail with paths[0] type error')
70+
ct.match(result.output, /DEPRECATION NOTICE: \[precommit\]/, '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, /paths\[0\]/, 'does not fail with paths[0] type error')
83+
ct.match(result.output, /DEPRECATION NOTICE: \[prebuild\]/, 'shows deprecation notice')
84+
85+
ct.end()
86+
})

0 commit comments

Comments
 (0)