Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
fix: make use of istanbul-instrumenter-loader to get correct coverage
Browse files Browse the repository at this point in the history
It is important to note that this is version 0.2.0 of the module.
Versions after that does not support the html and lcov reporters
(lcovonly is supported).
  • Loading branch information
mblarsen committed Oct 9, 2017
1 parent 37eff2e commit 2ef1ea6
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"devDependencies": {
"eslint-config-rem": "^3.2.0",
"husky": "^0.14.3",
"istanbul-instrumenter-loader": "0.2.0",
"lerna": "^2.0.0",
"xo": "^0.18.2"
}
Expand Down
45 changes: 33 additions & 12 deletions packages/poi-preset-karma/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,15 @@ module.exports = (options = {}) => {
reporters: ['mocha'].concat(coverage ? ['coverage'] : []),
coverageReporter: {
dir: 'coverage',
reporters: [{
type: 'html',
subdir: 'report-html'
}, {
type: 'lcov',
subdir: 'report-lcov'
}]
reporters: [
{ type: 'text' },
{ type: 'html', subdir: 'report-html' },
{ type: 'lcov', subdir: 'report-lcov' }
]
},
preprocessors: files.reduce((current, next) => {
if (typeof next === 'object' && next.included !== false) {
current[next.pattern] = ['webpack', 'sourcemap']
} else if (typeof next === 'string') {
current[next] = ['webpack', 'sourcemap']
}
const key = typeof next === 'object' && next.included !== false ? next.pattern : next
current[key] = ['webpack']
return current
}, {}),
webpackMiddleware: {
Expand All @@ -76,6 +71,32 @@ module.exports = (options = {}) => {

delete webpackConfig.entry

if (coverage) {
/* for general usage */
webpackConfig.module.rules = [
{
test: /\.(jsx?)$/,
exclude: /(node_modules|\.test\.jsx?)/,
enforce: 'post',
loader: 'istanbul-instrumenter-loader',
query: {
esModules: true
}
}
].concat(webpackConfig.module.rules)
/* for vue (assumes vue-loader) */
webpackConfig.module.rules = webpackConfig.module.rules
.map(r => {
const vueLoaderPos = r.use && r.use.findIndex(u => u.loader === 'vue-loader')
if (typeof vueLoaderPos === 'undefined' || vueLoaderPos === -1) {
return r
}
r.use[vueLoaderPos].options.preLoaders = r.use[vueLoaderPos].options.preLoaders || {}
r.use[vueLoaderPos].options.preLoaders.js = 'istanbul-instrumenter-loader?esModules=true'
return r
})
}

const karmaConfig = poi.merge(defaultConfig, poi.options.karma)
karmaConfig.webpack = webpackConfig

Expand Down
142 changes: 130 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ JSONStream@^1.0.4:
jsonparse "^1.2.0"
through ">=2.2.7 <3"

abbrev@1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"

[email protected]:
version "1.0.9"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"

acorn-jsx@^3.0.0:
version "3.0.1"
resolved "http://registry.npm.taobao.org/acorn-jsx/download/acorn-jsx-3.0.1.tgz#afdf9488fb1ecefc8348f6fb22f464e32a58b36b"
Expand Down Expand Up @@ -125,7 +133,7 @@ arrify@^1.0.0, arrify@^1.0.1:
version "1.0.1"
resolved "http://registry.npm.taobao.org/arrify/download/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"

async@^1.4.0, async@^1.5.0:
async@1.x, async@^1.4.0, async@^1.5.0:
version "1.5.2"
resolved "http://registry.npm.taobao.org/async/download/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"

Expand All @@ -145,6 +153,10 @@ balanced-match@^1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/balanced-match/download/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"

big.js@^3.1.3:
version "3.2.0"
resolved "https://registry.yarnpkg.com/big.js/-/big.js-3.2.0.tgz#a5fc298b81b9e0dca2e458824784b65c52ba588e"

boxen@^1.0.0:
version "1.2.1"
resolved "http://registry.npm.taobao.org/boxen/download/boxen-1.2.1.tgz#0f11e7fe344edb9397977fc13ede7f64d956481d"
Expand Down Expand Up @@ -690,6 +702,10 @@ duplexer@^0.1.1:
version "0.1.1"
resolved "http://registry.npm.taobao.org/duplexer/download/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"

emojis-list@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"

enhance-visitors@^1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/enhance-visitors/download/enhance-visitors-1.0.0.tgz#aa945d05da465672a1ebd38fee2ed3da8518e95a"
Expand Down Expand Up @@ -758,6 +774,17 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "http://registry.npm.taobao.org/escape-string-regexp/download/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"

[email protected]:
version "1.8.1"
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.8.1.tgz#5a5b53af4693110bebb0867aa3430dd3b70a1018"
dependencies:
esprima "^2.7.1"
estraverse "^1.9.1"
esutils "^2.0.2"
optionator "^0.8.1"
optionalDependencies:
source-map "~0.2.0"

escope@^3.6.0:
version "3.6.0"
resolved "http://registry.npm.taobao.org/escope/download/escope-3.6.0.tgz#e01975e812781a163a6dadfdd80398dc64c889c3"
Expand Down Expand Up @@ -923,6 +950,10 @@ espree@^3.1.3, espree@^3.4.0:
acorn "^5.1.1"
acorn-jsx "^3.0.0"

[email protected], esprima@^2.7.1:
version "2.7.3"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"

esprima@^4.0.0:
version "4.0.0"
resolved "http://registry.npm.taobao.org/esprima/download/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"
Expand All @@ -946,6 +977,10 @@ esrecurse@^4.1.0:
estraverse "^4.1.0"
object-assign "^4.0.1"

estraverse@^1.9.1:
version "1.9.3"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-1.9.3.tgz#af67f2dc922582415950926091a4005d29c9bb44"

estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1, estraverse@^4.2.0:
version "4.2.0"
resolved "http://registry.npm.taobao.org/estraverse/download/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"
Expand Down Expand Up @@ -1177,6 +1212,16 @@ github-url-from-git@^1.4.0:
version "1.5.0"
resolved "http://registry.npm.taobao.org/github-url-from-git/download/github-url-from-git-1.5.0.tgz#f985fedcc0a9aa579dc88d7aff068d55cc6251a0"

glob@^5.0.15:
version "5.0.15"
resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1"
dependencies:
inflight "^1.0.4"
inherits "2"
minimatch "2 || 3"
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.2:
version "7.1.2"
resolved "http://registry.npm.taobao.org/glob/download/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
Expand Down Expand Up @@ -1233,7 +1278,7 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
version "4.1.11"
resolved "http://registry.npm.taobao.org/graceful-fs/download/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"

handlebars@^4.0.2:
handlebars@^4.0.1, handlebars@^4.0.2:
version "4.0.10"
resolved "http://registry.npm.taobao.org/handlebars/download/handlebars-4.0.10.tgz#3d30c718b09a3d96f23ea4cc1f403c4d3ba9ff4f"
dependencies:
Expand All @@ -1249,6 +1294,10 @@ has-ansi@^2.0.0:
dependencies:
ansi-regex "^2.0.0"

has-flag@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"

has-flag@^2.0.0:
version "2.0.0"
resolved "http://registry.npm.taobao.org/has-flag/download/has-flag-2.0.0.tgz#e8207af1cc7b30d446cc70b734b5e8be18f88d51"
Expand Down Expand Up @@ -1544,6 +1593,33 @@ isexe@^2.0.0:
version "2.0.0"
resolved "http://registry.npm.taobao.org/isexe/download/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"

[email protected]:
version "0.2.0"
resolved "https://registry.yarnpkg.com/istanbul-instrumenter-loader/-/istanbul-instrumenter-loader-0.2.0.tgz#643e4e5e4e8f9466863a29a977d283ab372c019c"
dependencies:
istanbul "0.x.x"
loader-utils "0.x.x"
object-assign "4.x.x"

[email protected]:
version "0.4.5"
resolved "https://registry.yarnpkg.com/istanbul/-/istanbul-0.4.5.tgz#65c7d73d4c4da84d4f3ac310b918fb0b8033733b"
dependencies:
abbrev "1.0.x"
async "1.x"
escodegen "1.8.x"
esprima "2.7.x"
glob "^5.0.15"
handlebars "^4.0.1"
js-yaml "3.x"
mkdirp "0.5.x"
nopt "3.x"
once "1.x"
resolve "1.1.x"
supports-color "^3.1.0"
which "^1.1.1"
wordwrap "^1.0.0"

jest-docblock@^20.0.1:
version "20.0.3"
resolved "http://registry.npm.taobao.org/jest-docblock/download/jest-docblock-20.0.3.tgz#17bea984342cc33d83c50fbe1545ea0efaa44712"
Expand All @@ -1556,6 +1632,13 @@ js-types@^1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/js-types/download/js-types-1.0.0.tgz#d242e6494ed572ad3c92809fc8bed7f7687cbf03"

[email protected]:
version "3.10.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc"
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^3.5.1:
version "3.9.1"
resolved "http://registry.npm.taobao.org/js-yaml/download/js-yaml-3.9.1.tgz#08775cebdfdd359209f0d2acd383c8f86a6904a0"
Expand All @@ -1577,6 +1660,10 @@ json-stringify-safe@^5.0.1:
version "5.0.1"
resolved "http://registry.npm.taobao.org/json-stringify-safe/download/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"

json5@^0.5.0:
version "0.5.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"

jsonfile@^3.0.0:
version "3.0.1"
resolved "http://registry.npm.taobao.org/jsonfile/download/jsonfile-3.0.1.tgz#a5ecc6f65f53f662c4415c7675a0331d0992ec66"
Expand Down Expand Up @@ -1683,6 +1770,15 @@ load-json-file@^2.0.0:
pify "^2.0.0"
strip-bom "^3.0.0"

[email protected]:
version "0.2.17"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.17.tgz#f86e6374d43205a6e6c60e9196f17c0299bfb348"
dependencies:
big.js "^3.1.3"
emojis-list "^2.0.0"
json5 "^0.5.0"
object-assign "^4.0.1"

locate-path@^2.0.0:
version "2.0.0"
resolved "http://registry.npm.taobao.org/locate-path/download/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
Expand Down Expand Up @@ -1802,7 +1898,7 @@ mimic-fn@^1.0.0:
version "1.1.0"
resolved "http://registry.npm.taobao.org/mimic-fn/download/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18"

minimatch@^3.0.0, minimatch@^3.0.3, minimatch@^3.0.4:
"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.3, minimatch@^3.0.4:
version "3.0.4"
resolved "http://registry.npm.taobao.org/minimatch/download/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
dependencies:
Expand All @@ -1824,7 +1920,7 @@ minimist@~0.0.1:
version "0.0.10"
resolved "http://registry.npm.taobao.org/minimist/download/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"

mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
mkdirp@0.5.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
version "0.5.1"
resolved "http://registry.npm.taobao.org/mkdirp/download/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
Expand Down Expand Up @@ -1863,6 +1959,12 @@ natural-compare@^1.4.0:
version "1.4.0"
resolved "http://registry.npm.taobao.org/natural-compare/download/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"

[email protected]:
version "3.0.6"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"
dependencies:
abbrev "1"

normalize-package-data@^2.3.0, normalize-package-data@^2.3.2, normalize-package-data@^2.3.4, normalize-package-data@^2.3.5:
version "2.4.0"
resolved "http://registry.npm.taobao.org/normalize-package-data/download/normalize-package-data-2.4.0.tgz#12f95a307d58352075a04907b84ac8be98ac012f"
Expand Down Expand Up @@ -1899,11 +2001,11 @@ obj-props@^1.0.0:
version "1.1.0"
resolved "http://registry.npm.taobao.org/obj-props/download/obj-props-1.1.0.tgz#626313faa442befd4a44e9a02c3cb6bde937b511"

object-assign@^4.0.1, object-assign@^4.1.0:
object-assign@4.x.x, object-assign@^4.0.1, object-assign@^4.1.0:
version "4.1.1"
resolved "http://registry.npm.taobao.org/object-assign/download/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"

once@^1.3.0:
once@1.x, once@^1.3.0:
version "1.4.0"
resolved "http://registry.npm.taobao.org/once/download/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
dependencies:
Expand All @@ -1926,7 +2028,7 @@ optimist@^0.6.1:
minimist "~0.0.1"
wordwrap "~0.0.2"

optionator@^0.8.2:
optionator@^0.8.1, optionator@^0.8.2:
version "0.8.2"
resolved "http://registry.npm.taobao.org/optionator/download/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64"
dependencies:
Expand Down Expand Up @@ -2267,6 +2369,10 @@ resolve-from@^2.0.0:
version "2.0.0"
resolved "http://registry.npm.taobao.org/resolve-from/download/resolve-from-2.0.0.tgz#9480ab20e94ffa1d9e80a804c7ea147611966b57"

[email protected]:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"

resolve@^1.1.6, resolve@^1.2.0:
version "1.4.0"
resolved "http://registry.npm.taobao.org/resolve/download/resolve-1.4.0.tgz#a75be01c53da25d934a98ebd0e4c4a7312f92a86"
Expand Down Expand Up @@ -2391,6 +2497,12 @@ source-map@^0.4.4:
dependencies:
amdefine ">=0.0.4"

source-map@~0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.2.0.tgz#dab73fbcfc2ba819b4de03bd6f6eaa48164b3f9d"
dependencies:
amdefine ">=0.0.4"

source-map@~0.5.1:
version "0.5.6"
resolved "http://registry.npm.taobao.org/source-map/download/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
Expand Down Expand Up @@ -2504,6 +2616,12 @@ supports-color@^2.0.0:
version "2.0.0"
resolved "http://registry.npm.taobao.org/supports-color/download/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"

supports-color@^3.1.0:
version "3.2.3"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.2.3.tgz#65ac0504b3954171d8a64946b2ae3cbb8a5f54f6"
dependencies:
has-flag "^1.0.0"

supports-color@^4.0.0:
version "4.2.1"
resolved "http://registry.npm.taobao.org/supports-color/download/supports-color-4.2.1.tgz#65a4bb2631e90e02420dba5554c375a4754bb836"
Expand Down Expand Up @@ -2742,7 +2860,7 @@ which-module@^2.0.0:
version "2.0.0"
resolved "http://registry.npm.taobao.org/which-module/download/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"

which@^1.2.9:
which@^1.1.1, which@^1.2.9:
version "1.3.0"
resolved "http://registry.npm.taobao.org/which/download/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a"
dependencies:
Expand All @@ -2768,14 +2886,14 @@ [email protected]:
version "0.0.2"
resolved "http://registry.npm.taobao.org/wordwrap/download/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f"

wordwrap@^1.0.0, wordwrap@~1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/wordwrap/download/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"

wordwrap@~0.0.2:
version "0.0.3"
resolved "http://registry.npm.taobao.org/wordwrap/download/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"

wordwrap@~1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/wordwrap/download/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"

wrap-ansi@^2.0.0:
version "2.1.0"
resolved "http://registry.npm.taobao.org/wrap-ansi/download/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"
Expand Down

0 comments on commit 2ef1ea6

Please sign in to comment.