Skip to content

Commit

Permalink
(test): add code coverage for cypress tests ALSO NOT WORKING, see #6
Browse files Browse the repository at this point in the history
- instrument the code with istanbul and output usage into .nyc_output
- add nyc to create coverage reports with the data in .nyc_output

- output sourcemaps with browserify and webpack
  - FIXME: this doesn't seem to change anything????

FIXME: physijs_worker.js doesn't appear in coverage reports at all
  • Loading branch information
agilgur5 committed Nov 27, 2019
1 parent 3851267 commit 26429be
Show file tree
Hide file tree
Showing 6 changed files with 1,183 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# coverage
.nyc_output/
coverage/

### Node ###

# Logs
Expand Down
22 changes: 19 additions & 3 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
const browserify = require('@cypress/browserify-preprocessor')
const webpack = require('@cypress/webpack-preprocessor')
const codeCovTask = require('@cypress/code-coverage/task')

const ammoPath = require.resolve('../../physijs/vendor/ammo.js')

const bProcess = browserify({
browserifyOptions: {
// don't parse ammo
noParse: [ammoPath],
// override the preprocessor default (which runs babelify)
transform: []
debug: true, // inline source maps
// add babelify solely for usage of babel-plugin-istanbul
transform: [['babelify', {
ignore: [/ammo/, /three/], // this is an EXPONENTIAL speed up
ast: false,
babelrc: false,
plugins: ['istanbul'] // instrument with istanbul
}]]
}
})

Expand All @@ -19,7 +26,14 @@ const wProcess = webpack({
// don't parse ammo
module: {
noParse: ammoPath,
}
rules: [{
test: /\.js$/,
use: { loader: 'istanbul-instrumenter-loader' },
exclude: [/ammo/, /three/] // this is an EXPONENTIAL speed up
}]
},
// sourcemaps for coverage reporting
devtool: 'inline-cheap-source-map'
}
})

Expand All @@ -31,4 +45,6 @@ module.exports = (on) => {
}
return bProcess(file)
})

on('task', codeCovTask)
}
1 change: 1 addition & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require('./commands')
require('@cypress/code-coverage/support')

// nothing to screenshot here
Cypress.Screenshot.defaults({
Expand Down
3 changes: 3 additions & 0 deletions nyc.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
reporter: ['text', 'lcov']
}
Loading

0 comments on commit 26429be

Please sign in to comment.