Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add npm Karma plugins and rake task for JavaScript testing #46

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions client/assets/javascripts/spec/karma/config/unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Karma configuration
// Generated on Wed Jul 15 2015 10:58:46 GMT+0000 (UTC)

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: ['mocha', 'chai'],


// list of files / patterns to load in the browser
files: [
'../../../../node_modules/phantomjs-polyfill/bind-polyfill.js',
'../*_spec.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: {
'../*_spec.js' : ['webpack', 'sourcemap']
},


// 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: ['PhantomJS'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
})
}
15 changes: 15 additions & 0 deletions client/assets/javascripts/spec/sample_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var React = require('react');
var ReactAddons = require('react/addons');
var TestUtils = React.addons.TestUtils;
//var assert = require('assert');
//var expect = require('expect');
//var Root = require('../root');

describe('Array', function(){
describe('#indexOf()', function(){
it('should return -1 when the value is not present', function(){
assert.equal(-1, [1,2,3].indexOf(5));
assert.equal(-1, [1,2,3].indexOf(0));
})
})
})
4 changes: 2 additions & 2 deletions client/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ module.exports = function karmaMain(config) {

singleRun: process.env.CONTINUOUS_INTEGRATION === 'true',

frameworks: ['mocha'],
frameworks: ['mocha', 'chai'],

files: [
'tests.webpack.js'
'tests.webpack.js',
],

preprocessors: {
Expand Down
12 changes: 12 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"babel-eslint": "^3.1.7",
"bootstrap-sass": "^3.3.4",
"bootstrap-sass-loader": "^1.0.4",
"chai": "^3.1.0",
"css-loader": "^0.13.1",
"eslint": "^0.21.2",
"eslint-plugin-react": "^2.3.0",
Expand All @@ -51,7 +52,18 @@
"gulp": "^3.8.11",
"gulp-eslint": "^0.12.0",
"jscs": "^1.13.1",
"jsdom": "^5.6.1",
"karma": "^0.12.17",
"karma-chai": "^0.1.0",
"karma-cli": "^0.1.0",
"karma-mocha": "^0.2.0",
"karma-phantomjs-launcher": "^0.1.4",
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^1.6.0",
"mocha": "^1.20.1",
"node-sass": "^3.1.2",
"phantomjs": "1.9.7-1",
"phantomjs-polyfill": "0.0.1",
"react-hot-loader": "^1.2.7",
"sass-loader": "^1.0.2",
"style-loader": "^0.12.2",
Expand Down
5 changes: 5 additions & 0 deletions lib/tasks/js_tests.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
desc "Run Karma tests"
task :js_tests do
puts "Running Karma Tests"
sh "cd client && karma start assets/javascripts/spec/karma/config/unit.js"
end