-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
38 lines (33 loc) · 1.49 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
const fs = require('fs')
const { join } = require('path')
const { default: caz, inject } = require('caz')
const temp = join(__dirname, 'temp')
const template = join(temp, 'src')
beforeAll(async () => {
jest.spyOn(console, 'log').mockImplementation()
jest.spyOn(console, 'clear').mockImplementation()
await fs.promises.mkdir(template, { recursive: true })
await fs.promises.cp(join(__dirname, 'index.js'), join(template, 'index.js'))
await fs.promises.cp(join(__dirname, 'package.json'), join(template, 'package.json'))
await fs.promises.cp(join(__dirname, 'template'), join(template, 'template'), { recursive: true })
})
test('minimal', async () => {
inject(['minimal', '0.1.0', 'minimal template', 'zce', 'w@zce.me', 'https://zce.me', 'zce', false, 'npm'])
const project = join(temp, 'minimal')
await caz(template, project, { force: true })
expect(fs.existsSync(project)).toBe(true)
expect(fs.existsSync(join(project, '.git'))).toBe(true)
expect(fs.existsSync(join(project, 'README.md'))).toBe(true)
})
test('maximal', async () => {
inject(['maximal', '0.1.0', 'maximal template', 'zce', 'w@zce.me', 'https://zce.me', 'zce', false, 'npm'])
const project = join(temp, 'maximal')
await caz(template, project, { force: true })
expect(fs.existsSync(project)).toBe(true)
expect(fs.existsSync(join(project, '.git'))).toBe(true)
expect(fs.existsSync(join(project, 'README.md'))).toBe(true)
})
afterAll(async () => {
jest.clearAllMocks()
await fs.promises.rm(temp, { recursive: true })
})