mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
Creates safe versions of tests for Common, API, Karma, and E2E that don't pass errors via callback. The summary information will check if any tests failed and throw an error after all tests have been run.
This commit is contained in:
@@ -45,6 +45,16 @@ gulp.task('test:prepare', [
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
gulp.task('test:common', ['test:prepare:build'], (cb) => {
|
gulp.task('test:common', ['test:prepare:build'], (cb) => {
|
||||||
|
let runner = exec(
|
||||||
|
testBin('mocha test/common'),
|
||||||
|
(err, stdout, stderr) => {
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
pipe(runner);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('test:common:safe', ['test:prepare:build'], (cb) => {
|
||||||
let runner = exec(
|
let runner = exec(
|
||||||
testBin('mocha test/common'),
|
testBin('mocha test/common'),
|
||||||
(err, stdout, stderr) => {
|
(err, stdout, stderr) => {
|
||||||
@@ -54,7 +64,7 @@ gulp.task('test:common', ['test:prepare:build'], (cb) => {
|
|||||||
fail: testCount(stderr, /(\d+) failing/),
|
fail: testCount(stderr, /(\d+) failing/),
|
||||||
pend: testCount(stdout, /(\d+) pending/)
|
pend: testCount(stdout, /(\d+) pending/)
|
||||||
});
|
});
|
||||||
cb(err);
|
cb();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
pipe(runner);
|
pipe(runner);
|
||||||
@@ -62,6 +72,16 @@ gulp.task('test:common', ['test:prepare:build'], (cb) => {
|
|||||||
|
|
||||||
|
|
||||||
gulp.task('test:api', ['test:prepare:mongo'], (cb) => {
|
gulp.task('test:api', ['test:prepare:mongo'], (cb) => {
|
||||||
|
let runner = exec(
|
||||||
|
testBin("istanbul cover -i 'website/src/**' --dir coverage/api ./node_modules/.bin/_mocha -- test/api"),
|
||||||
|
(err, stdout, stderr) => {
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
pipe(runner);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('test:api:safe', ['test:prepare:mongo'], (cb) => {
|
||||||
let runner = exec(
|
let runner = exec(
|
||||||
testBin("istanbul cover -i 'website/src/**' --dir coverage/api ./node_modules/.bin/_mocha -- test/api"),
|
testBin("istanbul cover -i 'website/src/**' --dir coverage/api ./node_modules/.bin/_mocha -- test/api"),
|
||||||
(err, stdout, stderr) => {
|
(err, stdout, stderr) => {
|
||||||
@@ -71,10 +91,10 @@ gulp.task('test:api', ['test:prepare:mongo'], (cb) => {
|
|||||||
fail: testCount(stderr, /(\d+) failing/),
|
fail: testCount(stderr, /(\d+) failing/),
|
||||||
pend: testCount(stdout, /(\d+) pending/)
|
pend: testCount(stdout, /(\d+) pending/)
|
||||||
});
|
});
|
||||||
cb(err);
|
cb();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
pipe(runner);
|
pipe(runner)
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test:api:clean', (cb) => {
|
gulp.task('test:api:clean', (cb) => {
|
||||||
@@ -89,6 +109,16 @@ gulp.task('test:api:watch', [
|
|||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test:karma', ['test:prepare:build'], (cb) => {
|
gulp.task('test:karma', ['test:prepare:build'], (cb) => {
|
||||||
|
let runner = exec(
|
||||||
|
testBin('karma start --single-run'),
|
||||||
|
(err, stdout) => {
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
pipe(runner);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('test:karma:safe', ['test:prepare:build'], (cb) => {
|
||||||
let runner = exec(
|
let runner = exec(
|
||||||
testBin('karma start --single-run'),
|
testBin('karma start --single-run'),
|
||||||
(err, stdout) => {
|
(err, stdout) => {
|
||||||
@@ -98,7 +128,7 @@ gulp.task('test:karma', ['test:prepare:build'], (cb) => {
|
|||||||
fail: testCount(stdout, /(\d+) tests failed/),
|
fail: testCount(stdout, /(\d+) tests failed/),
|
||||||
pend: testCount(stdout, /(\d+) tests skipped/)
|
pend: testCount(stdout, /(\d+) tests skipped/)
|
||||||
});
|
});
|
||||||
cb(err);
|
cb();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
pipe(runner);
|
pipe(runner);
|
||||||
@@ -111,6 +141,31 @@ gulp.task('test:e2e', ['test:prepare'], (cb) => {
|
|||||||
'./node_modules/protractor/bin/webdriver-manager start',
|
'./node_modules/protractor/bin/webdriver-manager start',
|
||||||
].map(exec);
|
].map(exec);
|
||||||
|
|
||||||
|
Q.all([
|
||||||
|
awaitPort(3001),
|
||||||
|
awaitPort(4444)
|
||||||
|
]).then(() => {
|
||||||
|
let runner = exec(
|
||||||
|
'DISPLAY=:99 NODE_ENV=testing ./node_modules/protractor/bin/protractor protractor.conf.js',
|
||||||
|
(err, stdout, stderr) => {
|
||||||
|
/*
|
||||||
|
* Note: As it stands, protractor wont report pending specs
|
||||||
|
*/
|
||||||
|
support.forEach(kill);
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
pipe(runner);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('test:e2e:safe', ['test:prepare'], (cb) => {
|
||||||
|
let support = [
|
||||||
|
'Xvfb :99 -screen 0 1024x768x24 -extension RANDR',
|
||||||
|
`NODE_DB_URI="${TEST_DB_URI}" PORT="${TEST_SERVER_PORT}" node ./website/src/server.js`,
|
||||||
|
'./node_modules/protractor/bin/webdriver-manager start',
|
||||||
|
].map(exec);
|
||||||
|
|
||||||
Q.all([
|
Q.all([
|
||||||
awaitPort(3001),
|
awaitPort(3001),
|
||||||
awaitPort(4444)
|
awaitPort(4444)
|
||||||
@@ -129,7 +184,7 @@ gulp.task('test:e2e', ['test:prepare'], (cb) => {
|
|||||||
pend: 0
|
pend: 0
|
||||||
});
|
});
|
||||||
support.forEach(kill);
|
support.forEach(kill);
|
||||||
cb(err);
|
cb();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
pipe(runner);
|
pipe(runner);
|
||||||
@@ -137,10 +192,10 @@ gulp.task('test:e2e', ['test:prepare'], (cb) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test', [
|
gulp.task('test', [
|
||||||
'test:common',
|
'test:common:safe',
|
||||||
'test:karma',
|
'test:karma:safe',
|
||||||
'test:api',
|
'test:api:safe',
|
||||||
'test:e2e'
|
'test:e2e:safe'
|
||||||
], () => {
|
], () => {
|
||||||
let totals = [0,0,0];
|
let totals = [0,0,0];
|
||||||
|
|
||||||
@@ -164,5 +219,8 @@ gulp.task('test', [
|
|||||||
`\x1b[36mPending: ${totals[2]}\t`
|
`\x1b[36mPending: ${totals[2]}\t`
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('\n\x1b[36mThanks for helping keep Habitica clean!\x1b[0m');
|
if (totals[1] > 0) throw "ERROR: There are failing tests!"
|
||||||
|
else {
|
||||||
|
console.log('\n\x1b[36mThanks for helping keep Habitica clean!\x1b[0m');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user