diff --git a/.gitignore b/.gitignore index cc5d70dff9..3c27c8bc55 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,4 @@ test/test-project/node_modules/* test/test-project/node_modules/@asyncapi/* !test/test-project/node_modules/@asyncapi/html-template/ test/test-project/package-lock.json -test/test-project/verdaccio/storage/.verdaccio-db.json \ No newline at end of file +test/test-project/verdaccio/storage/ \ No newline at end of file diff --git a/lib/generator.js b/lib/generator.js index d8c3b0824b..53c155e036 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -374,6 +374,13 @@ class Generator { if (!document) { const err = new Error('Input is not a correct AsyncAPI document so it cannot be processed.'); err.diagnostics = diagnostics; + for (const diag of diagnostics) { + console.error( + `Diagnostic err: ${diag['message']} in path ${JSON.stringify(diag['path'])} starting `+ + `L${diag['range']['start']['line'] + 1} C${diag['range']['start']['character']}, ending `+ + `L${diag['range']['end']['line'] + 1} C${diag['range']['end']['character']}` + ); + } throw err; } else { this.asyncapi = document; @@ -1055,4 +1062,4 @@ class Generator { Generator.DEFAULT_TEMPLATES_DIR = DEFAULT_TEMPLATES_DIR; Generator.TRANSPILED_TEMPLATE_LOCATION = TRANSPILED_TEMPLATE_LOCATION; -module.exports = Generator; \ No newline at end of file +module.exports = Generator; diff --git a/test/test-project/test-registry.test.js b/test/test-project/test-registry.test.js index 7d07fa8d93..a886fe50d5 100644 --- a/test/test-project/test-registry.test.js +++ b/test/test-project/test-registry.test.js @@ -4,31 +4,29 @@ const { readFile } = require('fs').promises; const path = require('path'); -const Generator = require('@asyncapi/generator'); -const templateName = '@asyncapi/html-template'; -const tempOutputResults = '../temp/integrationTestResult'; +const Generator = require('../lib/generator'); +const dummySpecPath = path.resolve(__dirname, './docs/dummy.yml'); +const crypto = require('crypto'); +const mainTestResultPath = 'test/temp/integrationTestResult'; +//we do not want to download chromium for html-template if it is not needed +process.env['PUPPETEER_SKIP_CHROMIUM_DOWNLOAD'] = true; -console.log = jest.fn(); - -describe('Testing if html template can fetch from private repository', () => { - jest.setTimeout(200000); +describe('Integration testing generateFromFile() to make sure the result of the generation is not changend comparing to snapshot', () => { + const generateFolderName = () => { + //you always want to generate to new directory to make sure test runs in clear environment + return path.resolve(mainTestResultPath, crypto.randomBytes(4).toString('hex')); + }; - let ArboristMock; - let arboristMock; + jest.setTimeout(60000); - beforeEach(() => { - ArboristMock = require('@npmcli/arborist'); - arboristMock = new ArboristMock(); + it('generated using private registory', async () => { + const outputDir = generateFolderName(); + const generator = new Generator('@asyncapi/html-template', outputDir, + { forceWrite: true, templateParams: { singleFile: true }, + registry: {url: 'http://localhost:4873/', username: 'admin', password: 'nimbda'}}); + await generator.generateFromFile(dummySpecPath); + const file = await readFile(path.join(outputDir, 'index.html'), 'utf8'); + expect(file).toMatchSnapshot(); }); - it('fetching the html template from the private repository', async () => { - //you always want to generate to new directory to make sure test runs in clear environment - const outputDir = path.resolve(tempOutputResults, Math.random().toString(36).substring(7)); - //we setup the generator to pick the template file that is present in the private repository - const generator = new Generator(templateName, outputDir, { forceWrite: true, debug: true, templateParams: { singleFile: true }, registry: {url: 'http://localhost:4873/', username: 'admin', password: 'nimda'}}); - - await generator.installTemplate(); - - expect(arboristMock.reify).toHaveBeenCalledTimes(1); - }); });