forked from caz-templates/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
100 lines (95 loc) · 3.42 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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',
'https://zce.me',
'zce',
'template',
[],
'message',
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, '.vscode/extensions.json'))).toBe(true)
expect(fs.existsSync(join(project, '.vscode/settings.json'))).toBe(true)
expect(fs.existsSync(join(project, 'template/package.json'))).toBe(true)
expect(fs.existsSync(join(project, 'template/LICENSE'))).toBe(true)
expect(fs.existsSync(join(project, 'template/README.md'))).toBe(true)
expect(fs.existsSync(join(project, '.editorconfig'))).toBe(true)
expect(fs.existsSync(join(project, '.gitignore'))).toBe(true)
expect(fs.existsSync(join(project, 'index.js'))).toBe(true)
expect(fs.existsSync(join(project, 'LICENSE'))).toBe(true)
expect(fs.existsSync(join(project, 'package.json'))).toBe(true)
expect(fs.existsSync(join(project, 'README.md'))).toBe(true)
})
test('maximal', async () => {
inject([
'maximal',
'0.1.0',
'maximal template',
'zce',
'https://zce.me',
'zce',
'source',
[
'metadata',
'prompts',
'filters',
'helpers',
'install',
'init',
'setup',
'prepare',
'emit',
'complete',
'test'
],
'callback',
true,
'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, '.vscode/extensions.json'))).toBe(true)
expect(fs.existsSync(join(project, '.vscode/settings.json'))).toBe(true)
expect(fs.existsSync(join(project, 'node_modules'))).toBe(true)
expect(fs.existsSync(join(project, 'source/package.json'))).toBe(true)
expect(fs.existsSync(join(project, 'source/LICENSE'))).toBe(true)
expect(fs.existsSync(join(project, 'source/README.md'))).toBe(true)
expect(fs.existsSync(join(project, '.editorconfig'))).toBe(true)
expect(fs.existsSync(join(project, '.gitignore'))).toBe(true)
expect(fs.existsSync(join(project, '.travis.yml'))).toBe(true)
expect(fs.existsSync(join(project, 'index.js'))).toBe(true)
expect(fs.existsSync(join(project, 'index.test.js'))).toBe(true)
expect(fs.existsSync(join(project, 'LICENSE'))).toBe(true)
expect(fs.existsSync(join(project, 'package-lock.json'))).toBe(true)
expect(fs.existsSync(join(project, 'package.json'))).toBe(true)
expect(fs.existsSync(join(project, 'README.md'))).toBe(true)
})
afterAll(async () => {
jest.clearAllMocks()
await fs.promises.rm(temp, { recursive: true })
})