Skip to content

Commit

Permalink
setup test harness with using grunt + babel
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Dec 18, 2015
1 parent 603cc47 commit 12448b3
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 7 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
build/
test/
examples/
bin/
11 changes: 11 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@
"parser": "babel-eslint",
"rules": {
"indent": [2, 4]
},
"globals": {
"expect": true,
"describe": true,
"before": true,
"beforeEach": true,
"after": true,
"afterEach": true,
"it": true,
"should": true,
"browser": true
}
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ notifications:
language: node_js

node_js:
- '0.10'
- '0.12'

sudo: false

Expand Down
96 changes: 96 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
var os = require('os')

module.exports = function (grunt) {
var argv = require('optimist').argv

var mochaInstanbulOpts = {
scriptPath: require.resolve('isparta/bin/isparta'),
reporter: 'spec',
mochaOptions: ['--compilers', 'js:babel/register', '--recursive', '-t', '60000']
}

var mochaOpts = {
reporter: 'spec',
require: ['babel/register'],
grep: argv.grep,
invert: argv.invert,
bail: argv.bail,
timeout: 10000
}

function addEnv (envs) {
grunt.config.merge({ env: { env: { add: envs } } })
}

grunt.initConfig({
pkgFile: 'package.json',
clean: ['build'],
Expand Down Expand Up @@ -41,6 +64,48 @@ module.exports = function (grunt) {
}]
}
},
mocha_istanbul: {
functional: {
src: ['./test/setup.js', 'test/spec/functional/**/*.js'],
options: mochaInstanbulOpts
},
mobile: {
src: ['./test/setup.js', 'test/spec/mobile/**/*.js'],
options: mochaInstanbulOpts
},
desktop: {
src: ['./test/setup.js', 'test/spec/addValue.js'],
options: mochaInstanbulOpts
}
},
mochaTest: {
functional: {
src: ['./test/setup.js', 'test/spec/functional/**/*.js'],
options: mochaOpts
},
mobile: {
src: ['./test/setup.js', 'test/spec/mobile/**/*.js'],
options: mochaOpts
},
desktop: {
src: ['./test/setup.js', 'test/spec/*.js', 'test/spec/desktop/*.js'],
options: mochaOpts
}
},
'start-selenium-server': {
dev: {
options: {
autostop: false,
downloadUrl: 'https://selenium-release.storage.googleapis.com/2.47/selenium-server-standalone-2.47.0.jar',
downloadLocation: os.tmpdir(),
serverOptions: {},
systemProperties: {}
}
}
},
'stop-selenium-server': {
dev: {}
},
eslint: {
options: {
parser: 'babel-eslint'
Expand Down Expand Up @@ -110,4 +175,35 @@ module.exports = function (grunt) {
'bump:' + (type || 'patch')
])
})

grunt.registerTask('run-test', function () {
grunt.task.run('env', 'config', 'connect', 'start-selenium-server', 'mochaTest', 'passfail')
})

grunt.registerTask('test', function (env, cmd, isSeleniumServerRunning) {
isSeleniumServerRunning = isSeleniumServerRunning === undefined ? true : isSeleniumServerRunning
cmd = cmd || 'mochaTest'
env = env || 'desktop'
var tasks = [cmd + ':' + env]

addEnv({ _ENV: env })
process.env._ENV = env

if (!isSeleniumServerRunning && (env === 'functional' || (env === 'desktop' && !process.env.CI))) {
tasks.unshift('start-selenium-server:dev')
tasks.push('stop-selenium-server:dev')
}

grunt.task.run(tasks)
})

grunt.registerTask('testcover', function (env, isSeleniumServerRunning) {
env = env || process.env._ENV

if (typeof env !== 'string') {
throw new Error('no proper environment specified')
}

return grunt.task.run('test:' + env + ':mocha_istanbul:' + isSeleniumServerRunning)
})
}
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@
"devDependencies": {
"babel": "^5.8.23",
"babel-eslint": "^4.1.1",
"chai": "~2.3.0",
"chai-as-promised": "^5.0.0",
"chai": "^3.4.1",
"chai-as-promised": "^5.1.0",
"chai-string": "^1.1.4",
"codeclimate-test-reporter": "^0.1.1",
"coveralls": "~2.11.2",
"eslint": "^1.4.1",
"eslint-config-standard": "^4.4.0",
Expand All @@ -68,11 +70,14 @@
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-watch": "^0.6.1",
"grunt-eslint": "^17.1.0",
"grunt-mocha-istanbul": "^3.0.1",
"grunt-mocha-test": "^0.12.7",
"grunt-selenium-server": "^0.1.7",
"isparta": "^4.0.0",
"istanbul": "^0.3.13",
"load-grunt-tasks": "^3.2.0",
"mocha": "^2.2.4",
"saucelabs": "^1.0.1",
"should": "^6.0.1"
"mocha": "^2.3.4",
"saucelabs": "^1.0.1"
},
"tags": [
"web",
Expand Down
File renamed without changes.

0 comments on commit 12448b3

Please sign in to comment.