mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
* add files for new client side and reorg gulp tasks * add deps and script for new client * fix webpack paths so that building works * fix static assets not copied into prod build * fix linting * add eslint deps and re-enable it in webpack * add most missing deps for client side and split .babelrc for client * reorganize .eslintignore * update client tests paths and .gitignore * uncomment code * client: move App component * client: update oaths in App component * fix client tests and add more deps * add client side tests to npm test * fix typo in depencency name * update more deps * fix karma.conf.js and upgrade phantomjs * fix dep and move karma.conf to subdirectory * update karma.conf.js position in Gruntfile * try downgrading phantomjs * Fixup client tests (#8032) * Use phantom 2 * fix(tests): Fix refresher test * gitignore translation mock * Update karma version * disable e2e tests for new client from build * write vue templates with pug * add basic routing * remove unnecessary Function.bind shim * remove unused dependency
118 lines
3.1 KiB
JavaScript
118 lines
3.1 KiB
JavaScript
import { exec } from 'child_process';
|
|
import psTree from 'ps-tree';
|
|
import nconf from 'nconf';
|
|
import net from 'net';
|
|
import Bluebird from 'bluebird';
|
|
import { post } from 'superagent';
|
|
import { sync as glob } from 'glob';
|
|
import Mocha from 'mocha';
|
|
import { resolve } from 'path';
|
|
|
|
/*
|
|
* Get access to configruable values
|
|
*/
|
|
nconf.argv().env().file({ file: 'config.json' });
|
|
export var conf = nconf;
|
|
|
|
/*
|
|
* Kill a child process and any sub-children that process may have spawned.
|
|
* This is necessary to ensure that Gulp will terminate when it has completed
|
|
* its tasks.
|
|
*/
|
|
export function kill (proc) {
|
|
let killProcess = (pid) => {
|
|
psTree(pid, (_, pids) => {
|
|
if (pids.length) {
|
|
pids.forEach(kill); return;
|
|
}
|
|
try {
|
|
exec(/^win/.test(process.platform)
|
|
? `taskkill /PID ${pid} /T /F`
|
|
: `kill -9 ${pid}`);
|
|
}
|
|
catch (e) { console.log(e); }
|
|
});
|
|
};
|
|
|
|
killProcess(proc.PID || proc.pid);
|
|
}
|
|
|
|
/*
|
|
* Return a promise that will execute when Node is able to connect on a
|
|
* specific port. For example, this can be used to halt tasks until Selenium
|
|
* has fully spun up. Optionally provide a maximum number of seconds to wait
|
|
* before failing.
|
|
*/
|
|
export function awaitPort (port, max = 60) {
|
|
return new Bluebird((reject, resolve) => {
|
|
let socket, timeout, interval;
|
|
|
|
timeout = setTimeout(() => {
|
|
clearInterval(interval);
|
|
reject(`Timed out after ${max} seconds`);
|
|
}, max * 1000);
|
|
|
|
interval = setInterval(() => {
|
|
socket = net.connect({port: port}, () => {
|
|
clearInterval(interval);
|
|
clearTimeout(timeout);
|
|
socket.destroy();
|
|
resolve();
|
|
}).on('error', () => { socket.destroy; });
|
|
}, 1000);
|
|
});
|
|
}
|
|
|
|
/*
|
|
* Pipe the child's stdin and stderr to the parent process.
|
|
*/
|
|
export function pipe (child) {
|
|
child.stdout.on('data', (data) => { process.stdout.write(data); });
|
|
child.stderr.on('data', (data) => { process.stderr.write(data); });
|
|
}
|
|
|
|
/*
|
|
* Post request to notify configured slack channel
|
|
*/
|
|
export function postToSlack (msg, config = {}) {
|
|
let slackUrl = nconf.get('SLACK_URL');
|
|
|
|
if (!slackUrl) {
|
|
console.error('No slack post url specified. Your message was:');
|
|
console.log(msg);
|
|
|
|
return;
|
|
}
|
|
|
|
post(slackUrl)
|
|
.send({
|
|
channel: `#${config.channel || '#general'}`,
|
|
username: config.username || 'gulp task',
|
|
text: msg,
|
|
icon_emoji: `:${config.emoji || 'gulp'}:`,
|
|
})
|
|
.end((err, res) => {
|
|
if (err) console.error('Unable to post to slack', err);
|
|
});
|
|
}
|
|
|
|
export function runMochaTests (files, server, cb) {
|
|
require('../test/helpers/globals.helper');
|
|
|
|
let mocha = new Mocha({reporter: 'spec'});
|
|
let tests = glob(files);
|
|
|
|
tests.forEach((test) => {
|
|
delete require.cache[resolve(test)];
|
|
mocha.addFile(test);
|
|
});
|
|
|
|
mocha.run((numberOfFailures) => {
|
|
if (!process.env.RUN_INTEGRATION_TEST_FOREVER) {
|
|
if (server) kill(server);
|
|
process.exit(numberOfFailures);
|
|
}
|
|
cb();
|
|
});
|
|
}
|