mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Add api test task
This commit is contained in:
@@ -4,21 +4,24 @@ import mongoose from 'mongoose';
|
||||
import { exec } from 'child_process';
|
||||
import psTree from 'ps-tree';
|
||||
import gulp from 'gulp';
|
||||
import {sync as glob} from 'glob';
|
||||
import Q from 'q';
|
||||
import Mocha from 'mocha';
|
||||
|
||||
const TEST_SERVER_PORT = 3001
|
||||
const TEST_DB = 'habitrpg_test'
|
||||
|
||||
const TEST_DB_URI = `mongodb://localhost/${TEST_DB}`
|
||||
|
||||
const API_TEST_COMMAND = 'mocha test/api-legacy';
|
||||
const API_TEST_COMMAND = 'mocha test/api';
|
||||
const LEGACY_API_TEST_COMMAND = 'mocha test/api-legacy';
|
||||
const COMMON_TEST_COMMAND = 'mocha test/common';
|
||||
const CONTENT_TEST_COMMAND = 'mocha test/content --opts test/content/mocha.content.opts';
|
||||
const CONTENT_OPTIONS = {maxBuffer: 1024 * 500};
|
||||
const KARMA_TEST_COMMAND = 'karma start';
|
||||
const SERVER_SIDE_TEST_COMMAND = 'mocha test/server_side';
|
||||
|
||||
const ISTANBUL_TEST_COMMAND = `istanbul cover -i "website/src/**" --dir coverage/api $(npm bin)/${API_TEST_COMMAND}`;
|
||||
const ISTANBUL_TEST_COMMAND = `istanbul cover -i "website/src/**" --dir coverage/api $(npm bin)/${LEGACY_API_TEST_COMMAND}`;
|
||||
|
||||
/* Helper methods for reporting test summary */
|
||||
let testResults = [];
|
||||
@@ -176,7 +179,7 @@ gulp.task('test:api-legacy:safe', ['test:prepare:mongo'], (cb) => {
|
||||
});
|
||||
|
||||
gulp.task('test:api-legacy:clean', (cb) => {
|
||||
pipe(exec(testBin(API_TEST_COMMAND), () => cb()));
|
||||
pipe(exec(testBin(LEGACY_API_TEST_COMMAND), () => cb()));
|
||||
});
|
||||
|
||||
gulp.task('test:api-legacy:watch', [
|
||||
@@ -279,10 +282,40 @@ gulp.task('test:e2e:safe', ['test:prepare'], (cb) => {
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('test:api', ['test:startServer', 'test:prepare:mongo'], (done) => {
|
||||
let mocha = new Mocha();
|
||||
let tests = glob('./test/api/**/*.js');
|
||||
|
||||
tests.forEach((test) => {
|
||||
delete require.cache[resolve(test)];
|
||||
mocha.addFile(test);
|
||||
});
|
||||
|
||||
mocha.run((numberOfFailures) => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('test:api:safe', ['test:startServer', 'test:prepare:mongo'], (done) => {
|
||||
let runner = exec(
|
||||
testBin(API_TEST_COMMAND),
|
||||
(err, stdout, stderr) => {
|
||||
testResults.push({
|
||||
suite: 'API Specs',
|
||||
pass: testCount(stdout, /(\d+) passing/),
|
||||
fail: testCount(stderr, /(\d+) failing/),
|
||||
pend: testCount(stdout, /(\d+) pending/)
|
||||
});
|
||||
done();
|
||||
}
|
||||
);
|
||||
pipe(runner);
|
||||
});
|
||||
|
||||
gulp.task('test:startServer', (done) => {
|
||||
process.env.NODE_DB_URI = TEST_DB_URI;
|
||||
process.env.NODE_DB_URI = `mongodb://localhost/${TEST_DB}-api`;
|
||||
process.env.DISABLE_REQUEST_LOGGING = true;
|
||||
process.env.PORT = TEST_SERVER_PORT;
|
||||
process.env.PORT = 3002;
|
||||
|
||||
let server = require('../website/src/server.js');
|
||||
server.listen(TEST_SERVER_PORT, done);
|
||||
@@ -293,7 +326,8 @@ gulp.task('test', [
|
||||
'test:content:safe',
|
||||
'test:server_side:safe',
|
||||
'test:karma:safe',
|
||||
'test:api-legacy:safe',
|
||||
// 'test:api-legacy:safe',
|
||||
'test:api:safe',
|
||||
'test:e2e:safe'
|
||||
], () => {
|
||||
let totals = [0,0,0];
|
||||
@@ -321,5 +355,6 @@ gulp.task('test', [
|
||||
if (totals[1] > 0) throw "ERROR: There are failing tests!"
|
||||
else {
|
||||
console.log('\n\x1b[36mThanks for helping keep Habitica clean!\x1b[0m');
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user