mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
Extract mocha function into taskHelper
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
import { pipe, awaitPort, kill } from './taskHelper';
|
import {
|
||||||
|
pipe,
|
||||||
|
awaitPort,
|
||||||
|
kill,
|
||||||
|
runIntegrationTestsWithMocha,
|
||||||
|
} from './taskHelper';
|
||||||
import { server as karma } from 'karma';
|
import { server as karma } from 'karma';
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import psTree from 'ps-tree';
|
import psTree from 'ps-tree';
|
||||||
import gulp from 'gulp';
|
import gulp from 'gulp';
|
||||||
import { sync as glob } from 'glob';
|
|
||||||
import Q from 'q';
|
import Q from 'q';
|
||||||
import Mocha from 'mocha';
|
|
||||||
import { resolve } from 'path';
|
|
||||||
|
|
||||||
const TEST_SERVER_PORT = 3003
|
const TEST_SERVER_PORT = 3003
|
||||||
const TEST_DB = 'habitrpg_test'
|
const TEST_DB = 'habitrpg_test'
|
||||||
@@ -294,34 +296,12 @@ gulp.task('test:e2e:safe', ['test:prepare', 'test:prepare:server'], (cb) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test:api-v2', ['test:prepare:server'], (done) => {
|
gulp.task('test:api-v2', ['test:prepare:server'], (done) => {
|
||||||
runIntegrationTestsWithMocha('./test/api/v2/**/*.js')
|
runIntegrationTestsWithMocha('./test/api/v2/**/*.js', TEST_SERVER_PORT, server)
|
||||||
});
|
});
|
||||||
|
|
||||||
function runIntegrationTestsWithMocha(files) {
|
|
||||||
require('../test/helpers/globals.helper');
|
|
||||||
|
|
||||||
awaitPort(TEST_SERVER_PORT).then(() => {
|
|
||||||
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) {
|
|
||||||
kill(server);
|
|
||||||
process.exit(numberOfFailures);
|
|
||||||
}
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
gulp.task('test:api-v2:watch', ['test:prepare:server'], () => {
|
gulp.task('test:api-v2:watch', ['test:prepare:server'], () => {
|
||||||
process.env.RUN_INTEGRATION_TEST_FOREVER = true;
|
process.env.RUN_INTEGRATION_TEST_FOREVER = true;
|
||||||
gulp.watch(['website/src/**', 'test/api/**'], ['test:api']);
|
gulp.watch(['website/src/**', 'test/api/v2/**'], ['test:api']);
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test:api-v2:safe', ['test:prepare:server'], (done) => {
|
gulp.task('test:api-v2:safe', ['test:prepare:server'], (done) => {
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import nconf from 'nconf';
|
|||||||
import net from 'net';
|
import net from 'net';
|
||||||
import Q from 'q';
|
import Q from 'q';
|
||||||
import { post } from 'superagent';
|
import { post } from 'superagent';
|
||||||
|
import { sync as glob } from 'glob';
|
||||||
|
import Mocha from 'mocha';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get access to configruable values
|
* Get access to configruable values
|
||||||
@@ -91,3 +94,26 @@ export function postToSlack(msg, config={}) {
|
|||||||
if (err) console.error('Unable to post to slack', err);
|
if (err) console.error('Unable to post to slack', err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function runIntegrationTestsWithMocha(files, port, server) {
|
||||||
|
require('../test/helpers/globals.helper');
|
||||||
|
|
||||||
|
awaitPort(port).then(() => {
|
||||||
|
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) {
|
||||||
|
kill(server);
|
||||||
|
process.exit(numberOfFailures);
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user