From 7d7be4eae179f670088169bfbc554eec6717673c Mon Sep 17 00:00:00 2001 From: aayushRedHat Date: Wed, 10 Jan 2024 20:35:43 +0530 Subject: [PATCH] update requried changes --- .sonarcloud.properties | 2 +- lib/generator.js | 30 ++++++++++++------------- test/test-project/docker-compose.yml | 2 +- test/test-project/test-registry.test.js | 7 +++--- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.sonarcloud.properties b/.sonarcloud.properties index ffa559681..208c092d7 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -1,2 +1,2 @@ #we need to explicitly exclude them as some are commit to the repo -sonar.exclusions=test/**/*, test/test-project/** +sonar.exclusions=test/**/* diff --git a/lib/generator.js b/lib/generator.js index 53c155e03..0ecdbbc11 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -43,7 +43,7 @@ const DEFAULT_TEMPLATES_DIR = path.resolve(ROOT_DIR, 'node_modules'); const TRANSPILED_TEMPLATE_LOCATION = '__transpiled'; const TEMPLATE_CONTENT_DIRNAME = 'template'; -const GENERATOR_OPTIONS = ['debug', 'disabledHooks', 'entrypoint', 'forceWrite', 'install', 'noOverwriteGlobs', 'output', 'templateParams', 'mapBaseUrlToFolder','url','username','password','token','registry']; +const GENERATOR_OPTIONS = ['debug', 'disabledHooks', 'entrypoint', 'forceWrite', 'install', 'noOverwriteGlobs', 'output', 'templateParams', 'mapBaseUrlToFolder', 'url', 'username', 'password', 'token', 'registry']; const logMessage = require('./logMessages'); const shouldIgnoreFile = filePath => @@ -90,15 +90,15 @@ class Generator { * @param {String} [options.registry.password] Optional parameter to pass npm registry base64 encoded password * @param {String} [options.registry.token] Optional parameter to pass npm registry auth token */ - + constructor(templateName, targetDir, { templateParams = {}, entrypoint, noOverwriteGlobs, disabledHooks, output = 'fs', forceWrite = false, install = false, debug = false, mapBaseUrlToFolder = {}, registry = {}} = {}) { const options = arguments[arguments.length - 1]; this.verifyoptions(options); if (!templateName) throw new Error('No template name has been specified.'); if (!entrypoint && !targetDir) throw new Error('No target directory has been specified.'); if (!['fs', 'string'].includes(output)) throw new Error(`Invalid output type ${output}. Valid values are 'fs' and 'string'.`); - - /** @type {RegistryOptions} Npm registry information. */ + + /** @type {Object} Npm registry information. */ this.registry = registry; /** @type {String} Name of the template to generate. */ this.templateName = templateName; @@ -144,17 +144,17 @@ class Generator { /** * Check if the Registry Options are valid or not. - * + * * @private * @param {Object} invalidRegOptions Invalid Registry Options. - * + * */ verifyoptions(Options) { - if (typeof Options !== 'object') return []; - const invalidOptions = Object.keys(Options).filter(param => !GENERATOR_OPTIONS.includes(param)); - - if (invalidOptions.length > 0) { + if (typeof Options !== 'object') return []; + const invalidOptions = Object.keys(Options).filter(param => !GENERATOR_OPTIONS.includes(param)); + + if (invalidOptions.length > 0) { throw new Error(`These options are not supported by the generator: ${invalidOptions.join(', ')}`); } } @@ -166,7 +166,7 @@ class Generator { * @example * await generator.generate(myAsyncAPIdocument); * console.log('Done!'); - * + * * @example * generator * .generate(myAsyncAPIdocument) @@ -224,9 +224,9 @@ class Generator { * @example * const generator = new Generator(); * await generator.setupOutput(); - * + * * @async - * + * * @throws {Error} If 'output' is set to 'string' without providing 'entrypoint'. */ async setupOutput() { @@ -523,7 +523,7 @@ class Generator { /** * @private - * @param {Object} arbOptions ArbOptions to intialise the Registry details. + * @param {Object} arbOptions ArbOptions to intialise the Registry details. */ initialiseArbOptions(arbOptions) { if (this.registry.url) arbOptions.registry = this.registry.url; @@ -568,7 +568,7 @@ class Generator { const arbOptions = { path: ROOT_DIR, }; - + if (this.registry) { this.initialiseArbOptions(arbOptions); } diff --git a/test/test-project/docker-compose.yml b/test/test-project/docker-compose.yml index 8b5d65c2e..c7c6be45a 100644 --- a/test/test-project/docker-compose.yml +++ b/test/test-project/docker-compose.yml @@ -11,7 +11,7 @@ services: test: privileged: true - image: "node:18" + image: "node:${NODE_IMAGE_TAG}" volumes: - ../../:/app command: bash /app/test/test-project/test.sh \ No newline at end of file diff --git a/test/test-project/test-registry.test.js b/test/test-project/test-registry.test.js index 9e0fd65c4..79bacf693 100644 --- a/test/test-project/test-registry.test.js +++ b/test/test-project/test-registry.test.js @@ -8,8 +8,6 @@ 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; describe('Integration testing generateFromFile() to make sure the template can be download from the private repository.', () => { const generateFolderName = () => { @@ -21,11 +19,12 @@ describe('Integration testing generateFromFile() to make sure the template can b it('generated using private registory', async () => { const outputDir = generateFolderName(); - const generator = new Generator('@asyncapi/html-template', outputDir, + const generator = new Generator('@asyncapi/html-template@0.16.0', 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(); + expect(file).toBeDefined(); + expect(file.length).toBeGreaterThan(0); }); });