mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Adjust api test commands
This commit is contained in:
@@ -9,12 +9,13 @@ import Q from 'q';
|
|||||||
import Mocha from 'mocha';
|
import Mocha from 'mocha';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
|
|
||||||
const TEST_SERVER_PORT = 3001
|
const E2E_TEST_SERVER_PORT = 3001
|
||||||
|
const API_TEST_SERVER_PORT = 3003
|
||||||
const TEST_DB = 'habitrpg_test'
|
const TEST_DB = 'habitrpg_test'
|
||||||
|
|
||||||
const TEST_DB_URI = `mongodb://localhost/${TEST_DB}`
|
const TEST_DB_URI = `mongodb://localhost/${TEST_DB}`
|
||||||
|
|
||||||
const API_TEST_COMMAND = 'mocha test/api --compilers js:babel/register';
|
const API_TEST_COMMAND = 'mocha test/api --recursive --compilers js:babel/register';
|
||||||
const LEGACY_API_TEST_COMMAND = 'mocha test/api-legacy';
|
const LEGACY_API_TEST_COMMAND = 'mocha test/api-legacy';
|
||||||
const COMMON_TEST_COMMAND = 'mocha test/common --compilers coffee:coffee-script';
|
const COMMON_TEST_COMMAND = 'mocha test/common --compilers coffee:coffee-script';
|
||||||
const CONTENT_TEST_COMMAND = 'mocha test/content --compilers js:babel/register';
|
const CONTENT_TEST_COMMAND = 'mocha test/content --compilers js:babel/register';
|
||||||
@@ -229,7 +230,7 @@ gulp.task('test:karma:safe', ['test:prepare:build'], (cb) => {
|
|||||||
gulp.task('test:e2e', ['test:prepare'], (cb) => {
|
gulp.task('test:e2e', ['test:prepare'], (cb) => {
|
||||||
let support = [
|
let support = [
|
||||||
'Xvfb :99 -screen 0 1024x768x24 -extension RANDR',
|
'Xvfb :99 -screen 0 1024x768x24 -extension RANDR',
|
||||||
`NODE_DB_URI="${TEST_DB_URI}" PORT="${TEST_SERVER_PORT}" node ./website/src/server.js`,
|
`NODE_DB_URI="${TEST_DB_URI}" PORT="${E2E_TEST_SERVER_PORT}" node ./website/src/server.js`,
|
||||||
'./node_modules/protractor/bin/webdriver-manager start',
|
'./node_modules/protractor/bin/webdriver-manager start',
|
||||||
].map(exec);
|
].map(exec);
|
||||||
|
|
||||||
@@ -254,7 +255,7 @@ gulp.task('test:e2e', ['test:prepare'], (cb) => {
|
|||||||
gulp.task('test:e2e:safe', ['test:prepare'], (cb) => {
|
gulp.task('test:e2e:safe', ['test:prepare'], (cb) => {
|
||||||
let support = [
|
let support = [
|
||||||
'Xvfb :99 -screen 0 1024x768x24 -extension RANDR',
|
'Xvfb :99 -screen 0 1024x768x24 -extension RANDR',
|
||||||
`NODE_DB_URI="${TEST_DB_URI}" PORT="${TEST_SERVER_PORT}" node ./website/src/server.js`,
|
`NODE_DB_URI="${TEST_DB_URI}" PORT="${E2E_TEST_SERVER_PORT}" node ./website/src/server.js`,
|
||||||
'./node_modules/protractor/bin/webdriver-manager start',
|
'./node_modules/protractor/bin/webdriver-manager start',
|
||||||
].map(exec);
|
].map(exec);
|
||||||
|
|
||||||
@@ -283,47 +284,48 @@ gulp.task('test:e2e:safe', ['test:prepare'], (cb) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test:api', ['test:startServer', 'test:prepare:mongo'], (done) => {
|
gulp.task('test:api', ['test:prepare:mongo'], (done) => {
|
||||||
require('../test/helpers/globals.helper');
|
require('../test/helpers/globals.helper');
|
||||||
let mocha = new Mocha({reporter: 'spec'});
|
|
||||||
let tests = glob('./test/api/**/*.js');
|
|
||||||
|
|
||||||
tests.forEach((test) => {
|
let server = exec(`NODE_DB_URI="${TEST_DB_URI}" PORT="${API_TEST_SERVER_PORT}" node ./website/src/server.js`);
|
||||||
delete require.cache[resolve(test)];
|
|
||||||
mocha.addFile(test);
|
|
||||||
});
|
|
||||||
|
|
||||||
mocha.run((numberOfFailures) => {
|
awaitPort(API_TEST_SERVER_PORT).then(() => {
|
||||||
if (!process.env.RUN_INTEGRATION_TEST_FOREVER) {
|
let mocha = new Mocha({reporter: 'spec'});
|
||||||
process.exit(numberOfFailures);
|
let tests = glob('./test/api/**/*.js');
|
||||||
}
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('test:api:safe', ['test:startServer', 'test:prepare:mongo'], (done) => {
|
tests.forEach((test) => {
|
||||||
let runner = exec(
|
delete require.cache[resolve(test)];
|
||||||
testBin(API_TEST_COMMAND),
|
mocha.addFile(test);
|
||||||
(err, stdout, stderr) => {
|
});
|
||||||
testResults.push({
|
|
||||||
suite: 'API Specs',
|
mocha.run((numberOfFailures) => {
|
||||||
pass: testCount(stdout, /(\d+) passing/),
|
if (!process.env.RUN_INTEGRATION_TEST_FOREVER) {
|
||||||
fail: testCount(stderr, /(\d+) failing/),
|
kill(server);
|
||||||
pend: testCount(stdout, /(\d+) pending/)
|
}
|
||||||
});
|
|
||||||
done();
|
done();
|
||||||
}
|
});
|
||||||
);
|
});
|
||||||
pipe(runner);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test:startServer', (done) => {
|
gulp.task('test:api:safe', ['test:prepare:mongo'], (done) => {
|
||||||
process.env.NODE_DB_URI = `mongodb://localhost/${TEST_DB}-api`;
|
let server = exec(`NODE_DB_URI="${TEST_DB_URI}" PORT="${API_TEST_SERVER_PORT}" node ./website/src/server.js`);
|
||||||
process.env.DISABLE_REQUEST_LOGGING = true;
|
|
||||||
process.env.PORT = 3003;
|
|
||||||
|
|
||||||
let server = require('../website/src/server.js');
|
awaitPort(API_TEST_SERVER_PORT).then(() => {
|
||||||
server.listen(TEST_SERVER_PORT, done);
|
let runner = exec(
|
||||||
|
testBin(API_TEST_COMMAND),
|
||||||
|
(err, stdout, stderr) => {
|
||||||
|
testResults.push({
|
||||||
|
suite: 'API Specs\t',
|
||||||
|
pass: testCount(stdout, /(\d+) passing/),
|
||||||
|
fail: testCount(stderr, /(\d+) failing/),
|
||||||
|
pend: testCount(stdout, /(\d+) pending/)
|
||||||
|
});
|
||||||
|
kill(server);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
pipe(runner);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test', [
|
gulp.task('test', [
|
||||||
|
|||||||
Reference in New Issue
Block a user