Repository navigation
Expand file tree
/
Copy pathparameters.test.js
More file actions
86 lines (72 loc) · 3.29 KB
/
Copy pathparameters.test.js
File metadata and controls
86 lines (72 loc) · 3.29 KB
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
const path = require('path');
const Generator = require('@asyncapi/generator');
const {existsSync} = require("fs");
const { readFile } = require('fs').promises;
const MAIN_TEST_RESULT_PATH = path.join('tests', 'temp', 'integrationTestResult');
const generateFolderName = () => {
// you always want to generate to new directory to make sure test runs in clear environment
return path.resolve(MAIN_TEST_RESULT_PATH, Date.now().toString());
};
describe('integration tests for generated files under different template parameters', () => {
jest.setTimeout(30000);
it('should generate spring 2 code with parameter', async() => {
const outputDir = generateFolderName();
const params = {"springBoot2": true};
const kafkaExamplePath = './mocks/kafka.yml';
const generator = new Generator(path.normalize('./'), outputDir, { forceWrite: true, templateParams: params });
await generator.generateFromFile(path.resolve('tests', kafkaExamplePath));
const expectedFiles = [
'/src/main/java/com/asyncapi/service/MessageHandlerService.java',
'/src/main/java/com/asyncapi/model/LightMeasuredPayload.java',
'/src/main/java/com/asyncapi/model/LightMeasured.java',
'/build.gradle',
'/gradle.properties'
];
for (const index in expectedFiles) {
const file = await readFile(path.join(outputDir, expectedFiles[index]), 'utf8');
expect(file).toMatchSnapshot();
}
});
it('should generate maven build', async() => {
const outputDir = generateFolderName();
const params = {"maven": true};
const kafkaExamplePath = './mocks/kafka.yml';
const generator = new Generator(path.normalize('./'), outputDir, { forceWrite: true, templateParams: params });
await generator.generateFromFile(path.resolve('tests', kafkaExamplePath));
const expectedFiles = [
'/pom.xml'
];
const notExpectedFiles = [
'/build.gradle',
'/gradle.properties'
];
for (const index in expectedFiles) {
const file = await readFile(path.join(outputDir, expectedFiles[index]), 'utf8');
expect(file).toMatchSnapshot();
}
for (const index in notExpectedFiles) {
expect(existsSync(path.join(outputDir, notExpectedFiles[index]))).toBeFalsy();
}
});
it('should generate gradle build', async() => {
const outputDir = generateFolderName();
const params = {"maven": false};
const kafkaExamplePath = './mocks/kafka.yml';
const generator = new Generator(path.normalize('./'), outputDir, { forceWrite: true, templateParams: params });
await generator.generateFromFile(path.resolve('tests', kafkaExamplePath));
const notExpectedFiles = [
'/pom.xml'
];
const expectedFiles = [
'/build.gradle',
'/gradle.properties'
];
for (const index in expectedFiles) {
const file = await readFile(path.join(outputDir, expectedFiles[index]), 'utf8');
expect(file).toMatchSnapshot();
}
for (const index in notExpectedFiles) {
expect(existsSync(path.join(outputDir, notExpectedFiles[index]))).toBeFalsy();
}
});
});