Created
March 31, 2015 15:31
-
-
Save pbeshai/7bb7ba4bf257249493de to your computer and use it in GitHub Desktop.
Jest + ES6 via Babel. Coverage with Istanbul not working for individual files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> jest --coverage | |
Using Jest CLI v0.4.0 | |
Waiting on 1 test... | |
PASS web/__tests__/StatsTable-test.js (2.168s) | |
1 test passed (1 total) | |
Run time: 4.9s | |
--------------------|-----------|-----------|-----------|-----------| | |
File | % Stmts |% Branches | % Funcs | % Lines | | |
--------------------|-----------|-----------|-----------|-----------| | |
table/ | 24.11 | 9.55 | 25.71 | 25.1 | | |
StatsTable.js | 24.11 | 9.55 | 25.71 | 25.1 | | |
--------------------|-----------|-----------|-----------|-----------| | |
All files | 24.11 | 9.55 | 25.71 | 25.1 | | |
--------------------|-----------|-----------|-----------|-----------| | |
Failed with unexpected error. | |
/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/src/jest.js:179 | |
throw error; | |
^ | |
TypeError: Cannot set property 'covered' of undefined | |
at /Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:174:66 | |
at Array.forEach (native) | |
at annotateLines (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:172:28) | |
at HtmlReport.Report.mix.writeDetailPage (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:406:9) | |
at /Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:472:26 | |
at SyncFileWriter.extend.writeFile (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/util/file-writer.js:57:9) | |
at FileWriter.extend.writeFile (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/util/file-writer.js:147:23) | |
at /Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:471:24 | |
at Array.forEach (native) | |
at HtmlReport.Report.mix.writeFiles (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:465:23) | |
at /Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:467:22 | |
at Array.forEach (native) | |
at HtmlReport.Report.mix.writeFiles (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:465:23) | |
at HtmlReport.Report.mix.writeReport (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:549:14) | |
at LcovReport.Report.mix.writeReport (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/report/lcov.js:55:19) | |
at /Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/reporter.js:93:20 | |
at Array.forEach (native) | |
at Object.Reporter.write (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/istanbul/lib/reporter.js:87:30) | |
at DefaultTestReporter.IstanbulTestReporter.onRunComplete (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/src/IstanbulTestReporter.js:33:14) | |
at /Users/pbeshai/Workspace/redacted/node_modules/jest-cli/src/TestRunner.js:453:40 | |
at _fulfilled (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/q/q.js:798:54) | |
at self.promiseDispatch.done (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/q/q.js:827:30) | |
at Promise.promise.promiseDispatch (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/q/q.js:760:13) | |
at /Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/q/q.js:574:44 | |
at flush (/Users/pbeshai/Workspace/redacted/node_modules/jest-cli/node_modules/q/q.js:108:17) | |
at /Users/pbeshai/Workspace/redacted/node_modules/jest-cli/src/lib/FakeTimers.js:325:7 | |
at process._tickCallback (node.js:442:13) | |
npm ERR! redacted@0.0.1 coverage: `jest --coverage` | |
npm ERR! Exit status 8 | |
npm ERR! | |
npm ERR! Failed at the redacted@0.0.1 coverage script. | |
npm ERR! This is most likely a problem with the redacted package, | |
npm ERR! not with npm itself. | |
npm ERR! Tell the author that this fails on your system: | |
npm ERR! jest --coverage | |
npm ERR! You can get their info via: | |
npm ERR! npm owner ls redacted | |
npm ERR! There is likely additional logging output above. | |
npm ERR! System Darwin 14.1.0 | |
npm ERR! command "/Users/pbeshai/.nvm/v0.10.36/bin/node" "/Users/pbeshai/.nvm/v0.10.36/bin/npm" "run" "coverage" | |
npm ERR! cwd /Users/pbeshai/Workspace/redacted | |
npm ERR! node -v v0.10.36 | |
npm ERR! npm -v 1.4.28 | |
npm ERR! code ELIFECYCLE | |
npm ERR! | |
npm ERR! Additional logging details can be found in: | |
npm ERR! /Users/pbeshai/Workspace/redacted/npm-debug.log | |
npm ERR! not ok code 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AS PER https://github.com/facebook/jest/issues/114 | |
// Provides various polyfills during testing. | |
require('babel/polyfill'); | |
var fs = require('fs'); | |
var sms = require("source-map-support"); | |
// I couldn't find an obvious way to get source-map-support working with inline source maps. | |
// So we write the maps to the file system in preprocessor, then read them during the `test framework setup` stage. | |
var map_path = function(string) { | |
return '/tmp/' + require('crypto').createHash('md5').update(string).digest('hex') + '.map'; | |
}; | |
sms.install({ | |
retrieveSourceMap: function(source) { | |
var map; | |
try { | |
map = fs.readFileSync(map_path(source), 'utf8'); | |
} catch (err) { | |
return; | |
} | |
return map ? { | |
url: undefined, | |
map: map | |
} : undefined ; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var babel = require('babel'); | |
var fs = require('fs'); | |
// setup source mapping as per https://github.com/facebook/jest/issues/114 | |
var map_path = function(string) { | |
return '/tmp/' + require('crypto').createHash('md5').update(string).digest('hex') + '.map'; | |
}; | |
module.exports = { | |
process: function (src, filename) { | |
if (filename.indexOf("node_modules") !== -1 || filename.indexOf("bower_components") !== -1) { | |
return src; | |
} | |
if (babel.canCompile(filename)) { | |
// Force inclusion of the polyfill, then append regular compiled output. | |
var compiled = babel.transform(src, { filename: filename, sourceMap: true }); | |
var result = compiled.code; | |
fs.writeFileSync(map_path(filename), JSON.stringify(compiled.map)); | |
return result; | |
} | |
return src; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
... | |
"jest": { | |
"testPathDirs": [ | |
"web" | |
], | |
"testPathIgnorePatterns": [ | |
"/node_modules/", | |
"/bower_components/" | |
], | |
"setupEnvScriptFile": "<rootDir>/jest-prepare.js", | |
"scriptPreprocessor": "<rootDir>/jest-preprocessor.js", | |
"unmockedModulePathPatterns": [ | |
"<rootDir>/node_modules/react", | |
"<rootDir>/node_modules/source-map-support" | |
] | |
}, | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment