Skip to content

Commit

Permalink
add coverage to selenium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philschatz committed Feb 5, 2016
1 parent 1efc04e commit dfbc1a7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"deployment": "gulp prod",
"build": "gulp build",
"test-integration:only": "mocha -R spec ./test-integration/index",
"pretest-integration": "npm run build",
"pretest-integration": "COVERAGE=true npm run build",
"test-integration": "./scripts/run-test-integration.sh",
"lint-cjsx": "./scripts/lint-cjsx-files.sh",
"start": "gulp dev"
Expand Down Expand Up @@ -89,6 +89,7 @@
"gulp-util": "3.0.6",
"gulp-watch": "4.3.5",
"http-server": "0.8.5",
"istanbul": "0.4.1",
"istanbul-instrumenter-loader": "0.1.3",
"json-loader": "0.5.3",
"karma": "0.13.19",
Expand Down
3 changes: 3 additions & 0 deletions test-integration/helpers/describe.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
selenium = require 'selenium-webdriver'
seleniumMocha = require('selenium-webdriver/testing')
_ = require 'underscore'

chai = require 'chai'
chai.use require 'chai-as-promised'
expect = {chai}
Expand All @@ -25,6 +26,8 @@ logger.addHandler (record) ->





describe = (name, cb) ->
seleniumMocha.describe name, ->

Expand Down
26 changes: 26 additions & 0 deletions test-integration/helpers/user.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
_ = require 'underscore'
{TestHelper} = require './test-element'

# Record code coverage before logging out
istanbul = require 'istanbul'
{mergeFileCoverage} = istanbul.utils

COMMON_ELEMENTS =
loginLink:
linkText: 'Login'
Expand Down Expand Up @@ -31,6 +35,21 @@ COMMON_ELEMENTS =
COMMON_ELEMENTS.eitherSignInElement =
css: "#{COMMON_ELEMENTS.searchQuery.css}, #{COMMON_ELEMENTS.usernameInput.css}"


# Record code coverage before logging out.
# Merges the coverage results from multiple tests
__coverage__ = {}
mergeCoverage = (obj) ->
Object.keys(obj).forEach (filePath) ->
original = __coverage__[filePath]
added = obj[filePath]
if original
result = mergeFileCoverage(original, added)
else
result = added
__coverage__[filePath] = result


class User extends TestHelper
constructor: (test) ->
testElementLocator = 'body'
Expand Down Expand Up @@ -78,6 +97,10 @@ class User extends TestHelper
@el.userMenu.isPresent()

_logout: =>
# Pull out the coverage data
@test.driver.executeScript("var c = window.__coverage__; delete window.__coverage__; return c;").then (results) ->
mergeCoverage(results) if results

@el.userMenu.get().click()
@el.logoutForm.get().submit()

Expand All @@ -92,6 +115,9 @@ class User extends TestHelper
@el.homeLink.get().click()


User.getCoverageData = ->
__coverage__

User.logout = (test) ->
user = new User(test).logout()

Expand Down
12 changes: 11 additions & 1 deletion webpack.config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ ExtractTextPlugin = require 'extract-text-webpack-plugin'
webpack = require 'webpack'

isProduction = process.env.NODE_ENV is 'production'
isCoverage = process.env.COVERAGE
LOADERS = if isProduction then [] else ["react-hot", "webpack-module-hot-accept"]
lessLoader = if isProduction
{ test: /\.less$/, loader: ExtractTextPlugin.extract('css!less') }
else
{ test: /\.less$/, loaders: LOADERS.concat('style-loader', 'css-loader', 'less-loader') }

if isCoverage
POST_LOADERS = [
{ test: /\.coffee$/, loaders: ["istanbul-instrumenter"] }
{ test: /\.cjsx$/, loaders: ["istanbul-instrumenter"] }
]
else
POST_LOADERS = []

module.exports =
cache: true

Expand Down Expand Up @@ -41,7 +50,8 @@ module.exports =
{ test: /\.cjsx$/, loaders: LOADERS.concat("coffee-jsx-loader") }
{ test: /\.(png|jpg|svg)/, loader: 'file-loader?name=[name].[ext]'}
{ test: /\.(woff|woff2|eot|ttf)/, loader: "url-loader?limit=30000&name=[name]-[hash].[ext]" }
]
]
postLoaders: POST_LOADERS
resolve:
extensions: ['', '.js', '.json', '.coffee', '.cjsx']

Expand Down

0 comments on commit dfbc1a7

Please sign in to comment.