mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-18 18:54:52 +00:00
Add Karma testing framework and a unit test for AudioHandler
This commit is contained in:
parent
5e67fad28f
commit
f4fef8d967
@ -45,12 +45,16 @@ gulp.task('start', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test', function() {
|
gulp.task('test', function() {
|
||||||
let unitTest = spawn(
|
let lintTest = spawn(
|
||||||
'node_modules/mocha/bin/mocha',
|
'node_modules/mocha/bin/mocha',
|
||||||
['test/unit', '--compilers', 'js:babel-core/register'],
|
['test/unit/lint.js', '--compilers', 'js:babel-core/register'],
|
||||||
{stdio: 'inherit'}
|
{stdio: 'inherit'}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
lintTest.on('exit', function() {
|
||||||
|
|
||||||
|
let unitTest = spawn('node_modules/karma/bin/karma', ['start', '--single-run'], {stdio: 'inherit'});
|
||||||
|
|
||||||
unitTest.on('exit', function() {
|
unitTest.on('exit', function() {
|
||||||
|
|
||||||
// Start app
|
// Start app
|
||||||
@ -70,6 +74,8 @@ gulp.task('test', function() {
|
|||||||
// Kill app Node process when tests are done
|
// Kill app Node process when tests are done
|
||||||
app.kill();
|
app.kill();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
69
karma.conf.js
Normal file
69
karma.conf.js
Normal file
@ -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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
};
|
@ -32,10 +32,15 @@
|
|||||||
"gulp-nodemon": "^2.0.6",
|
"gulp-nodemon": "^2.0.6",
|
||||||
"jscs": "^2.10.1",
|
"jscs": "^2.10.1",
|
||||||
"jshint": "^2.9.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": "^2.4.5",
|
||||||
"mocha-jscs": "^4.2.0",
|
"mocha-jscs": "^4.2.0",
|
||||||
"mocha-jshint": "^2.3.1",
|
"mocha-jshint": "^2.3.1",
|
||||||
"nightwatch": "^0.8.16",
|
"nightwatch": "^0.8.16",
|
||||||
|
"sinon": "^1.17.3",
|
||||||
"vinyl-buffer": "^1.0.0",
|
"vinyl-buffer": "^1.0.0",
|
||||||
"vinyl-source-stream": "^1.1.0"
|
"vinyl-source-stream": "^1.1.0"
|
||||||
},
|
},
|
||||||
@ -45,7 +50,7 @@
|
|||||||
"dev": "npm run bundle && gulp start",
|
"dev": "npm run bundle && gulp start",
|
||||||
"bundle": "gulp bundle",
|
"bundle": "gulp bundle",
|
||||||
"test": "npm run bundle && gulp test",
|
"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",
|
"author": "Daniel Seripap",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
|
53
test/unit/audio.js
Normal file
53
test/unit/audio.js
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
1
test/unit/index.js
Normal file
1
test/unit/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
require('./audio.js');
|
Loading…
x
Reference in New Issue
Block a user