-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathdirective.test.js
50 lines (42 loc) · 1.38 KB
/
directive.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
globalThis.__dirname = __dirname
vi.mock('fs-extra')
vi.mock('../../../../lib', async (importOriginal) => {
const originalLib = await importOriginal()
return {
...originalLib,
generateTemplate: () => '',
}
})
import fs from 'fs-extra'
import { vol } from 'memfs'
import { vi, beforeEach, afterEach, test, expect } from 'vitest'
import '../../../../lib/test'
import { files } from '../../../generate/directive/directive.js'
import { tasks } from '../directive.js'
beforeEach(() => {
vol.fromJSON(files({ name: 'require-admin', type: 'validator', tests: true }))
vi.spyOn(console, 'info').mockImplementation(() => {})
vi.spyOn(console, 'log').mockImplementation(() => {})
})
afterEach(() => {
vol.reset()
vi.spyOn(fs, 'unlinkSync').mockClear()
console.info.mockRestore()
console.log.mockRestore()
})
test('destroys directive files', async () => {
const unlinkSpy = vi.spyOn(fs, 'unlinkSync')
const t = tasks({
componentName: 'directive',
filesFn: (args) => files({ ...args, type: 'validator' }),
name: 'require-admin',
})
t.options.renderer = 'silent'
return t.run().then(() => {
const generatedFiles = Object.keys(
files({ name: 'require-admin', type: 'validator', tests: true }),
)
expect(generatedFiles.length).toEqual(unlinkSpy.mock.calls.length)
generatedFiles.forEach((f) => expect(unlinkSpy).toHaveBeenCalledWith(f))
})
})