-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-file-create.spec.ts
71 lines (60 loc) · 2 KB
/
test-file-create.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
import * as fs from 'fs-extra';
import * as path from 'path';
import { FileGeneratorHandler } from '../handlers/file-manager/file-generate';
import { Logger } from '@nestjs/common';
import { isIntegrationTest } from 'src/common/utils';
(isIntegrationTest ? describe : describe.skip)('FileGeneratorHandler', () => {
const projectSrcPath = path.normalize(
path.join('src', 'build-system', '__tests__', 'test-project'),
);
const mdFilePath = path.normalize(
path.join('src', 'build-system', '__tests__', 'file-arch.md'),
);
const structMdFilePath = path.normalize(
path.join('src', 'build-system', '__tests__', 'file-structure-document.md'),
);
beforeEach(async () => {
// Ensure the project directory is clean
await fs.remove(
path.normalize(
path.join('src', 'build-system', '__tests__', 'test-project', 'src'),
),
);
});
afterEach(async () => {
// Clean up the generated test files
await fs.remove(
path.normalize(
path.join('src', 'build-system', '__tests__', 'test-project', 'src'),
),
);
});
it('should generate files based on file-arch.md', async () => {
const archMarkdownContent = fs.readFileSync(
path.normalize(path.resolve(mdFilePath)),
'utf8',
);
const structMarkdownContent = fs.readFileSync(
path.normalize(path.resolve(structMdFilePath)),
'utf8',
);
const handler = new FileGeneratorHandler();
// Run the file generator with the JSON data
const result = await handler.generateFiles(
archMarkdownContent,
projectSrcPath,
);
Logger.log('File generation result:', result);
// Verify that all files exist
const jsonData = JSON.parse(
/<GENERATEDCODE>([\s\S]*?)<\/GENERATEDCODE>/.exec(
archMarkdownContent,
)![1],
);
const files = Object.keys(jsonData.files);
for (const file of files) {
const filePath = path.resolve(projectSrcPath, file);
expect(fs.existsSync(filePath)).toBeTruthy();
}
}, 30000);
});