diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 248d80c..c4e815f 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -45,30 +45,36 @@ gulp.task('start', function() { }); gulp.task('test', function() { - let unitTest = spawn( + let lintTest = spawn( 'node_modules/mocha/bin/mocha', - ['test/unit', '--compilers', 'js:babel-core/register'], + ['test/unit/lint.js', '--compilers', 'js:babel-core/register'], {stdio: 'inherit'} ); - unitTest.on('exit', function() { + lintTest.on('exit', function() { - // Start app - let app = spawn('node', ['index.js']); + let unitTest = spawn('node_modules/karma/bin/karma', ['start', '--single-run'], {stdio: 'inherit'}); - app.stdout.on('data', function(data) { - console.log(String(data)); - }); + unitTest.on('exit', function() { - let acceptanceTest = spawn( - 'node_modules/nightwatch/bin/nightwatch', - ['--test', 'test/acceptance/index.js', '--config', 'test/acceptance/nightwatch-local.json'], - {stdio: 'inherit'} - ); + // Start app + let app = spawn('node', ['index.js']); + + app.stdout.on('data', function(data) { + console.log(String(data)); + }); + + let acceptanceTest = spawn( + 'node_modules/nightwatch/bin/nightwatch', + ['--test', 'test/acceptance/index.js', '--config', 'test/acceptance/nightwatch-local.json'], + {stdio: 'inherit'} + ); + + acceptanceTest.on('exit', function() { + // Kill app Node process when tests are done + app.kill(); + }); - acceptanceTest.on('exit', function() { - // Kill app Node process when tests are done - app.kill(); }); }); diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..6b79df8 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,69 @@ +// Karma configuration +// Generated on Sat Feb 27 2016 15:39:33 GMT-0500 (EST) + +module.exports = function(config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['browserify', 'mocha'], + + // list of files / patterns to load in the browser + files: [ + 'test/unit/index.js' + ], + + // list of files to exclude + exclude: [ + ], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + 'test/unit/**/*.js': ['browserify'] + }, + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['Chrome'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity, + + browserify: { + debug: true, + configure: function(bundle) { + bundle.once('prebundle', function() { + bundle.transform('babelify'); + }); + } + } + + }); +}; diff --git a/package.json b/package.json index 997f078..6445250 100644 --- a/package.json +++ b/package.json @@ -32,10 +32,15 @@ "gulp-nodemon": "^2.0.6", "jscs": "^2.10.1", "jshint": "^2.9.1", + "karma": "^0.13.21", + "karma-browserify": "^5.0.2", + "karma-chrome-launcher": "^0.2.2", + "karma-mocha": "^0.2.2", "mocha": "^2.4.5", "mocha-jscs": "^4.2.0", "mocha-jshint": "^2.3.1", "nightwatch": "^0.8.16", + "sinon": "^1.17.3", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0" }, @@ -45,7 +50,7 @@ "dev": "npm run bundle && gulp start", "bundle": "gulp bundle", "test": "npm run bundle && gulp test", - "test-travis": "node_modules/mocha/bin/mocha test/unit --compilers js:babel-core/register && node_modules/nightwatch/bin/nightwatch --test test/acceptance/index.js --config test/acceptance/nightwatch.json -e chrome" + "test-travis": "node_modules/mocha/bin/mocha test/unit/lint.js --compilers js:babel-core/register && node_modules/karma/bin/karma start --single-run && node_modules/nightwatch/bin/nightwatch --test test/acceptance/index.js --config test/acceptance/nightwatch.json -e chrome" }, "author": "Daniel Seripap", "license": "MIT" diff --git a/test/unit/audio.js b/test/unit/audio.js new file mode 100644 index 0000000..6c6b1bb --- /dev/null +++ b/test/unit/audio.js @@ -0,0 +1,53 @@ +import assert from 'assert'; +import AudioHandler from '../../src/js/audio.js'; +import sinon from 'sinon'; + +describe('Audio', () => { + + describe('playing sounds', () => { + + describe('when window.Audio is supported', () => { + + describe('when sound is enabled', () => { + let playStub; + + before(() => { + let audio = new AudioHandler(); + playStub = sinon.stub(audio._beep, 'play'); + audio.play(); + }); + + after(() => { + playStub.reset(); + }); + + it('should play sounds', () => { + assert(playStub.called); + }); + }); + + describe('sound is not enabled', () => { + let playStub; + + before(() => { + let audio = new AudioHandler(); + audio.soundEnabled = false; + playStub = sinon.stub(audio._beep, 'play'); + audio.play(); + }); + + after(() => { + playStub.reset(); + }); + + it('should not play sounds', () => { + assert(playStub.notCalled); + }); + + }); + + }); + + }); + +}); diff --git a/test/unit/index.js b/test/unit/index.js new file mode 100644 index 0000000..1c2e979 --- /dev/null +++ b/test/unit/index.js @@ -0,0 +1 @@ +require('./audio.js'); diff --git a/test/unit/app.js b/test/unit/lint.js similarity index 100% rename from test/unit/app.js rename to test/unit/lint.js