From dc25630ef2a444b78f75ce6b8a67f482ab99ea96 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 15 Dec 2019 23:04:11 +0100 Subject: [PATCH] test: add test for listen port --- test/e2e-cli/config/default.yaml | 6 ++-- test/e2e-cli/test/core/listen.spec.ts | 41 +++++++++++++++++++++++++++ test/e2e-cli/utils/web.ts | 23 +++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 test/e2e-cli/test/core/listen.spec.ts create mode 100644 test/e2e-cli/utils/web.ts diff --git a/test/e2e-cli/config/default.yaml b/test/e2e-cli/config/default.yaml index 39ec46bc4..e107aea83 100644 --- a/test/e2e-cli/config/default.yaml +++ b/test/e2e-cli/config/default.yaml @@ -14,7 +14,7 @@ web: title: verdaccio-default uplinks: - npmjs: + local: url: http://localhost:4873 logs: @@ -25,11 +25,11 @@ packages: access: $all publish: $anonymous unpublish: $authenticated - proxy: npmjs + proxy: local '**': access: $all publish: $all unpublish: $authenticated - proxy: npmjs + proxy: local _debug: true diff --git a/test/e2e-cli/test/core/listen.spec.ts b/test/e2e-cli/test/core/listen.spec.ts new file mode 100644 index 000000000..df92f546a --- /dev/null +++ b/test/e2e-cli/test/core/listen.spec.ts @@ -0,0 +1,41 @@ +import path from 'path'; +import fs from "fs"; +import {installVerdaccio} from "../__partials/npm_commands"; +import {spawnRegistry} from "../../utils/registry"; +import {callRegistry} from "../../utils/web"; + +describe('npm install', ()=> { + jest.setTimeout(90000); + const port = '9012'; + + // @ts-ignore + const tempRootFolder = global.__namespace.getItem('dir-root'); + const verdaccioInstall = path.join(tempRootFolder, 'verdaccio-root-install'); + let registryProcess; + const configPath = path.join(tempRootFolder, 'verdaccio.yaml'); + + beforeAll(async () => { + await installVerdaccio(verdaccioInstall); + fs.copyFileSync(path.join(__dirname, '../../config/default.yaml'), configPath); + }); + + test('should match the listing port and load metadata', async () => { + const pathVerdaccioModule = require.resolve('verdaccio/bin/verdaccio', { + paths: [verdaccioInstall] + }); + + registryProcess = await spawnRegistry(pathVerdaccioModule, + ['-c', configPath, '-l', port], + { cwd: verdaccioInstall, silent: true } + ); + + const body = await callRegistry(`http://localhost:${port}/verdaccio`); + const parsedBody = JSON.parse(body); + + expect(parsedBody.name).toEqual('verdaccio'); + }); + + afterAll(async () => { + registryProcess.kill(); + }); +}); diff --git a/test/e2e-cli/utils/web.ts b/test/e2e-cli/utils/web.ts new file mode 100644 index 000000000..e6d89f73a --- /dev/null +++ b/test/e2e-cli/utils/web.ts @@ -0,0 +1,23 @@ +import {IncomingMessage} from 'http'; +import request from 'request'; + + +export function callRegistry(url: string): Promise { + return new Promise((resolve, reject) => { + let options = { + url: url, + headers: { 'Accept': 'application/json' }, + }; + // @ts-ignore + request(options, (error: any, response: IncomingMessage, body: string) => { + if (error) { + reject(error); + // @ts-ignore + } else if (response.statusCode >= 400) { + reject(new Error(`Requesting "${url}" returned status code ${response.statusCode}.`)); + } else { + resolve(body); + } + }); + }); +}