0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-02-17 23:45:29 -05:00

test: add test for listen port

This commit is contained in:
Juan Picado @jotadeveloper 2019-12-15 23:04:11 +01:00
parent b6d2b2690a
commit dc25630ef2
No known key found for this signature in database
GPG key ID: 15AA875EF3768142
3 changed files with 67 additions and 3 deletions

View file

@ -14,7 +14,7 @@ web:
title: verdaccio-default title: verdaccio-default
uplinks: uplinks:
npmjs: local:
url: http://localhost:4873 url: http://localhost:4873
logs: logs:
@ -25,11 +25,11 @@ packages:
access: $all access: $all
publish: $anonymous publish: $anonymous
unpublish: $authenticated unpublish: $authenticated
proxy: npmjs proxy: local
'**': '**':
access: $all access: $all
publish: $all publish: $all
unpublish: $authenticated unpublish: $authenticated
proxy: npmjs proxy: local
_debug: true _debug: true

View file

@ -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();
});
});

23
test/e2e-cli/utils/web.ts Normal file
View file

@ -0,0 +1,23 @@
import {IncomingMessage} from 'http';
import request from 'request';
export function callRegistry(url: string): Promise<string> {
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);
}
});
});
}