mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
Refactor task helper for unit and integration tests.
This commit is contained in:
@@ -2,7 +2,7 @@ import {
|
||||
pipe,
|
||||
awaitPort,
|
||||
kill,
|
||||
runIntegrationTestsWithMocha,
|
||||
runMochaTests,
|
||||
} from './taskHelper';
|
||||
import { server as karma } from 'karma';
|
||||
import mongoose from 'mongoose';
|
||||
@@ -296,7 +296,10 @@ gulp.task('test:e2e:safe', ['test:prepare', 'test:prepare:server'], (cb) => {
|
||||
});
|
||||
|
||||
gulp.task('test:api-v2', ['test:prepare:server'], (done) => {
|
||||
runIntegrationTestsWithMocha('./test/api/v2/**/*.js', TEST_SERVER_PORT, server)
|
||||
|
||||
awaitPort(TEST_SERVER_PORT).then(() => {
|
||||
runMochaTests('./test/api/v2/**/*.js', server, done)
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('test:api-v2:watch', ['test:prepare:server'], () => {
|
||||
|
||||
@@ -95,25 +95,22 @@ export function postToSlack(msg, config={}) {
|
||||
});
|
||||
}
|
||||
|
||||
export function runIntegrationTestsWithMocha(files, port, server) {
|
||||
export function runMochaTests(files, server, cb) {
|
||||
require('../test/helpers/globals.helper');
|
||||
|
||||
awaitPort(port).then(() => {
|
||||
let mocha = new Mocha({reporter: 'spec'});
|
||||
let tests = glob(files);
|
||||
let mocha = new Mocha({reporter: 'spec'});
|
||||
let tests = glob(files);
|
||||
|
||||
tests.forEach((test) => {
|
||||
delete require.cache[resolve(test)];
|
||||
mocha.addFile(test);
|
||||
});
|
||||
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();
|
||||
});
|
||||
mocha.run((numberOfFailures) => {
|
||||
if (!process.env.RUN_INTEGRATION_TEST_FOREVER) {
|
||||
if (server) kill(server);
|
||||
process.exit(numberOfFailures);
|
||||
}
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user