From 7c2ed29d89d20d6334cdbd8d27d1b6de9e119829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierrick=20BOUL=C3=89?= Date: Mon, 11 Mar 2024 20:06:47 +0100 Subject: [PATCH] feat: Use npmcli config in asyncapi generator (npm config registry docker test) --- test/test-project/package.json | 3 +- test/test-project/test-registry.test.js | 49 +++++++++++++++++++------ test/test-project/test.sh | 11 +++++- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/test/test-project/package.json b/test/test-project/package.json index 0f33fb7e78..783ebd0114 100644 --- a/test/test-project/package.json +++ b/test/test-project/package.json @@ -6,7 +6,8 @@ "test:project:B": "jest --testNamePattern='Test B' --detectOpenHandles --testPathPattern=test-project/test-project --modulePathIgnorePatterns='./__mocks__'", "test:project:C": "jest --testNamePattern='Test C' --detectOpenHandles --testPathPattern=test-project/test-project --modulePathIgnorePatterns='./__mocks__'", "test:global": "jest --detectOpenHandles --testPathPattern=test-global --modulePathIgnorePatterns='./__mocks__'", - "test:registry": "jest --detectOpenHandles --testPathPattern=test-registry --modulePathIgnorePatterns='./__mocks__'", + "test:registry:arg": "jest --testNamePattern='argument' --detectOpenHandles --testPathPattern=test-registry --modulePathIgnorePatterns='./__mocks__'", + "test:registry:npm-config": "jest --testNamePattern='npm config' --detectOpenHandles --testPathPattern=test-registry --modulePathIgnorePatterns='./__mocks__'", "test:cleanup": "rimraf \"../temp\"" }, "dependencies": { diff --git a/test/test-project/test-registry.test.js b/test/test-project/test-registry.test.js index d3e7899c41..0edbab8945 100644 --- a/test/test-project/test-registry.test.js +++ b/test/test-project/test-registry.test.js @@ -11,7 +11,7 @@ const mainTestResultPath = 'test/temp/integrationTestResult'; process.env['PUPPETEER_SKIP_CHROMIUM_DOWNLOAD'] = true; console.log = jest.fn(); -describe('Integration testing generateFromFile() to make sure the template can be download from the private repository.', () => { +describe('Integration testing generateFromFile() to make sure the template can be download from the private repository from argument', () => { 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')); @@ -22,24 +22,51 @@ 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, - { + { debug: true, - install: true, - forceWrite: true, - templateParams: { - singleFile: true + install: true, + forceWrite: true, + templateParams: { + singleFile: true }, registry: { - url: 'http://verdaccio:4873', + url: 'http://verdaccio:4873', auth: 'YWRtaW46bmltZGE=' // base64 encoded username and password represented as admin:nimda - + } }); - + await generator.generateFromFile(dummySpecPath); - + const file = await readFile(path.join(outputDir, 'index.html'), 'utf8'); expect(file).toContain('Dummy example with all spec features included'); expect(console.log).toHaveBeenCalledWith('Using npm registry http://verdaccio:4873 and authorization type //verdaccio:4873:_auth to handle template installation.'); }); -}); \ No newline at end of file +}); + +describe('Integration testing generateFromFile() to make sure the template can be download from the private repository from npm config', () => { + 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')); + }; + + jest.setTimeout(1000000); + + it('generated using private registory from npm config', async () => { + const outputDir = generateFolderName(); + const generator = new Generator('@asyncapi/html-template', outputDir, + { + debug: true, + install: true, + forceWrite: true, + templateParams: { + singleFile: true + } + }); + + await generator.generateFromFile(dummySpecPath); + + const file = await readFile(path.join(outputDir, 'index.html'), 'utf8'); + expect(file).toContain('Dummy example with all spec features included'); + }); +}); diff --git a/test/test-project/test.sh b/test/test-project/test.sh index 1c1850c0b7..31891c8a42 100644 --- a/test/test-project/test.sh +++ b/test/test-project/test.sh @@ -35,9 +35,16 @@ function test_registry { echo "########## Starting registry test ##########" + echo "0.0.0.0 registry.npmjs.org" > /etc/hosts # no access to registry.npmjs.org directly cp -r /app /testprojectregistry cd /testprojectregistry/test/test-project - npm run test:registry + + npm run test:registry:arg + + npm config set registry http://verdaccio:4873 + #base64 encoded username and password represented as admin:nimda + npm config set -- //verdaccio:4873/:_auth=YWRtaW46bmltZGE= + npm run test:registry:npm-config } # Required by GitHub Actions @@ -67,4 +74,4 @@ case "$1" in echo "Invalid argument. Supported arguments: test-project" exit 1 ;; -esac \ No newline at end of file +esac