Skip to content

Commit

Permalink
feat(project): introduce test disabler
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Kiefer committed Mar 22, 2019
1 parent 9d43fc4 commit dd84ff6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ gulp.task('default', gulp.series(['clean', 'html', 'css', 'js', 'vendor']));

gulp.task('test', gulp.series(['default'], function (done) {

process.env.NODE_ENV = 'test';

return new KarmaServ({
configFile: `${configuration.paths.test}/config/karma.unit.js`,
singleRun: true
Expand Down
14 changes: 13 additions & 1 deletion lib/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ function spawnObstacles () {

canvas.moveObstacles();

if (_isTestMode()) {

return;

}

// execute collision detection inside web worker
const {
collisionDetection,
Expand All @@ -102,7 +108,7 @@ function spawnObstacles () {

const job = collisionDetection(collideCheckObject);

job.done = (isCollided) => {
job.done = function (isCollided) {

if (isCollided) {

Expand Down Expand Up @@ -170,6 +176,12 @@ function _reset () {

}

function _isTestMode () {

return $('#test-mode').length > 0;

}

document.addEventListener('DOMContentLoaded', event => {

_init();
Expand Down
16 changes: 15 additions & 1 deletion test/main/mainSpec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global it, describe, expect, before, __html__, _init, _reset, bird, canvas, sinon */
/* global it, describe, expect, before, __html__, _init, _reset, bird, canvas, sinon, _isTestMode */
/* eslint-disable no-unused-expressions */
describe('Main', function () {

Expand Down Expand Up @@ -108,6 +108,20 @@ describe('Main', function () {

});

describe('#_isTestMode', function () {

it('should return true in test mode', function () {

// given
const isTestMode = _isTestMode();

// then
expect(isTestMode).to.be.true;

});

});

describe('#_reset', function () {

before(function () {
Expand Down
3 changes: 3 additions & 0 deletions test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@

<body>

<!-- enable test mode -->
<div id='test-mode'></div>

</body>
</html>

0 comments on commit dd84ff6

Please sign in to comment.