mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
test: add test for install a package
This commit is contained in:
parent
e1685d205b
commit
582b19d02f
7 changed files with 61 additions and 47 deletions
|
@ -18,7 +18,7 @@ uplinks:
|
|||
url: http://localhost:4873
|
||||
|
||||
logs:
|
||||
- { type: stdout, format: pretty, level: info }
|
||||
- { type: stdout, format: pretty, level: warn }
|
||||
|
||||
packages:
|
||||
'@*/*':
|
||||
|
|
5
test/e2e-cli/test/__partials/npm_commands.ts
Normal file
5
test/e2e-cli/test/__partials/npm_commands.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { npm } from '../../utils/process';
|
||||
|
||||
export function installVerdaccio(verdaccioInstall) {
|
||||
return npm('install', '--prefix', verdaccioInstall, 'verdaccio', '--registry' ,'http://localhost:4873', '--no-package-lock');
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
import path from 'path';
|
||||
import { npm } from '../../utils/process';
|
||||
import fs from "fs";
|
||||
import * as __global from "../../utils/global";
|
||||
import {spawnRegistry} from "../../utils/registry";
|
||||
import {execAndWaitForOutputToMatch} from '../../utils/process';
|
||||
import {installVerdaccio} from "../__partials/npm_commands";
|
||||
import {expectFileToExist} from "../../utils/expect";
|
||||
|
||||
function testExample() {
|
||||
console.log('running example');
|
||||
|
@ -15,15 +17,16 @@ export default async function() {
|
|||
|
||||
describe('npm install', ()=> {
|
||||
jest.setTimeout(90000);
|
||||
const port = '9011';
|
||||
|
||||
// @ts-ignore
|
||||
const tempRootFolder = global.__namespace.getItem('dir-root');
|
||||
const verdaccioInstall = path.join(tempRootFolder, 'verdaccio-root-install');
|
||||
let registryProcess;
|
||||
|
||||
|
||||
beforeAll(async () => {
|
||||
const verdaccioInstall = path.join(tempRootFolder, 'verdaccio-root');
|
||||
await npm('install', '--prefix', verdaccioInstall, 'verdaccio', '--registry' ,'http://localhost:4873', '--no-package-lock');
|
||||
await installVerdaccio(verdaccioInstall);
|
||||
|
||||
const configPath = path.join(tempRootFolder, 'verdaccio.yaml');
|
||||
fs.copyFileSync(path.join(__dirname, '../../config/default.yaml'), configPath);
|
||||
// @ts-ignore
|
||||
|
@ -32,15 +35,27 @@ describe('npm install', ()=> {
|
|||
paths: [verdaccioInstall]
|
||||
});
|
||||
registryProcess = await spawnRegistry(pathVerdaccioModule,
|
||||
['-c', configPath, '-l', '9011'],
|
||||
['-c', configPath, '-l', port],
|
||||
{ cwd: verdaccioInstall, silent: false }
|
||||
);
|
||||
});
|
||||
|
||||
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/);
|
||||
|
||||
expect(output.ok).toBeTruthy();
|
||||
});
|
||||
|
||||
test('should install jquery', async () => {
|
||||
await npm('info', 'verdaccio', '--registry' ,'http://localhost:9011');
|
||||
expect(true).toBe(true);
|
||||
})
|
||||
const testCwd = path.join(tempRootFolder, '_jquery_');
|
||||
await execAndWaitForOutputToMatch('npm', ['install', '--prefix', testCwd, 'jquery', '--registry' ,`http://localhost:${port}`], /''/, {
|
||||
cwd: verdaccioInstall
|
||||
});
|
||||
|
||||
const exist = await expectFileToExist(path.join(testCwd, 'node_modules', 'jquery', 'package.json'));
|
||||
expect(exist).toBeTruthy();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
registryProcess.kill();
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
import path from 'path';
|
||||
// import { npm } from '../../utils/process';
|
||||
|
||||
function testExample() {
|
||||
console.log('running example');
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
export default async function() {
|
||||
await testExample();
|
||||
}
|
||||
|
||||
describe.skip('test example', ()=> {
|
||||
|
||||
beforeAll(() => {
|
||||
|
||||
});
|
||||
|
||||
test('sub example', async (done) => {
|
||||
console.log(`New directory: ${process.cwd()}`, __dirname);
|
||||
process.chdir(path.join(__dirname, '../../projects/basic'));
|
||||
console.log(`New directory: ${process.cwd()}`);
|
||||
// await npm('install', '--registry' ,'http://localhost:4873');
|
||||
done();
|
||||
// @ts-ignore
|
||||
// console.log('--->', global.__namespace.getItem('dir-root'));
|
||||
expect(true).toBe(true);
|
||||
})
|
||||
});
|
13
test/e2e-cli/utils/expect.ts
Normal file
13
test/e2e-cli/utils/expect.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import * as fs from 'fs-extra';
|
||||
|
||||
export function expectFileToExist(fileName: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.exists(fileName, (exist) => {
|
||||
if (exist) {
|
||||
resolve(exist);
|
||||
} else {
|
||||
reject(new Error(`File ${fileName} was expected to exist but not found...`));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import * as child_process from 'child_process';
|
||||
import {SpawnOptions} from "child_process";
|
||||
|
||||
export async function _exec(options, cmd, args) {
|
||||
let stdout = '';
|
||||
|
@ -47,9 +48,6 @@ export async function _exec(options, cmd, args) {
|
|||
const err = new Error(`Running "${cmd} ${args.join(' ')}" returned error code `);
|
||||
return new Promise((resolve, reject) => {
|
||||
childProcess.on('exit', (error) => {
|
||||
// _processes = _processes.filter(p => p !== childProcess);
|
||||
console.log("--EXIT PROCESS-->", error);
|
||||
|
||||
if (!error) {
|
||||
resolve({ stdout, stderr });
|
||||
} else {
|
||||
|
@ -62,7 +60,7 @@ export async function _exec(options, cmd, args) {
|
|||
const match = options.waitForMatch;
|
||||
childProcess.stdout.on('data', (data) => {
|
||||
if (data.toString().match(match)) {
|
||||
resolve({ stdout, stderr });
|
||||
resolve({ok: true, stdout, stderr });
|
||||
}
|
||||
});
|
||||
childProcess.stderr.on('data', (data) => {
|
||||
|
@ -74,16 +72,19 @@ export async function _exec(options, cmd, args) {
|
|||
});
|
||||
}
|
||||
|
||||
export function execAndWaitForOutputToMatch(
|
||||
cmd: string,
|
||||
args: string[],
|
||||
match: RegExp,
|
||||
spawnOptions: SpawnOptions = {}): any {
|
||||
return _exec({ waitForMatch: match, ...spawnOptions }, cmd, args);
|
||||
}
|
||||
|
||||
|
||||
export function npm(...args) {
|
||||
return _exec({}, 'npm', args);
|
||||
}
|
||||
|
||||
|
||||
export function node(...args) {
|
||||
return _exec({}, 'node', args);
|
||||
}
|
||||
|
||||
export function silentNpm(...args) {
|
||||
return _exec({silent: true}, 'npm', args);
|
||||
}
|
9
test/e2e-cli/utils/utils.ts
Normal file
9
test/e2e-cli/utils/utils.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
export function copyConfigFile(rootFolder, configTemplate): string {
|
||||
const configPath = path.join(rootFolder, 'verdaccio.yaml');
|
||||
fs.copyFileSync(path.join(__dirname, configTemplate), configPath);
|
||||
|
||||
return configPath;
|
||||
}
|
Loading…
Reference in a new issue