@asyncapi/generator 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +146 -0
- package/Dockerfile +7 -8
- package/cli.js +7 -0
- package/docs/api.md +12 -3
- package/docs/asyncapi-document.md +2 -1
- package/docs/configuration-file.md +112 -33
- package/docs/file-templates.md +2 -0
- package/docs/generator-template-java.md +560 -0
- package/docs/generator-template.md +62 -29
- package/docs/hooks.md +3 -3
- package/docs/installation-guide.md +5 -51
- package/docs/migration-cli.md +70 -0
- package/docs/migration-nunjucks-react.md +144 -0
- package/docs/nunjucks-render-engine.md +6 -2
- package/docs/template.md +2 -2
- package/docs/usage.md +14 -32
- package/docs/versioning.md +3 -1
- package/lib/conditionalGeneration.js +162 -0
- package/lib/filtersRegistry.js +5 -1
- package/lib/generator.js +96 -43
- package/lib/hooksRegistry.js +8 -1
- package/lib/logMessages.js +6 -1
- package/lib/parser.js +10 -0
- package/lib/renderer/nunjucks.js +2 -2
- package/lib/templateConfigValidator.js +30 -1
- package/package.json +4 -6
- package/test/generator.test.js +1 -1
- package/test/hooksRegistry.test.js +173 -0
- package/test/integration.test.js +51 -4
- package/test/parser.test.js +100 -2
- package/test/templateConfigValidator.test.js +18 -1
- package/test/test-project/README.md +5 -1
- package/test/test-project/docker-compose.yml +7 -15
- package/test/test-project/package.json +0 -1
- package/test/test-project/test-project.test.js +6 -2
- package/test/test-project/test-registry.test.js +7 -2
- package/test/test-project/test.sh +6 -1
- package/test/test-project/verdaccio/config.yaml +6 -0
- package/test/test-templates/nunjucks-template/package-lock.json +110 -183
- package/test/test-templates/react-template/.ageneratorrc +33 -0
- package/test/test-templates/react-template/package.json +5 -20
- package/test/test-templates/react-template/template/conditionalFile.txt +0 -0
- package/test/test-templates/react-template/template/conditionalFolder/conditionalFile.txt +0 -0
- package/test/test-templates/react-template/template/conditionalFolder2/input.txt +0 -0
- package/test/test-templates/react-template/template/models.js +6 -0
- package/test/utils.test.js +53 -0
- package/test/test-project/test-entrypoint.sh +0 -12
- package/test/test-templates/react-template/__transpiled/test-file.md.js +0 -24
- package/test/test-templates/react-template/__transpiled/test-file.md.js.map +0 -1
- package/test/test-templates/react-template/package-lock.json +0 -4135
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { addHook, registerLocalHooks, registerConfigHooks, registerHooks } = require('../lib/hooksRegistry');
|
|
7
|
+
|
|
8
|
+
jest.mock('fs');
|
|
9
|
+
jest.mock('path');
|
|
10
|
+
|
|
11
|
+
describe('hooksRegistry', () => {
|
|
12
|
+
let hooks;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
hooks = {}; // reset hooks for each test
|
|
16
|
+
jest.clearAllMocks(); // Reset all mocks
|
|
17
|
+
jest.resetModules(); // Reset modules
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('registerHooks', () => {
|
|
21
|
+
it('registers both local and config hooks', async () => {
|
|
22
|
+
const templateDir = path.join(__dirname, 'fixtures', 'template', 'hooks');
|
|
23
|
+
const hooksDir = path.join(__dirname, 'hooks');
|
|
24
|
+
|
|
25
|
+
fs.mkdirSync(hooksDir, { recursive: true });
|
|
26
|
+
fs.writeFileSync(path.join(hooksDir, 'preGenerate.js'), `
|
|
27
|
+
module.exports = function localPreGenerateHook() {};
|
|
28
|
+
`);
|
|
29
|
+
|
|
30
|
+
const templateConfig = {
|
|
31
|
+
hooks: {
|
|
32
|
+
'@asyncapi/hooks-module': ['configPreGenerateHook']
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
jest.mock('@asyncapi/hooks-module', () => ({
|
|
37
|
+
preGenerate: [function configPreGenerateHook() {}]
|
|
38
|
+
}), { virtual: true });
|
|
39
|
+
|
|
40
|
+
const result = await registerHooks(hooks, templateConfig, templateDir, 'hooks');
|
|
41
|
+
|
|
42
|
+
expect(result.preGenerate).toHaveLength(1);
|
|
43
|
+
expect(result.preGenerate[0].name).toBe('configPreGenerateHook');
|
|
44
|
+
|
|
45
|
+
fs.rmSync(hooksDir, { recursive: true, force: true });
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('registerLocalHooks', () => {
|
|
50
|
+
const mockPreGenerateHook = function preGenerateHook() {};
|
|
51
|
+
|
|
52
|
+
beforeAll(() => {
|
|
53
|
+
path.join.mockImplementation((...args) => args.join('/'));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
fs.existsSync.mockReturnValue(true);
|
|
58
|
+
fs.readdirSync.mockReturnValue(['preGenerate.js']);
|
|
59
|
+
|
|
60
|
+
jest.mock('fixtures/template/hooks/preGenerate.js', () => mockPreGenerateHook, { virtual: true });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('handles missing hooks directory', async () => {
|
|
64
|
+
fs.existsSync.mockReturnValueOnce(false);
|
|
65
|
+
|
|
66
|
+
const result = await registerLocalHooks(hooks, '/non/existent/path', 'hooks');
|
|
67
|
+
expect(result).toBe(hooks);
|
|
68
|
+
expect(result.preGenerate).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('handles errors during hook loading', async () => {
|
|
72
|
+
fs.existsSync.mockReturnValue(true);
|
|
73
|
+
fs.readdirSync.mockReturnValue(['errorHook.js']);
|
|
74
|
+
|
|
75
|
+
jest.mock('fixtures/template/hooks/errorHook.js', () => {
|
|
76
|
+
throw new Error('Mock import error');
|
|
77
|
+
}, { virtual: true });
|
|
78
|
+
|
|
79
|
+
await expect(registerLocalHooks(hooks, 'fixtures/template', 'hooks'))
|
|
80
|
+
.resolves.not.toThrow();
|
|
81
|
+
|
|
82
|
+
expect(hooks).toEqual({});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('registerConfigHooks', () => {
|
|
87
|
+
it('registers hooks from template config', async () => {
|
|
88
|
+
const templateDir = path.join(__dirname, 'fixtures', 'template');
|
|
89
|
+
const templateConfig = {
|
|
90
|
+
hooks: {
|
|
91
|
+
'@asyncapi/hooks-module': ['preGenerateHook']
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Mock the hook module
|
|
96
|
+
jest.mock('@asyncapi/hooks-module', () => ({
|
|
97
|
+
preGenerate: [function preGenerateHook() {}]
|
|
98
|
+
}), { virtual: true });
|
|
99
|
+
|
|
100
|
+
const result = await registerConfigHooks(hooks, templateDir, templateConfig);
|
|
101
|
+
|
|
102
|
+
expect(result.preGenerate).toHaveLength(1);
|
|
103
|
+
expect(result.preGenerate[0].name).toBe('preGenerateHook');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('handles missing hooks in config', async () => {
|
|
107
|
+
const result = await registerConfigHooks(hooks, '', {});
|
|
108
|
+
expect(result).toBeUndefined();
|
|
109
|
+
expect(hooks).toEqual({});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('addHooks', () => {
|
|
114
|
+
it('adds hooks from module to hooks object', () => {
|
|
115
|
+
const mod = {
|
|
116
|
+
preGenerate: [function preGenerateHook() {}],
|
|
117
|
+
postGenerate: [function postGenerateHook() {}]
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
addHook(hooks, mod, null);
|
|
121
|
+
|
|
122
|
+
expect(hooks.preGenerate).toHaveLength(1);
|
|
123
|
+
expect(hooks.postGenerate).toHaveLength(1);
|
|
124
|
+
expect(hooks.preGenerate[0].name).toBe('preGenerateHook');
|
|
125
|
+
expect(hooks.postGenerate[0].name).toBe('postGenerateHook');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('adds hooks from module.default if it exists', () => {
|
|
129
|
+
const mod = {
|
|
130
|
+
default: {
|
|
131
|
+
preGenerate: [function preGenerateHook() {}],
|
|
132
|
+
postGenerate: [function postGenerateHook() {}]
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
addHook(hooks, mod, null);
|
|
137
|
+
|
|
138
|
+
expect(hooks.preGenerate).toHaveLength(1);
|
|
139
|
+
expect(hooks.postGenerate).toHaveLength(1);
|
|
140
|
+
expect(hooks.preGenerate[0].name).toBe('preGenerateHook');
|
|
141
|
+
expect(hooks.postGenerate[0].name).toBe('postGenerateHook');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('does not add hooks that are not in config', () => {
|
|
145
|
+
const mod = {
|
|
146
|
+
preGenerate: [function preGenerateHook() {}],
|
|
147
|
+
postGenerate: [function postGenerateHook() {}]
|
|
148
|
+
};
|
|
149
|
+
const config = ['preGenerateHook'];
|
|
150
|
+
|
|
151
|
+
addHook(hooks, mod, config);
|
|
152
|
+
|
|
153
|
+
expect(hooks.preGenerate).toHaveLength(1);
|
|
154
|
+
expect(hooks.postGenerate).toBeUndefined();
|
|
155
|
+
expect(hooks.preGenerate[0].name).toBe('preGenerateHook');
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('adds hooks that are in config', () => {
|
|
159
|
+
const mod = {
|
|
160
|
+
preGenerate: [function preGenerateHook() {}],
|
|
161
|
+
postGenerate: [function postGenerateHook() {}]
|
|
162
|
+
};
|
|
163
|
+
const config = ['preGenerateHook', 'postGenerateHook'];
|
|
164
|
+
|
|
165
|
+
addHook(hooks, mod, config);
|
|
166
|
+
|
|
167
|
+
expect(hooks.preGenerate).toHaveLength(1);
|
|
168
|
+
expect(hooks.postGenerate).toHaveLength(1);
|
|
169
|
+
expect(hooks.preGenerate[0].name).toBe('preGenerateHook');
|
|
170
|
+
expect(hooks.postGenerate[0].name).toBe('postGenerateHook');
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
package/test/integration.test.js
CHANGED
|
@@ -10,11 +10,11 @@ const dummySpecPath = path.resolve(__dirname, './docs/dummy.yml');
|
|
|
10
10
|
const refSpecPath = path.resolve(__dirname, './docs/apiwithref.json');
|
|
11
11
|
const refSpecFolder = path.resolve(__dirname, './docs/');
|
|
12
12
|
const crypto = require('crypto');
|
|
13
|
-
const mainTestResultPath = '
|
|
14
|
-
const reactTemplate = 'test
|
|
15
|
-
const nunjucksTemplate = 'test
|
|
13
|
+
const mainTestResultPath = path.resolve(__dirname, './temp/integrationTestResult');
|
|
14
|
+
const reactTemplate = path.resolve(__dirname, './test-templates/react-template');
|
|
15
|
+
const nunjucksTemplate = path.resolve(__dirname, './test-templates/nunjucks-template');
|
|
16
16
|
//temp location where react template is copied for each test that does some mutation on template files
|
|
17
|
-
const copyOfReactTemplate = '
|
|
17
|
+
const copyOfReactTemplate = path.resolve(__dirname, './temp/reactTemplate');
|
|
18
18
|
|
|
19
19
|
describe('Integration testing generateFromFile() to make sure the result of the generation is not changend comparing to snapshot', () => {
|
|
20
20
|
const generateFolderName = () => {
|
|
@@ -153,4 +153,51 @@ describe('Integration testing generateFromFile() to make sure the result of the
|
|
|
153
153
|
Include log message test in the future to ensure that the log.debug for skipping overwrite is called
|
|
154
154
|
*/
|
|
155
155
|
});
|
|
156
|
+
|
|
157
|
+
it('should not generate the conditionalFolder if the singleFolder parameter is set true', async () => {
|
|
158
|
+
const outputDir = generateFolderName();
|
|
159
|
+
const generator = new Generator(reactTemplate, outputDir, {
|
|
160
|
+
forceWrite: true ,
|
|
161
|
+
templateParams: { version: 'v1', mode: 'production', singleFolder: 'true' }
|
|
162
|
+
});
|
|
163
|
+
await generator.generateFromFile(dummySpecPath);
|
|
164
|
+
const conditionalFolderPath = path.join(outputDir, 'conditionalFolder');
|
|
165
|
+
const exists = await access(conditionalFolderPath).then(() => true).catch(() => false);
|
|
166
|
+
expect(exists).toBe(false);
|
|
167
|
+
});
|
|
168
|
+
it('should not generate the conditionalFile if the singleFile parameter is set true', async () => {
|
|
169
|
+
const outputDir = generateFolderName();
|
|
170
|
+
const generator = new Generator(reactTemplate, outputDir, {
|
|
171
|
+
forceWrite: true ,
|
|
172
|
+
templateParams: { version: 'v1', mode: 'production', singleFile: 'true' }
|
|
173
|
+
});
|
|
174
|
+
await generator.generateFromFile(dummySpecPath);
|
|
175
|
+
const conditionalFilePath = path.join(outputDir, 'conditionalFile.txt');
|
|
176
|
+
const exists = await readFile(conditionalFilePath).then(() => true).catch(() => false);
|
|
177
|
+
expect(exists).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('should generate the conditionalFile if the singleFile parameter is set false', async () => {
|
|
181
|
+
const outputDir = generateFolderName();
|
|
182
|
+
const generator = new Generator(reactTemplate, outputDir, {
|
|
183
|
+
forceWrite: true ,
|
|
184
|
+
templateParams: { version: 'v1', mode: 'production', singleFile: 'false' }
|
|
185
|
+
});
|
|
186
|
+
await generator.generateFromFile(dummySpecPath);
|
|
187
|
+
const conditionalFilePath = path.join(outputDir, 'conditionalFile.txt');
|
|
188
|
+
const exists = await readFile(conditionalFilePath).then(() => true).catch(() => false);
|
|
189
|
+
expect(exists).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('should generate the conditionalFile if the singleFile parameter is set false using enum validation', async () => {
|
|
193
|
+
const outputDir = generateFolderName();
|
|
194
|
+
const generator = new Generator(reactTemplate, outputDir, {
|
|
195
|
+
forceWrite: true ,
|
|
196
|
+
templateParams: { version: 'v1', mode: 'production', singleFile: 'false' }
|
|
197
|
+
});
|
|
198
|
+
await generator.generateFromFile(dummySpecPath);
|
|
199
|
+
const conditionalFilePath = path.join(outputDir, 'conditionalFolder2/input.txt');
|
|
200
|
+
const exists = await readFile(conditionalFilePath).then(() => true).catch(() => false);
|
|
201
|
+
expect(exists).toBe(true);
|
|
202
|
+
});
|
|
156
203
|
});
|
package/test/parser.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const { sanitizeTemplateApiVersion, usesNewAPI, parse } = require('../lib/parser');
|
|
3
|
+
const { sanitizeTemplateApiVersion, usesNewAPI, parse, convertOldOptionsToNew } = require('../lib/parser');
|
|
4
4
|
const dummyV2Document = fs.readFileSync(path.resolve(__dirname, './docs/dummy.yml'), 'utf8');
|
|
5
5
|
const dummyV3Document = fs.readFileSync(path.resolve(__dirname, './docs/dummyV3.yml'), 'utf8');
|
|
6
6
|
|
|
@@ -99,9 +99,107 @@ describe('Parser', () => {
|
|
|
99
99
|
});
|
|
100
100
|
it('should be able to parse AsyncAPI v3 document for parser API v3', async () => {
|
|
101
101
|
const parsedDocument = await parse(dummyV3Document, {}, {templateConfig: {apiVersion: 'v3'}});
|
|
102
|
-
|
|
103
102
|
expect(parsedDocument).toBeDefined();
|
|
104
103
|
expect(parsedDocument.document.version()).toEqual('3.0.0');
|
|
105
104
|
});
|
|
106
105
|
});
|
|
106
|
+
|
|
107
|
+
describe('getProperApiDocument', () => {
|
|
108
|
+
const parser_api_version = 'x-parser-api-version';
|
|
109
|
+
const parser_spec_parsed = 'x-parser-spec-parsed';
|
|
110
|
+
const parser_original_schema = 'x-parser-original-schema-format';
|
|
111
|
+
const parser_original_payload = 'x-parser-original-payload';
|
|
112
|
+
const parser_message = 'x-parser-message-parsed';
|
|
113
|
+
it('should convert to old API if apiVersion is undefined', async () => {
|
|
114
|
+
// parse calls the get properAPIDocument and returns it along with a diagnostic in a Object
|
|
115
|
+
// so its like called the get properAPIDocument function and then returned the result
|
|
116
|
+
const templateConfig = {};
|
|
117
|
+
const properDocument = await parse(dummyV2Document, {}, { templateConfig });
|
|
118
|
+
|
|
119
|
+
// Validate that properDocument convert it to expected API version from the template
|
|
120
|
+
expect(properDocument).toBeDefined();
|
|
121
|
+
|
|
122
|
+
expect(properDocument).toBeDefined();
|
|
123
|
+
expect(properDocument.document._json).toBeDefined();
|
|
124
|
+
expect(properDocument.document._json.asyncapi).toEqual('2.3.0');
|
|
125
|
+
expect(properDocument.diagnostics).toBeDefined();
|
|
126
|
+
expect(properDocument.diagnostics.length).toBeGreaterThan(0);
|
|
127
|
+
|
|
128
|
+
expect(properDocument.document._json[parser_api_version]).toBeDefined();
|
|
129
|
+
expect(properDocument.document._json[parser_api_version]).toEqual(0);
|
|
130
|
+
expect(properDocument.document._json[parser_spec_parsed]).toBeDefined();
|
|
131
|
+
expect(properDocument.document._json[parser_spec_parsed]).toEqual(true);
|
|
132
|
+
|
|
133
|
+
expect(properDocument.document._meta).toBeDefined();
|
|
134
|
+
expect(properDocument.document._meta).toEqual({});
|
|
135
|
+
expect(properDocument.document._json.components.messages.dummyCreated).toBeDefined();
|
|
136
|
+
expect(properDocument.document._json.components.messages.dummyCreated[parser_original_schema]).toBeDefined(); // Only old API includes this filed
|
|
137
|
+
expect(properDocument.document._json.components.messages.dummyCreated[parser_original_payload]).toBeDefined();
|
|
138
|
+
expect(properDocument.document._json.components.messages.dummyCreated[parser_message]).toBeDefined();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should convert to specified API version', async () => {
|
|
142
|
+
const templateConfig = { apiVersion: 'v2' };
|
|
143
|
+
const properDocument = await parse(dummyV2Document, {}, { templateConfig });
|
|
144
|
+
|
|
145
|
+
// Validate that properDocument is defined
|
|
146
|
+
expect(properDocument).toBeDefined();
|
|
147
|
+
|
|
148
|
+
// Validate that the document is converted to the specified API version
|
|
149
|
+
expect(properDocument.document._json.asyncapi).toEqual('2.3.0');
|
|
150
|
+
expect(properDocument.diagnostics).toBeDefined();
|
|
151
|
+
expect(properDocument.diagnostics.length).toBeGreaterThan(0);
|
|
152
|
+
|
|
153
|
+
expect(properDocument.document._json[parser_api_version]).toBeDefined();
|
|
154
|
+
expect(properDocument.document._json[parser_spec_parsed]).toBeDefined();
|
|
155
|
+
expect(properDocument.document._json[parser_api_version]).toEqual(2);
|
|
156
|
+
expect(properDocument.document._json[parser_spec_parsed]).toEqual(true);
|
|
157
|
+
|
|
158
|
+
expect(properDocument.document._meta).toBeDefined();
|
|
159
|
+
expect(properDocument.document._json.components.messages.dummyCreated).toBeDefined();
|
|
160
|
+
expect(properDocument.document._json.components.messages.dummyCreated[parser_original_schema]).toBeUndefined();
|
|
161
|
+
expect(properDocument.document._json.components.messages.dummyCreated[parser_original_payload]).toBeUndefined();
|
|
162
|
+
expect(properDocument.document._json.components.messages.dummyCreated[parser_message]).toBeUndefined();
|
|
163
|
+
|
|
164
|
+
// Validate that old API-specific functions and properties are not present
|
|
165
|
+
expect(properDocument.oldApiSpecificFunction).toBeUndefined();
|
|
166
|
+
expect(properDocument.oldApiSpecificProperty).toBeUndefined();
|
|
167
|
+
expect(properDocument.anotherOldApiFunction).toBeUndefined();
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('convertOldOptionsToNew', () => {
|
|
172
|
+
it('should convert old options to new options', () => {
|
|
173
|
+
const oldOptions = {
|
|
174
|
+
path: './test/docs/',
|
|
175
|
+
applyTraits: true,
|
|
176
|
+
resolve: {
|
|
177
|
+
http: {
|
|
178
|
+
order: 1,
|
|
179
|
+
canRead: true,
|
|
180
|
+
read: jest.fn()
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const generator = {
|
|
185
|
+
mapBaseUrlToFolder: {
|
|
186
|
+
url: 'https://schema.example.com/crm/',
|
|
187
|
+
folder: './test/docs/'
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const newOptions = convertOldOptionsToNew(oldOptions, generator);
|
|
191
|
+
|
|
192
|
+
expect(newOptions).toBeDefined();
|
|
193
|
+
expect(newOptions.source).toEqual(oldOptions.path);
|
|
194
|
+
expect(newOptions.applyTraits).toEqual(oldOptions.applyTraits);
|
|
195
|
+
expect(newOptions.__unstable).toBeDefined();
|
|
196
|
+
expect(newOptions.__unstable.resolver.resolvers.length).toBeGreaterThan(0);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('should return undefined if oldOptions is not provided', () => {
|
|
200
|
+
const newOptions = convertOldOptionsToNew(undefined, {});
|
|
201
|
+
|
|
202
|
+
expect(newOptions).toBeUndefined();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
107
205
|
});
|
|
@@ -160,6 +160,23 @@ describe('Template Configuration Validator', () => {
|
|
|
160
160
|
expect(templateConfig.conditionalFiles['my/path/to/file.js']).toBeDefined();
|
|
161
161
|
});
|
|
162
162
|
|
|
163
|
+
it('Validation enrich conditional files object with validate object if the subject is info', () => {
|
|
164
|
+
const templateParams = {};
|
|
165
|
+
const templateConfig = {
|
|
166
|
+
conditionalFiles: {
|
|
167
|
+
'my/path/to/file.js': {
|
|
168
|
+
subject: 'info.title',
|
|
169
|
+
validation: {
|
|
170
|
+
const: 'asyncapi'
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
validateTemplateConfig(templateConfig, templateParams);
|
|
176
|
+
|
|
177
|
+
expect(templateConfig.conditionalFiles['my/path/to/file.js']).toBeDefined();
|
|
178
|
+
});
|
|
179
|
+
|
|
163
180
|
it('Validation throw error if specified server is not in asyncapi document', () => {
|
|
164
181
|
const templateParams = {
|
|
165
182
|
server: 'myserver'
|
|
@@ -274,4 +291,4 @@ describe('Template Configuration Validator', () => {
|
|
|
274
291
|
expect(() => validateTemplateConfig(templateConfig, templateParams, asyncapiDocument)).toThrow('Server "dummy-mqtt" uses the mqtt protocol but this template only supports the following ones: myprotocol.');
|
|
275
292
|
});
|
|
276
293
|
});
|
|
277
|
-
});
|
|
294
|
+
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
It is a test project where AsyncAPI Generator and test template are used as Node.js dependencies.
|
|
2
2
|
The purpose of this project is to test AsyncAPI Generator library use case outside the Generator code base.
|
|
3
3
|
|
|
4
|
-
Instead of running tests with `npm test`, make sure you have Docker Compose and run
|
|
4
|
+
Instead of running tests with `npm test`, make sure you have Docker Compose and run the following command:
|
|
5
|
+
|
|
6
|
+
Linux/MacOS: `NODE_VERSION=18 docker-compose up --abort-on-container-exit --force-recreate`.
|
|
7
|
+
|
|
8
|
+
Windows: `set NODE_VERSION=18&& docker-compose up --abort-on-container-exit --force-recreate`.
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
version: '3'
|
|
2
|
-
|
|
3
1
|
services:
|
|
4
2
|
verdaccio:
|
|
5
3
|
image: verdaccio/verdaccio:5
|
|
@@ -7,18 +5,12 @@ services:
|
|
|
7
5
|
- '4873:4873'
|
|
8
6
|
volumes:
|
|
9
7
|
- './verdaccio:/verdaccio/conf'
|
|
10
|
-
networks:
|
|
11
|
-
- mynetwork
|
|
12
8
|
|
|
13
9
|
test-project:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
networks:
|
|
23
|
-
mynetwork:
|
|
24
|
-
driver: bridge
|
|
10
|
+
pull_policy: build
|
|
11
|
+
build:
|
|
12
|
+
context: ../../../../ # Root of the project
|
|
13
|
+
args:
|
|
14
|
+
NODE_VERSION: ${NODE_VERSION}
|
|
15
|
+
user: root # Use root user to avoid permission issues when creating directories
|
|
16
|
+
command: ["sh", "/app/apps/generator/test/test-project/test.sh", "test-project"]
|
|
@@ -15,11 +15,15 @@ const logMessage = require('../../lib/logMessages.js');
|
|
|
15
15
|
const newContentNotExpectedInTest = 'new content';
|
|
16
16
|
const version = '0.0.1';
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const originalConsoleLog = console.log;
|
|
19
19
|
|
|
20
|
+
// Replace console.log with a custom mock function
|
|
21
|
+
console.log = jest.fn((...args) => {
|
|
22
|
+
// Call the original function to actually log to the console
|
|
23
|
+
originalConsoleLog(...args);
|
|
24
|
+
});
|
|
20
25
|
describe('Testing if markdown was generated with proper version of the template', () => {
|
|
21
26
|
jest.setTimeout(1000000);
|
|
22
|
-
|
|
23
27
|
it('Test A - generated markdown should not contain new content in modified template', async () => {
|
|
24
28
|
//we setup generator using template name, not path, without explicitly running installation
|
|
25
29
|
//generator picks up template that is already in node_modules as it was installed before as node dependency
|
|
@@ -8,8 +8,14 @@ const Generator = require('@asyncapi/generator');
|
|
|
8
8
|
const dummySpecPath = path.resolve(__dirname, '../docs/dummy.yml');
|
|
9
9
|
const tempOutputResults = path.resolve(__dirname, 'output');
|
|
10
10
|
|
|
11
|
-
console.log
|
|
11
|
+
// Save the original console.log
|
|
12
|
+
const originalConsoleLog = console.log;
|
|
12
13
|
|
|
14
|
+
// Replace console.log with a custom mock function
|
|
15
|
+
console.log = jest.fn((...args) => {
|
|
16
|
+
// Call the original function to actually log to the console
|
|
17
|
+
originalConsoleLog(...args);
|
|
18
|
+
});
|
|
13
19
|
describe('Integration testing generateFromFile() to make sure the template can be download from the private repository from argument', () => {
|
|
14
20
|
jest.setTimeout(1000000);
|
|
15
21
|
|
|
@@ -38,7 +44,6 @@ describe('Integration testing generateFromFile() to make sure the template can b
|
|
|
38
44
|
|
|
39
45
|
describe('Integration testing generateFromFile() to make sure the template can be download from the private repository from npm config', () => {
|
|
40
46
|
jest.setTimeout(1000000);
|
|
41
|
-
|
|
42
47
|
it('generated using private registory from npm config', async () => {
|
|
43
48
|
const generator = new Generator('react-template', tempOutputResults,
|
|
44
49
|
{
|
|
@@ -51,7 +51,7 @@ Starting registry test
|
|
|
51
51
|
sudo chown -R 1001:121 "/root/.npm"
|
|
52
52
|
|
|
53
53
|
# Always run these steps
|
|
54
|
-
cd app
|
|
54
|
+
cd /app
|
|
55
55
|
|
|
56
56
|
echo "##########
|
|
57
57
|
Running installation in root
|
|
@@ -71,6 +71,11 @@ Publish test template to local npm-verdaccio
|
|
|
71
71
|
npm config set -- //verdaccio:4873/:_auth=YWRtaW46bmltZGE=
|
|
72
72
|
npm config set registry http://verdaccio:4873
|
|
73
73
|
|
|
74
|
+
echo "##########
|
|
75
|
+
Publish @asyncapi/generator-components to local npm-verdaccio
|
|
76
|
+
##########"
|
|
77
|
+
npm publish ../../../../packages/components
|
|
78
|
+
|
|
74
79
|
echo "##########
|
|
75
80
|
Publishing the correct template as 0.0.1
|
|
76
81
|
##########"
|
|
@@ -10,7 +10,13 @@ packages:
|
|
|
10
10
|
"react-template":
|
|
11
11
|
access: admin
|
|
12
12
|
publish: admin
|
|
13
|
+
"@asyncapi/generator-components":
|
|
14
|
+
access: admin
|
|
15
|
+
publish: admin
|
|
13
16
|
"!react-template":
|
|
14
17
|
access: admin
|
|
15
18
|
proxy: npmjs
|
|
19
|
+
"!@asyncapi/generator-components":
|
|
20
|
+
access: admin
|
|
21
|
+
proxy: npmjs
|
|
16
22
|
log: { type: stdout, format: pretty, level: error }
|