@asyncapi/generator 2.7.0 → 2.8.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/docs/api.md +33 -0
  3. package/docs/baked-in-templates.md +100 -0
  4. package/docs/configuration-file.md +49 -31
  5. package/docs/template.md +22 -3
  6. package/lib/generator.js +31 -3
  7. package/lib/templates/BakedInTemplatesList.json +20 -0
  8. package/lib/templates/bakedInTemplates.js +53 -0
  9. package/package.json +9 -5
  10. package/test/__mocks__/@npmcli/arborist.js +0 -11
  11. package/test/__mocks__/@npmcli/config.js +0 -3
  12. package/test/__mocks__/fs.extra.js +0 -3
  13. package/test/__mocks__/loglevel.js +0 -3
  14. package/test/__mocks__/resolve-from.js +0 -8
  15. package/test/__mocks__/resolve-pkg.js +0 -8
  16. package/test/__snapshots__/integration.test.js.snap +0 -419
  17. package/test/docs/apiwithref.json +0 -41
  18. package/test/docs/dummy.yml +0 -390
  19. package/test/docs/dummyV3.yml +0 -31
  20. package/test/docs/shared.json +0 -27
  21. package/test/docs/ws.yml +0 -36
  22. package/test/generator.test.js +0 -629
  23. package/test/hooksRegistry.test.js +0 -173
  24. package/test/integration.test.js +0 -203
  25. package/test/parser.test.js +0 -205
  26. package/test/renderer.test.js +0 -62
  27. package/test/templateConfigValidator.test.js +0 -294
  28. package/test/test-project/.yarncr.yml +0 -3
  29. package/test/test-project/README.md +0 -8
  30. package/test/test-project/docker-compose.yml +0 -16
  31. package/test/test-project/package.json +0 -24
  32. package/test/test-project/test-global.test.js +0 -37
  33. package/test/test-project/test-project.test.js +0 -102
  34. package/test/test-project/test-registry.test.js +0 -62
  35. package/test/test-project/test.sh +0 -104
  36. package/test/test-project/verdaccio/config.yaml +0 -22
  37. package/test/test-project/verdaccio/htpasswd +0 -1
  38. package/test/test-templates/nunjucks-template/package-lock.json +0 -4062
  39. package/test/test-templates/nunjucks-template/package.json +0 -21
  40. package/test/test-templates/nunjucks-template/template/test-file.md +0 -5
  41. package/test/test-templates/react-template/.ageneratorrc +0 -33
  42. package/test/test-templates/react-template/package.json +0 -14
  43. package/test/test-templates/react-template/template/conditionalFile.txt +0 -0
  44. package/test/test-templates/react-template/template/conditionalFolder/conditionalFile.txt +0 -0
  45. package/test/test-templates/react-template/template/conditionalFolder2/input.txt +0 -0
  46. package/test/test-templates/react-template/template/models.js +0 -6
  47. package/test/test-templates/react-template/template/test-file.md.js +0 -11
  48. package/test/utils.test.js +0 -129
@@ -1,294 +0,0 @@
1
- /* eslint-disable sonarjs/no-identical-functions */
2
- /* eslint-disable sonarjs/no-duplicate-string */
3
- const { validateTemplateConfig } = require('../lib/templateConfigValidator');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const { parse } = require('../lib/parser');
7
- const dummyYAML = fs.readFileSync(path.resolve(__dirname, './docs/dummy.yml'), 'utf8');
8
-
9
- jest.mock('../lib/utils');
10
-
11
- describe('Template Configuration Validator', () => {
12
- let asyncapiDocument;
13
-
14
- beforeAll(async () => {
15
- const { document } = await parse(dummyYAML, {}, {templateConfig: {}});
16
- asyncapiDocument = document;
17
- });
18
-
19
- it('Validation doesn\'t throw errors if params are not passed and template has no config', () => {
20
- const templateParams = {};
21
- const templateConfig = {};
22
-
23
- const isValid = validateTemplateConfig(templateConfig, templateParams, asyncapiDocument);
24
-
25
- expect(isValid).toStrictEqual(true);
26
- });
27
-
28
- it('Validation doesn\'t throw errors for correct react renderer', () => {
29
- const templateParams = {};
30
- const templateConfig = {
31
- renderer: 'react'
32
- };
33
- const isValid = validateTemplateConfig(templateConfig, templateParams, asyncapiDocument);
34
- expect(isValid).toStrictEqual(true);
35
- });
36
- it('Validation doesn\'t throw errors for correct nunjucks renderer', () => {
37
- const templateParams = {};
38
- const templateConfig = {
39
- renderer: 'nunjucks'
40
- };
41
- const isValid = validateTemplateConfig(templateConfig, templateParams, asyncapiDocument);
42
- expect(isValid).toStrictEqual(true);
43
- });
44
- it('Validation throw error if renderer not supported', () => {
45
- const templateParams = {};
46
- const templateConfig = {
47
- renderer: 'non_existing'
48
- };
49
- expect(() => validateTemplateConfig(templateConfig, templateParams)).toThrow('We do not support \'non_existing\' as a renderer for a template. Only \'react\' or \'nunjucks\' are supported.');
50
- });
51
-
52
- it('Validation throw error if template is not compatible because of generator version', () => {
53
- const utils = require('../lib/utils');
54
- utils.__generatorVersion = '1.0.0';
55
-
56
- const templateParams = {};
57
- const templateConfig = {
58
- generator: '>1.0.1'
59
- };
60
-
61
- expect(() => validateTemplateConfig(templateConfig, templateParams)).toThrow('This template is not compatible with the current version of the generator (1.0.0). This template is compatible with the following version range: >1.0.1.');
62
- });
63
-
64
- it('Validation throw error if template is not compatible because of non-supported apiVersion value', () => {
65
- const utils = require('../lib/utils');
66
- utils.__generatorVersion = '1.0.0';
67
-
68
- const templateParams = {};
69
- const templateConfig = {
70
- apiVersion: '999999'
71
- };
72
-
73
- expect(() => validateTemplateConfig(templateConfig, templateParams)).toThrow('The version specified in apiVersion is not supported by this Generator version. Supported versions are: v1, v2');
74
- });
75
-
76
- it('Validation throw error if required params not provided', () => {
77
- const templateParams = {};
78
- const templateConfig = {
79
- parameters: {
80
- test: {
81
- description: 'test',
82
- required: true
83
- }
84
- }
85
- };
86
-
87
- expect(() => validateTemplateConfig(templateConfig, templateParams)).toThrow('This template requires the following missing params: test.');
88
- });
89
-
90
- it('Validation throw error if provided param is not in the list of params supported by the template', () => {
91
- const templateParams = {
92
- tsets: 'myTest'
93
- };
94
- const templateConfig = {
95
- parameters: {
96
- test: {
97
- description: 'this param distance to test1 equals 3 according to levenshtein-edit-distance'
98
- },
99
- thisissomethingsodifferent: {
100
- description: 'this param distance to test1 equals 21 according to levenshtein-edit-distance'
101
- }
102
- }
103
- };
104
- expect(() => validateTemplateConfig(templateConfig, templateParams, asyncapiDocument)).toThrow('This template doesn\'t have the following params: tsets.\nDid you mean "test" instead of "tsets"?');
105
- });
106
-
107
- it('Validation throw error if provided param is not supported by the template as template has no params specified', () => {
108
- console.warn = jest.fn();
109
- const templateParams = {
110
- test1: 'myTest'
111
- };
112
- const templateConfig = {};
113
-
114
- expect(() => validateTemplateConfig(templateConfig, templateParams, asyncapiDocument)).toThrow('This template doesn\'t have any params.');
115
- });
116
- it('Validation throw error if subject in condition files is not string', () => {
117
- const templateParams = {};
118
- const templateConfig = {
119
- conditionalFiles: {
120
- 'my/path/to/file.js': {
121
- subject: ['server.protocol'],
122
- validation: {
123
- const: 'myprotocol'
124
- }
125
- }
126
- }
127
- };
128
-
129
- expect(() => validateTemplateConfig(templateConfig, templateParams)).toThrow('Invalid conditional file subject for my/path/to/file.js: server.protocol.');
130
- });
131
-
132
- it('Validation throw error if validation in condition files is not object', () => {
133
- const templateParams = {};
134
- const templateConfig = {
135
- conditionalFiles: {
136
- 'my/path/to/file.js': {
137
- subject: 'server.url',
138
- validation: 'http://example.com'
139
- }
140
- }
141
- };
142
-
143
- expect(() => validateTemplateConfig(templateConfig, templateParams)).toThrow('Invalid conditional file validation object for my/path/to/file.js: http://example.com.');
144
- });
145
-
146
- it('Validation enrich conditional files object with validate object', () => {
147
- const templateParams = {};
148
- const templateConfig = {
149
- conditionalFiles: {
150
- 'my/path/to/file.js': {
151
- subject: 'server.protocol',
152
- validation: {
153
- const: 'myprotocol'
154
- }
155
- }
156
- }
157
- };
158
- validateTemplateConfig(templateConfig, templateParams);
159
-
160
- expect(templateConfig.conditionalFiles['my/path/to/file.js']).toBeDefined();
161
- });
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
-
180
- it('Validation throw error if specified server is not in asyncapi document', () => {
181
- const templateParams = {
182
- server: 'myserver'
183
- };
184
- const templateConfig = {
185
- parameters: {
186
- server: {
187
- description: ''
188
- }
189
- }
190
- };
191
-
192
- expect(() => validateTemplateConfig(templateConfig, templateParams, asyncapiDocument)).toThrow('Couldn\'t find server with name myserver.');
193
- });
194
-
195
- it('Validation throw error if given protocol is not supported by template', () => {
196
- const templateParams = {
197
- server: 'dummy-mqtt'
198
- };
199
- const templateConfig = {
200
- supportedProtocols: ['myprotocol'],
201
- parameters: {
202
- server: {
203
- description: ''
204
- }
205
- }
206
- };
207
-
208
- expect(() => validateTemplateConfig(templateConfig, templateParams, asyncapiDocument)).toThrow('Server "dummy-mqtt" uses the mqtt protocol but this template only supports the following ones: myprotocol.');
209
- });
210
-
211
- describe('should work with v1 apiVersion', () => {
212
- let asyncapiDocument;
213
- const v2TemplateConfig = {apiVersion: 'v1'};
214
- beforeAll(async () => {
215
- const { document } = await parse(dummyYAML, {}, {templateConfig: v2TemplateConfig});
216
- asyncapiDocument = document;
217
- });
218
-
219
- it('Validation throw error if specified server is not in asyncapi document', () => {
220
- const templateParams = {
221
- server: 'myserver'
222
- };
223
- const templateConfig = {
224
- ...v2TemplateConfig,
225
- parameters: {
226
- server: {
227
- description: ''
228
- }
229
- }
230
- };
231
-
232
- expect(() => validateTemplateConfig(templateConfig, templateParams, asyncapiDocument)).toThrow('Couldn\'t find server with name myserver.');
233
- });
234
-
235
- it('Validation throw error if given protocol is not supported by template', () => {
236
- const templateParams = {
237
- server: 'dummy-mqtt'
238
- };
239
- const templateConfig = {
240
- ...v2TemplateConfig,
241
- supportedProtocols: ['myprotocol'],
242
- parameters: {
243
- server: {
244
- description: ''
245
- }
246
- }
247
- };
248
-
249
- expect(() => validateTemplateConfig(templateConfig, templateParams, asyncapiDocument)).toThrow('Server "dummy-mqtt" uses the mqtt protocol but this template only supports the following ones: myprotocol.');
250
- });
251
- });
252
-
253
- describe('should work with v2 apiVersion', () => {
254
- let asyncapiDocument;
255
- const v2TemplateConfig = {apiVersion: 'v2'};
256
- beforeAll(async () => {
257
- const { document } = await parse(dummyYAML, {}, {templateConfig: v2TemplateConfig});
258
- asyncapiDocument = document;
259
- });
260
-
261
- it('Validation throw error if specified server is not in asyncapi document', () => {
262
- const templateParams = {
263
- server: 'myserver'
264
- };
265
- const templateConfig = {
266
- ...v2TemplateConfig,
267
- parameters: {
268
- server: {
269
- description: ''
270
- }
271
- }
272
- };
273
-
274
- expect(() => validateTemplateConfig(templateConfig, templateParams, asyncapiDocument)).toThrow('Couldn\'t find server with name myserver.');
275
- });
276
-
277
- it('Validation throw error if given protocol is not supported by template', () => {
278
- const templateParams = {
279
- server: 'dummy-mqtt'
280
- };
281
- const templateConfig = {
282
- ...v2TemplateConfig,
283
- supportedProtocols: ['myprotocol'],
284
- parameters: {
285
- server: {
286
- description: ''
287
- }
288
- }
289
- };
290
-
291
- expect(() => validateTemplateConfig(templateConfig, templateParams, asyncapiDocument)).toThrow('Server "dummy-mqtt" uses the mqtt protocol but this template only supports the following ones: myprotocol.');
292
- });
293
- });
294
- });
@@ -1,3 +0,0 @@
1
- npmRegistries:
2
- "http://localhost:4873/":
3
- npmAuthToken: LwRGijjh4ZHXm+Q3FthZhA==
@@ -1,8 +0,0 @@
1
- It is a test project where AsyncAPI Generator and test template are used as Node.js dependencies.
2
- The purpose of this project is to test AsyncAPI Generator library use case outside the Generator code base.
3
-
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,16 +0,0 @@
1
- services:
2
- verdaccio:
3
- image: verdaccio/verdaccio:5
4
- ports:
5
- - '4873:4873'
6
- volumes:
7
- - './verdaccio:/verdaccio/conf'
8
-
9
- test-project:
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"]
@@ -1,24 +0,0 @@
1
- {
2
- "description": "Test project. More info in the readme.",
3
- "scripts": {
4
- "test": "npm run test:cleanup && npm run test:project && npm run test:global && npm run test:registry",
5
- "test:project:A": "jest --testNamePattern='Test A' --detectOpenHandles --testPathPattern=test-project/test-project --modulePathIgnorePatterns='./__mocks__'",
6
- "test:project:B": "jest --testNamePattern='Test B' --detectOpenHandles --testPathPattern=test-project/test-project --modulePathIgnorePatterns='./__mocks__'",
7
- "test:project:C": "jest --testNamePattern='Test C' --detectOpenHandles --testPathPattern=test-project/test-project --modulePathIgnorePatterns='./__mocks__'",
8
- "test:global": "jest --detectOpenHandles --testPathPattern=test-global --modulePathIgnorePatterns='./__mocks__'",
9
- "test:registry:arg": "jest --testNamePattern='argument' --detectOpenHandles --testPathPattern=test-registry --modulePathIgnorePatterns='./__mocks__'",
10
- "test:registry:npm-config": "jest --testNamePattern='npm config' --detectOpenHandles --testPathPattern=test-registry --modulePathIgnorePatterns='./__mocks__'",
11
- "test:cleanup": "rimraf \"../temp\""
12
- },
13
- "devDependencies": {
14
- "jest": "28.1.3",
15
- "rimraf": "3.0.2"
16
- },
17
- "jest": {
18
- "moduleNameMapper": {
19
- "^nimma/legacy$": "<rootDir>/../../../../node_modules/nimma/dist/legacy/cjs/index.js",
20
- "^nimma/(.*)": "<rootDir>/../../../../node_modules/nimma/dist/cjs/$1",
21
- "^@asyncapi/nunjucks-filters$": "<rootDir>/../../../nunjucks-filters"
22
- }
23
- }
24
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
- const { readFile } = require('fs').promises;
6
- const path = require('path');
7
- const Generator = require('@asyncapi/generator');
8
- const dummySpecPath = path.resolve(__dirname, '../docs/dummy.yml');
9
- const templateName = 'react-template';
10
- const tempOutputResults = '../temp/integrationTestResult';
11
- const fileToCheck = 'test-file.md';
12
- const logMessage = require('../../lib/logMessages');
13
- const newContentNotExpectedInTest = 'new content';
14
- console.log = jest.fn();
15
-
16
- describe('Testing if markdown was generated using global template', () => {
17
- jest.setTimeout(1000000);
18
-
19
- it('generated markdown should not contain information that was added to template after it was installed globally', async () => {
20
- //you always want to generate to new directory to make sure test runs in clear environment
21
- const outputDir = path.resolve(tempOutputResults, Math.random().toString(36).substring(7));
22
-
23
- //we setup generator using template name, not path, without explicitly running installation
24
- //generator picks up template that is already in node_modules as it was installed before as node dependency in global packages location
25
- const generator = new Generator(templateName, outputDir, { forceWrite: true, debug: true, templateParams: { version: 'v1', mode: 'production' } });
26
- await generator.generateFromFile(dummySpecPath);
27
-
28
- const file = await readFile(path.join(outputDir, fileToCheck), 'utf8');
29
- const isNewContentThere = file.includes(newContentNotExpectedInTest);
30
-
31
- //global template was not modified so it should not contain new content after template modification
32
- expect(isNewContentThere).toStrictEqual(false);
33
- //we make sure that logs indicate that global package was used
34
- expect(console.log).toHaveBeenCalledWith(logMessage.templateNotFound(templateName));
35
- expect(console.log).toHaveBeenCalledWith(logMessage.templateVersion('0.0.1'));
36
- });
37
- });
@@ -1,102 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
- const { readFile } = require('fs').promises;
6
- const path = require('path');
7
- const Generator = require('@asyncapi/generator');
8
- const dummySpecPath = path.resolve(__dirname, '../docs/dummy.yml');
9
- const templateLocation = path.resolve(__dirname,'../test-templates/react-template');
10
- const templateName = 'react-template';
11
- const tempOutputResults = path.resolve(__dirname, 'output');
12
- const fileToCheck = 'test-file.md';
13
- const source = path.join(__dirname, 'node_modules', templateName);
14
- const logMessage = require('../../lib/logMessages.js');
15
- const newContentNotExpectedInTest = 'new content';
16
- const version = '0.0.1';
17
-
18
- const originalConsoleLog = console.log;
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
- });
25
- describe('Testing if markdown was generated with proper version of the template', () => {
26
- jest.setTimeout(1000000);
27
- it('Test A - generated markdown should not contain new content in modified template', async () => {
28
- //we setup generator using template name, not path, without explicitly running installation
29
- //generator picks up template that is already in node_modules as it was installed before as node dependency
30
- //it was installed before triggering test in test.sh
31
- const generator = new Generator(templateName, tempOutputResults, { forceWrite: true, debug: true, templateParams: { version: 'v1', mode: 'production' } });
32
- await generator.generateFromFile(dummySpecPath);
33
-
34
- const file = await readFile(path.join(tempOutputResults, fileToCheck), 'utf8');
35
- const isNewContentThere = file.includes(newContentNotExpectedInTest);
36
-
37
- //we make sure that markdown file doesn't contain new content as old version of template do not have it
38
- expect(isNewContentThere).toStrictEqual(false);
39
- //we make sure that logs do not indicate that new installation is started
40
- expect(console.log).not.toHaveBeenCalledWith(logMessage.installationDebugMessage(logMessage.TEMPLATE_INSTALL_FLAG_MSG));
41
- expect(console.log).toHaveBeenCalledWith(logMessage.templateSource(source));
42
- expect(console.log).toHaveBeenCalledWith(logMessage.templateVersion(version));
43
- });
44
-
45
- it('Test B - generated markdown should contain new content because of explicit fresh installation of different template version (install: true)', async () => {
46
- const templateVersion = '0.0.2';
47
-
48
- const generator = new Generator(`${templateName}@${templateVersion}`, tempOutputResults, { compile: true, forceWrite: true, install: true, debug: true, templateParams: { version: 'v1', mode: 'production' } });
49
- await generator.generateFromFile(dummySpecPath);
50
-
51
- const file = await readFile(path.join(tempOutputResults, fileToCheck), 'utf8');
52
- const isNewContentThere = file.includes(newContentNotExpectedInTest);
53
-
54
- //in 0.0.2 version of template there is a new content as in test.sh we made sure new template version has new content not present in 0.0.1
55
- expect(isNewContentThere).toStrictEqual(true);
56
- expect(console.log).toHaveBeenCalledWith(logMessage.installationDebugMessage(logMessage.TEMPLATE_INSTALL_FLAG_MSG));
57
- expect(console.log).toHaveBeenCalledWith(logMessage.templateVersion(templateVersion));
58
- });
59
-
60
- it('Test C - generated markdown should not contain new content of template because local version of the template is old and does not have new content (with and without install:true)', async () => {
61
- let file;
62
- let isNewContentThere;
63
-
64
- //we need arborist to perform installation of local template
65
- const Arborist = require('@npmcli/arborist');
66
-
67
- //we need to install local template before we can use it
68
- const arb = new Arborist({
69
- path: templateLocation
70
- });
71
-
72
- await arb.reify({
73
- save: false
74
- });
75
-
76
- //run generation by passing path to local template without passing install flag, sources should be taken from local path
77
- const generatorWithoutInstallFlag = new Generator(templateLocation, tempOutputResults, { forceWrite: true, debug: true, templateParams: { version: 'v1', mode: 'production' } });
78
- await generatorWithoutInstallFlag.generateFromFile(dummySpecPath);
79
-
80
- file = await readFile(path.join(tempOutputResults, fileToCheck), 'utf8');
81
- isNewContentThere = file.includes(newContentNotExpectedInTest);
82
-
83
- //we make sure that markdown file doesn't contain new content as old version of template do not have it
84
- expect(isNewContentThere).toStrictEqual(false);
85
- expect(console.log).toHaveBeenCalledWith(logMessage.templateSource(templateLocation));
86
- expect(console.log).toHaveBeenCalledWith(logMessage.templateVersion(version));
87
- expect(console.log).toHaveBeenCalledWith(logMessage.NODE_MODULES_INSTALL);
88
-
89
- //run generation by passing path to local template and passing install flag, sources should be taken from local path and simlink created
90
- const generatorWithInstallFlag = new Generator(templateLocation, tempOutputResults, { install: true, forceWrite: true, debug: true, templateParams: { version: 'v1', mode: 'production' } });
91
- await generatorWithInstallFlag.generateFromFile(dummySpecPath);
92
-
93
- file = await readFile(path.join(tempOutputResults, fileToCheck), 'utf8');
94
- isNewContentThere = file.includes(newContentNotExpectedInTest);
95
-
96
- //we make sure that markdown file doesn't contain new content as old version of template do not have it
97
- expect(isNewContentThere).toStrictEqual(false);
98
- expect(console.log).toHaveBeenCalledWith(logMessage.installationDebugMessage(logMessage.TEMPLATE_INSTALL_FLAG_MSG));
99
- expect(console.log).toHaveBeenCalledWith(logMessage.templateVersion(version));
100
- expect(console.log).toHaveBeenCalledWith(logMessage.NPM_INSTALL_TRIGGER);
101
- });
102
- });
@@ -1,62 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
- const { readFile } = require('fs').promises;
6
- const path = require('path');
7
- const Generator = require('@asyncapi/generator');
8
- const dummySpecPath = path.resolve(__dirname, '../docs/dummy.yml');
9
- const tempOutputResults = path.resolve(__dirname, 'output');
10
-
11
- // Save the original console.log
12
- const originalConsoleLog = console.log;
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
- });
19
- describe('Integration testing generateFromFile() to make sure the template can be download from the private repository from argument', () => {
20
- jest.setTimeout(1000000);
21
-
22
- it('generated using private registory', async () => {
23
- const generator = new Generator('react-template', tempOutputResults,
24
- {
25
- compile: true,
26
- debug: true,
27
- install: true,
28
- forceWrite: true,
29
- templateParams: { version: 'v1', mode: 'production' },
30
- registry: {
31
- url: 'http://verdaccio:4873',
32
- auth: 'YWRtaW46bmltZGE=' // base64 encoded username and password represented as admin:nimda
33
-
34
- }
35
- });
36
-
37
- await generator.generateFromFile(dummySpecPath);
38
-
39
- const file = await readFile(path.join(tempOutputResults, 'test-file.md'), 'utf8');
40
- expect(file).toContain('new content');
41
- expect(console.log).toHaveBeenCalledWith('Using npm registry http://verdaccio:4873 and authorization type //verdaccio:4873:_auth to handle template installation.');
42
- });
43
- });
44
-
45
- describe('Integration testing generateFromFile() to make sure the template can be download from the private repository from npm config', () => {
46
- jest.setTimeout(1000000);
47
- it('generated using private registory from npm config', async () => {
48
- const generator = new Generator('react-template', tempOutputResults,
49
- {
50
- compile: true,
51
- debug: true,
52
- install: true,
53
- forceWrite: true,
54
- templateParams: { version: 'v1', mode: 'production' }
55
- });
56
-
57
- await generator.generateFromFile(dummySpecPath);
58
-
59
- const file = await readFile(path.join(tempOutputResults, 'test-file.md'), 'utf8');
60
- expect(file).toContain('new content');
61
- });
62
- });
@@ -1,104 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Function to install and test a specific project
4
- function test_project {
5
- echo "##########
6
- Starting standard project test
7
- ##########"
8
- # Copy to isolated env
9
- cp -r /app /testprojectA
10
- cd /testprojectA/apps/generator/test/test-project
11
- npm install react-template@0.0.1 # installing old version of template
12
- npm run test:project:A
13
- # Copy to isolated env
14
- cp -r /app /testprojectB
15
- cd /testprojectB/apps/generator/test/test-project
16
- npm run test:project:B
17
- # Copy to isolated env
18
- cp -r /app /testprojectC
19
- cd /testprojectC/apps/generator/test/test-project
20
- npm run test:project:C
21
- echo "##########
22
- Starting test of global template installation
23
- ##########"
24
- cp -r /app /testprojectglobal
25
- cd /testprojectglobal/apps/generator/test/test-project
26
- # Installing test template globally before global tests
27
- npm install -g react-template@0.0.1
28
- npm run test:global
29
- }
30
-
31
- # Function to test the registry
32
- function test_registry {
33
- echo "##########
34
- Starting registry test
35
- ##########"
36
- echo "0.0.0.0 registry.npmjs.org" > /etc/hosts # no access to registry.npmjs.org directly
37
- cp -r /app /testprojectregistry
38
- cd /testprojectregistry/apps/generator/test/test-project
39
-
40
- npm config delete registry #making sure we do not have verdaccio details in config and test really use library arguments
41
- npm run test:registry:arg
42
-
43
- #Now running test for npm config support
44
- npm config set registry http://verdaccio:4873
45
- #base64 encoded username and password represented as admin:nimda
46
- npm config set -- //verdaccio:4873/:_auth=YWRtaW46bmltZGE=
47
- npm run test:registry:npm-config
48
- }
49
-
50
- # Required by GitHub Actions
51
- sudo chown -R 1001:121 "/root/.npm"
52
-
53
- # Always run these steps
54
- cd /app
55
-
56
- echo "##########
57
- Running installation in root
58
- ##########"
59
- npm install
60
- cd apps/generator/test/test-project
61
-
62
- echo "##########
63
- Running installation in test-project
64
- ##########"
65
- npm install
66
- npm install --install-links ../.. #installing generator without symlink
67
-
68
- echo "##########
69
- Publish test template to local npm-verdaccio
70
- ##########"
71
- npm config set -- //verdaccio:4873/:_auth=YWRtaW46bmltZGE=
72
- npm config set registry http://verdaccio:4873
73
-
74
- echo "##########
75
- Publish @asyncapi/generator-components to local npm-verdaccio
76
- ##########"
77
- npm publish ../../../../packages/components
78
-
79
- echo "##########
80
- Publishing the correct template as 0.0.1
81
- ##########"
82
- npm publish ../test-templates/react-template
83
-
84
- echo "##########
85
- Publishing new version as 0.0.2
86
- ##########"
87
- cp -r ../test-templates/react-template ../test-templates/react-template-v2 #we need copy so later in project tests we still have access to old v1 template
88
- new_version="0.0.2"
89
- sed -i 's/"version": "[^"]*"/"version": "'"$new_version"'"/' ../test-templates/react-template-v2/package.json
90
- new_content="import { File, Text } from '@asyncapi/generator-react-sdk'; export default function({ asyncapi, params }) { return ( <File name='test-file.md'> <Text>new content</Text> </File> ); }"
91
- echo "$new_content" > ../test-templates/react-template-v2/template/test-file.md.js
92
- npm publish ../test-templates/react-template-v2
93
-
94
- # Run the functions based on the provided arguments
95
- case "$1" in
96
- "test-project")
97
- test_project
98
- test_registry
99
- ;;
100
- *)
101
- echo "Invalid argument. Supported arguments: test-project"
102
- exit 1
103
- ;;
104
- esac
@@ -1,22 +0,0 @@
1
- storage: ../storage
2
- auth:
3
- htpasswd:
4
- file: ./htpasswd
5
- algorithm: bcrypt
6
- uplinks:
7
- npmjs:
8
- url: https://registry.npmjs.org/
9
- packages:
10
- "react-template":
11
- access: admin
12
- publish: admin
13
- "@asyncapi/generator-components":
14
- access: admin
15
- publish: admin
16
- "!react-template":
17
- access: admin
18
- proxy: npmjs
19
- "!@asyncapi/generator-components":
20
- access: admin
21
- proxy: npmjs
22
- log: { type: stdout, format: pretty, level: error }