-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.test.js
More file actions
46 lines (41 loc) · 1.43 KB
/
cli.test.js
File metadata and controls
46 lines (41 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict'
const { spawnSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const os = require('os')
const test = require('ava')
const pkg = require('./package.json')
const cli = path.join(__dirname, 'cli.js')
test('prints version for --version and -v', t => {
for (const flag of ['--version', '-v']) {
const r = spawnSync(process.execPath, [cli, flag], { encoding: 'utf8' })
t.is(r.status, 0, flag)
t.is(r.stdout.trim(), pkg.version, flag)
}
})
test('prints help for --help and -h', t => {
for (const flag of ['--help', '-h']) {
const r = spawnSync(process.execPath, [cli, flag], { encoding: 'utf8' })
t.is(r.status, 0, flag)
t.true(r.stdout.includes('Usage:'), flag)
t.true(r.stdout.includes('htmlcompile'), flag)
}
})
test('exits with error when run without arguments', t => {
const r = spawnSync(process.execPath, [cli], { encoding: 'utf8' })
t.is(r.status, 1)
})
test('compiles when given input and output dirs', t => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'htmlcompile-cli-'))
const out = path.join(dir, 'dist')
fs.mkdirSync(out)
fs.writeFileSync(path.join(dir, 'a.ejs'), '<p><%= 1 %></p>')
const r = spawnSync(process.execPath, [cli, dir, out], {
encoding: 'utf8',
timeout: 120000,
})
t.is(r.status, 0, r.stderr || r.stdout)
const files = fs.readdirSync(out)
t.true(files.length > 0)
fs.rmSync(dir, { recursive: true, force: true })
})