Skip to content

Commit

Permalink
feat: Use npmcli config in asyncapi generator (npm config registry do…
Browse files Browse the repository at this point in the history
…cker test)
  • Loading branch information
Pierrick BOULÉ committed Mar 19, 2024
1 parent c33ccae commit 619e7a8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
5 changes: 3 additions & 2 deletions test/test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -24,4 +25,4 @@
"^nimma/(.*)": "<rootDir>/../../node_modules/nimma/dist/cjs/$1"
}
}
}
}
49 changes: 38 additions & 11 deletions test/test-project/test-registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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.');
});
});
});

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');
});
});
11 changes: 9 additions & 2 deletions test/test-project/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,4 +74,4 @@ case "$1" in
echo "Invalid argument. Supported arguments: test-project"
exit 1
;;
esac
esac

0 comments on commit 619e7a8

Please sign in to comment.