From b6d2b2690aa265e74adc71b631d784a68731b1d2 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 15 Dec 2019 22:18:47 +0100 Subject: [PATCH] chore: add info test --- test/e2e-cli/setup/setup.ts | 3 +- test/e2e-cli/test/__partials/npm_commands.ts | 4 +-- test/e2e-cli/test/core/info.spec.ts | 29 ++++++++++++++++++++ test/e2e-cli/test/install/install.spec.ts | 13 ++------- test/e2e-cli/utils/process.ts | 11 ++++++-- 5 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 test/e2e-cli/test/core/info.spec.ts diff --git a/test/e2e-cli/setup/setup.ts b/test/e2e-cli/setup/setup.ts index 3f60036ab..27ac7b771 100644 --- a/test/e2e-cli/setup/setup.ts +++ b/test/e2e-cli/setup/setup.ts @@ -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 diff --git a/test/e2e-cli/test/__partials/npm_commands.ts b/test/e2e-cli/test/__partials/npm_commands.ts index 104137f62..9f5515ce4 100644 --- a/test/e2e-cli/test/__partials/npm_commands.ts +++ b/test/e2e-cli/test/__partials/npm_commands.ts @@ -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'); } diff --git a/test/e2e-cli/test/core/info.spec.ts b/test/e2e-cli/test/core/info.spec.ts new file mode 100644 index 000000000..d5fa8047a --- /dev/null +++ b/test/e2e-cli/test/core/info.spec.ts @@ -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(); + }); +}); diff --git a/test/e2e-cli/test/install/install.spec.ts b/test/e2e-cli/test/install/install.spec.ts index 9e949af6c..72da34c68 100644 --- a/test/e2e-cli/test/install/install.spec.ts +++ b/test/e2e-cli/test/install/install.spec.ts @@ -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(); }); diff --git a/test/e2e-cli/utils/process.ts b/test/e2e-cli/utils/process.ts index 6b4d07377..6b50fce94 100644 --- a/test/e2e-cli/utils/process.ts +++ b/test/e2e-cli/utils/process.ts @@ -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); }