1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/functional/lib/startup.js

80 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-04-19 21:15:28 +02:00
'use strict';
2013-12-19 16:11:54 +01:00
const _ = require('lodash');
2017-04-19 21:15:28 +02:00
const fork = require('child_process').fork;
const bodyParser = require('body-parser');
2017-04-19 21:15:28 +02:00
const express = require('express');
const rimRaf = require('rimraf');
const path = require('path');
2017-04-19 21:15:28 +02:00
const Server = require('./server');
2013-12-19 16:11:54 +01:00
2017-04-19 21:15:28 +02:00
const forks = process.forks = [];
process.server = new Server('http://localhost:55551/');
process.server2 = new Server('http://localhost:55552/');
process.server3 = new Server('http://localhost:55553/');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
process.express = app;
2017-04-19 21:15:28 +02:00
process.express.listen(55550);
2014-07-22 20:24:19 +02:00
2017-04-19 21:15:28 +02:00
module.exports.start = function(dir, conf) {
return new Promise(function(resolve, reject) {
const storageDir = path.join(__dirname, `/../${dir}`);
const configPath = path.join(__dirname, '../', conf);
rimRaf(storageDir, function(err) {
if(_.isNil(err) === false) {
reject(err);
}
const filteredArguments = process.execArgv = process.execArgv.filter(function(x) {
// filter out --debug-brk and --inspect-brk since Node7
return (x.indexOf('--debug-brk') === -1 && x.indexOf('--inspect-brk') === -1);
2017-04-19 21:15:28 +02:00
});
const childFork = fork(__dirname + '/../../../bin/verdaccio',
['-c', configPath],
{
silent: !process.env.TRAVIS
// silent: false
}
2017-04-19 21:15:28 +02:00
);
forks.push(childFork);
childFork.on('message', function(msg) {
2017-04-19 21:15:28 +02:00
if ('verdaccio_started' in msg) {
resolve();
}
});
childFork.on('error', function(err) {
2017-04-19 21:15:28 +02:00
reject(err);
});
childFork.on('disconnect', function(err) {
reject(err);
});
childFork.on('exit', function(err) {
reject(err);
});
process.execArgv = filteredArguments;
2017-04-19 21:15:28 +02:00
});
});
};
2013-12-19 16:11:54 +01:00
process.on('exit', function() {
if (_.isNil(forks[0]) === false) {
2017-03-04 00:39:26 +01:00
forks[0].kill();
}
if (_.isNil(forks[1]) === false) {
2017-03-04 00:39:26 +01:00
forks[1].kill();
}
if (_.isNil(forks[2]) === false) {
2017-03-04 00:39:26 +01:00
forks[2].kill();
}
2017-04-19 21:15:28 +02:00
});