Skip to content

Commit

Permalink
Changed testing
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushRedHat committed Jan 9, 2024
1 parent 777108e commit 650303e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
test/test-project/verdaccio/storage/
9 changes: 8 additions & 1 deletion lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1055,4 +1062,4 @@ class Generator {
Generator.DEFAULT_TEMPLATES_DIR = DEFAULT_TEMPLATES_DIR;
Generator.TRANSPILED_TEMPLATE_LOCATION = TRANSPILED_TEMPLATE_LOCATION;

module.exports = Generator;
module.exports = Generator;
42 changes: 20 additions & 22 deletions test/test-project/test-registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 650303e

Please sign in to comment.