-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
generate-files.spec.ts
82 lines (74 loc) · 2.66 KB
/
generate-files.spec.ts
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
import type { Tree } from 'nx/src/generators/tree';
import { createTree } from 'nx/src/generators/testing-utils/create-tree';
import { generateFiles } from './generate-files';
import { join } from 'path';
import * as FileType from 'file-type';
describe('generateFiles', () => {
let tree: Tree;
beforeAll(() => {
tree = createTree();
generateFiles(tree, join(__dirname, './test-files'), '.', {
foo: 'bar',
name: 'my-project',
projectName: 'my-project-name',
dot: '.',
});
});
it('should copy files from a directory into a tree', () => {
expect(tree.exists('file.txt')).toBeTruthy();
expect(tree.read('file.txt', 'utf-8')).toMatchSnapshot();
});
it('should copy files from a directory into the tree', () => {
expect(tree.exists('directory/file-in-directory.txt')).toBeTruthy();
expect(
tree.read('directory/file-in-directory.txt', 'utf-8')
).toMatchSnapshot();
});
it('should remove ".template" from paths', () => {
expect(
tree.exists('file-with-template-suffix.txt.template')
).not.toBeTruthy();
expect(tree.exists('file-with-template-suffix.txt')).toBeTruthy();
expect(
tree.read('file-with-template-suffix.txt', 'utf-8')
).toMatchSnapshot();
});
it('should substitute properties in paths', () => {
expect(tree.exists('file-with-property-foo-__foo__.txt')).not.toBeTruthy();
expect(tree.exists('file-with-property-foo-bar.txt')).toBeTruthy();
expect(
tree.read('file-with-property-foo-bar.txt', 'utf-8')
).toMatchSnapshot();
});
it('should substitute properties in directory names', () => {
expect(
tree.exists('directory-foo-__foo__/file-in-directory-foo-__foo__.txt')
).not.toBeTruthy();
expect(
tree.exists('directory-foo-bar/file-in-directory-foo-bar.txt')
).toBeTruthy();
expect(
tree.read('directory-foo-bar/file-in-directory-foo-bar.txt', 'utf-8')
).toMatchSnapshot();
});
it('should generate files from template in a directory', () => {
expect(tree.exists(`src/common-util.ts`)).toBeTruthy();
expect(
tree.exists(`src/my-project-name/create-my-project.input.ts`)
).toBeTruthy();
expect(
tree.exists(
`src/my-project-name/my-project/my-project-name.my-project.model.ts`
)
).toBeTruthy();
expect(tree.exists(`src/my-project-name/output/.gitkeep`)).toBeTruthy();
expect(tree.exists(`src/my-project.module.ts`)).toBeTruthy();
});
it('should preserve image files', async () => {
expect(tree.exists('image.png')).toBeTruthy();
await expect(FileType.fromBuffer(tree.read('image.png'))).resolves.toEqual({
ext: 'png',
mime: 'image/png',
});
});
});