-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
44 lines (35 loc) · 1.17 KB
/
index.test.js
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
// @ts-check
const fs = require('fs')
const path = require('path')
const assert = require('assert')
const { default: caz, inject } = require('caz')
console.log = () => {}
console.clear = () => {}
process.env.NODE_ENV = 'test'
const temp = path.join(__dirname, 'temp')
const template = path.join(temp, 'source')
fs.mkdirSync(template, { recursive: true })
fs.cpSync(path.join(__dirname, 'package.json'), path.join(template, 'package.json'))
fs.cpSync(path.join(__dirname, 'template'), path.join(template, 'template'), { recursive: true })
const assertGenerated = async (input, output) => {
inject(input)
const project = path.join(temp, input[0])
await caz(template, project, { force: true })
for (const item of output) {
const exists = fs.existsSync(path.join(project, item))
assert.strictEqual(exists, true, `Expected ${item} to exist.`)
}
}
const test = async () => {
// TODO: test with different template or different answers
await assertGenerated(
['minimal'],
['package.json', 'README.md']
)
console.info('\x1b[91m→ minimal passed\x1b[0m')
fs.rmSync(temp, { recursive: true })
}
test().catch(err => {
console.error(err)
process.exit(1)
})