1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-17 07:45:52 +01:00
verdaccio/test/functional/lib/server_process.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-11-27 07:15:09 +01:00
// @flow
import _ from 'lodash';
import rimRaf from 'rimraf';
import path from 'path';
import {fork} from 'child_process';
import type {IVerdaccioConfig, IServerBridge, IServerProcess} from './types';
export default class VerdaccioProcess implements IServerProcess {
2017-12-03 22:23:06 +01:00
bridge: IServerBridge;
config: IVerdaccioConfig;
childFork: any;
silence: boolean;
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
constructor(config: IVerdaccioConfig, bridge: IServerBridge, silence: boolean = true) {
this.config = config;
this.bridge = bridge;
this.silence = silence;
}
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
init(): Promise<any> {
return new Promise((resolve, reject) => {
const verdaccioRegisterWrap: string = path.join(__dirname, '../../../bin/verdaccio');
const storageDir: string = path.join(__dirname, `/../${this.config.storagePath}`);
const configPath: string = path.join(__dirname, '../', this.config.configPath);
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
rimRaf(storageDir, (err) => {
if (_.isNil(err) === false) {
reject(err);
}
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
this.childFork = fork(verdaccioRegisterWrap,
['-c', configPath],
{
silent: this.silence
}
);
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
this.childFork.on('message', (msg) => {
if ('verdaccio_started' in msg) {
this.bridge.debug().status(200).then((body) => {
this.bridge.auth('test', 'test')
.status(201)
.body_ok(/'test'/)
.then(() => {
resolve([this, body.pid]);
}, reject)
}, reject);
}
});
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
this.childFork.on('error', function(err) {
reject(err);
});
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
this.childFork.on('disconnect', function(err) {
reject(err);
});
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
this.childFork.on('exit', function(err) {
reject(err);
});
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
});
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
});
}
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
stop(): void {
return this.childFork.kill('SIGINT');
}
2017-11-27 07:15:09 +01:00
2017-12-03 22:23:06 +01:00
}