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:
parent
b6d2b2690a
commit
dc25630ef2
3 changed files with 67 additions and 3 deletions
|
@ -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
|
||||
|
|
41
test/e2e-cli/test/core/listen.spec.ts
Normal file
41
test/e2e-cli/test/core/listen.spec.ts
Normal 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
23
test/e2e-cli/utils/web.ts
Normal 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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Add table
Reference in a new issue