mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
chore: add info test
This commit is contained in:
parent
0027566308
commit
b6d2b2690a
5 changed files with 44 additions and 16 deletions
|
@ -21,7 +21,8 @@ module.exports = async () => {
|
|||
global.registryProcess = spawn(
|
||||
'node',
|
||||
[require.resolve('verdaccio/bin/verdaccio'), '-c', './verdaccio.yaml'],
|
||||
{ cwd: tempRoot, stdio: 'inherit' },
|
||||
// @ts-ignore
|
||||
{ cwd: tempRoot, silence: true },
|
||||
);
|
||||
|
||||
// publish current build version on local registry
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { npm } from '../../utils/process';
|
||||
import { silentNpm } from '../../utils/process';
|
||||
|
||||
export function installVerdaccio(verdaccioInstall) {
|
||||
return npm('install', '--prefix', verdaccioInstall, 'verdaccio', '--registry' ,'http://localhost:4873', '--no-package-lock');
|
||||
return silentNpm('install', '--prefix', verdaccioInstall, 'verdaccio', '--registry' ,'http://localhost:4873', '--no-package-lock');
|
||||
}
|
||||
|
|
29
test/e2e-cli/test/core/info.spec.ts
Normal file
29
test/e2e-cli/test/core/info.spec.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import path from 'path';
|
||||
import {runVerdaccio} from '../../utils/process';
|
||||
import {installVerdaccio} from "../__partials/npm_commands";
|
||||
|
||||
describe('verdaccio info', ()=> {
|
||||
jest.setTimeout(90000);
|
||||
// @ts-ignore
|
||||
const tempRootFolder = global.__namespace.getItem('dir-root');
|
||||
const verdaccioInstall = path.join(tempRootFolder, 'verdaccio-root-info');
|
||||
let registryProcess;
|
||||
|
||||
beforeAll(async () => {
|
||||
await installVerdaccio(verdaccioInstall);
|
||||
});
|
||||
|
||||
|
||||
test('should run verdaccio info command', async () => {
|
||||
const pathVerdaccioModule = require.resolve('verdaccio/bin/verdaccio', {
|
||||
paths: [verdaccioInstall]
|
||||
});
|
||||
const hasMatch = await runVerdaccio(pathVerdaccioModule, verdaccioInstall, ['--info'], /Environment/);
|
||||
|
||||
expect(hasMatch.ok).toBeTruthy();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
registryProcess.kill();
|
||||
});
|
||||
});
|
|
@ -6,15 +6,6 @@ import {execAndWaitForOutputToMatch} from '../../utils/process';
|
|||
import {installVerdaccio} from "../__partials/npm_commands";
|
||||
import {expectFileToExist} from "../../utils/expect";
|
||||
|
||||
function testExample() {
|
||||
console.log('running example');
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
export default async function() {
|
||||
await testExample();
|
||||
}
|
||||
|
||||
describe('npm install', ()=> {
|
||||
jest.setTimeout(90000);
|
||||
const port = '9011';
|
||||
|
@ -36,13 +27,13 @@ describe('npm install', ()=> {
|
|||
});
|
||||
registryProcess = await spawnRegistry(pathVerdaccioModule,
|
||||
['-c', configPath, '-l', port],
|
||||
{ cwd: verdaccioInstall, silent: false }
|
||||
{ cwd: verdaccioInstall, silent: true }
|
||||
);
|
||||
});
|
||||
|
||||
test('should match on npm info verdaccio', async () => {
|
||||
// FIXME: not the best match, looking for a better way to match the terminal output
|
||||
const output = await execAndWaitForOutputToMatch('npm', ['info', 'verdaccio', '--registry' ,`http://localhost:${port}`], /verdaccio-4.3.5.tgz/);
|
||||
const output = await execAndWaitForOutputToMatch('npm', ['info', 'verdaccio', '--registry'], /A lightweight private npm proxy registry/);
|
||||
|
||||
expect(output.ok).toBeTruthy();
|
||||
});
|
||||
|
|
|
@ -28,23 +28,25 @@ export async function _exec(options, cmd, args) {
|
|||
if (options.silent) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.toString('utf-8')
|
||||
.split(/[\n\r]+/)
|
||||
.filter(line => line !== '')
|
||||
.forEach(line => console.log(' ' + line));
|
||||
});
|
||||
|
||||
childProcess.stderr.on('data', (data) => {
|
||||
stderr += data.toString('utf-8');
|
||||
if (options.silent) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.toString('utf-8')
|
||||
.split(/[\n\r]+/)
|
||||
.filter(line => line !== '')
|
||||
.forEach(line => console.error((' ' + line)));
|
||||
});
|
||||
|
||||
// Create the error here so the stack shows who called this function.
|
||||
const err = new Error(`Running "${cmd} ${args.join(' ')}" returned error code `);
|
||||
return new Promise((resolve, reject) => {
|
||||
childProcess.on('exit', (error) => {
|
||||
|
@ -59,6 +61,7 @@ export async function _exec(options, cmd, args) {
|
|||
if (options.waitForMatch) {
|
||||
const match = options.waitForMatch;
|
||||
childProcess.stdout.on('data', (data) => {
|
||||
// console.log("-->data==>", data.toString(), data.toString().match(match));
|
||||
if (data.toString().match(match)) {
|
||||
resolve({ok: true, stdout, stderr });
|
||||
}
|
||||
|
@ -77,7 +80,7 @@ export function execAndWaitForOutputToMatch(
|
|||
args: string[],
|
||||
match: RegExp,
|
||||
spawnOptions: SpawnOptions = {}): any {
|
||||
return _exec({ waitForMatch: match, ...spawnOptions }, cmd, args);
|
||||
return _exec({ waitForMatch: match, ...spawnOptions, silence: true }, cmd, args);
|
||||
}
|
||||
|
||||
|
||||
|
@ -85,6 +88,10 @@ export function npm(...args) {
|
|||
return _exec({}, 'npm', args);
|
||||
}
|
||||
|
||||
export function runVerdaccio(cmd, installation, args, match: RegExp): any {
|
||||
return _exec({ cwd: installation, silent: true, waitForMatch: match }, cmd, args);
|
||||
}
|
||||
|
||||
export function silentNpm(...args) {
|
||||
return _exec({silent: true}, 'npm', args);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue