Hi there. First than anything, thank you for this amazing project.
I'm using jest version 18.0.0, and babel-jest 18.0.0. I also use webpack (I've pasted all my configs at the bottom).
When running npm run test it throws TypeError: Cannot read property 'instrument' of undefined. I inspected the babel-jest/index.js file and looks like the issue is around line 58 near _ref2.instrument:
return {
canInstrument: true,
getCacheKey(
fileData,
filename,
configString, _ref2)
{let instrument = _ref2.instrument,watch = _ref2.watch;
return crypto.createHash('md5').
update(fileData).
update(configString)
// Don't use the in-memory cache in watch mode because the .babelrc
// file may be modified.
.update(getBabelRC(filename, { useCache: !watch })).
update(instrument ? 'instrument' : '').
digest('hex');
},
Btw, I've tried to upgrade to jest 18.1.0, but the result is the same. Btw, I noticed there is no version 18.1.0 for babel-jest.
Jest configuration seems to be so simple that I might be doing something really silly, my configs are:
package.json
{
"name": "dashboard3",
"version": "1.0.0",
"description": "dashboard app",
"main": "index.js",
"scripts": {
"test": "jest",
"build": "webpack",
"dev": "webpack --devtool eval --progress --colors --watch --content-base build",
"prod": "PROD=1 webpack --progress --colors"
},
"author": "Oscar",
"license": "ISC",
"dependencies": {
"react": "^15.3.2",
"react-dom": "^15.3.2"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-core": "^6.2.1",
"babel-eslint": "^7.1.1",
"babel-jest": "^18.0.0",
"babel-loader": "^6.2.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-object-rest-spread": "^6.20.2",
"babel-polyfill": "^6.22.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-jest": "^18.0.0",
"babel-preset-react": "^6.1.18",
"classnames": "^2.2.1",
"css-loader": "^0.23.0",
"es6-promise": "^3.0.2",
"eslint": "^3.13.1",
"eslint-config-airbnb": "^14.0.0",
"eslint-loader": "^1.6.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.2",
"eslint-plugin-react": "^6.9.0",
"identity-obj-proxy": "^3.0.0",
"immutable": "^3.7.5",
"jest": "^18.0.0",
"jest-cli": "^0.8.2",
"jest-webpack": "^0.2.1",
"jest-webpack-alias": "^2.0.0",
"json-loader": "^0.5.4",
"keymirror": "^0.1.1",
"moment": "^2.11.0",
"moment-timezone": "^0.5.0",
"node-sass": "^3.4.2",
"normalizr": "^2.2.1",
"object-assign": "^4.0.1",
"react-redux": "^4.4.5",
"redux": "^3.6.0",
"redux-logger": "^2.7.4",
"redux-thunk": "^2.1.0",
"sass-loader": "^3.1.2",
"style-loader": "^0.13.0",
"validate.js": "^0.11.1",
"webpack": "^1.12.9",
"webpack-babel-jest": "^1.0.2",
"whatwg-fetch": "1.0.0"
},
"jest": {
"scriptPreprocessor": "./node_modules/babel-jest",
"testFileExtensions": [
"es6",
"js",
"jsx"
],
"moduleFileExtensions": [
"js",
"json",
"es6",
"jsx"
]
}
}
my .babelrc
{
"presets": ["react", "es2015"],
"plugins": ["transform-object-rest-spread"]
}
And my webpack.conf.js
var path = require('path');
var webpack = require('webpack');
require('es6-promise').polyfill(); // latest version of the css loader requires this.
var PROD = JSON.parse(process.env.PROD || "0");
module.exports = {
devtool: 'source-map',
entry: path.resolve(__dirname, 'src/index.js'),
output: {
path: path.resolve(__dirname, '../public/js'),
filename: 'dashboard3-bundle.js',
},
resolve: {
root: [path.resolve(__dirname, 'src'), path.resolve(__dirname, 'node_modules')],
extensions: ['', '.scss', '.js', '.json']
},
plugins: PROD ? [new webpack.optimize.UglifyJsPlugin({minimize: true, compress: {warnings: false }})] : [],
eslint: {
configFile: './.eslintrc'
},
module: {
preLoaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader'
}
],
loaders: [
{
test: /(\.js)?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel?presets[]=react,presets[]=es2015,presets[]=jest',
},
{
test: /\.scss$/,
loaders: ['style', 'css', 'sass']
},
{
test: /\.json$/,
loaders: ['json']
}
]
}
};
Thank you for or any thoughts or guidance.
Sorry, this is not a help forum but an issue tracker. I'm unsure what is going on here, but you may want to ask on stackoverflow or try to create a repro on repl.it or a repository on github that shows this problem.
@cpojer. Thank you for your insights. I apologize for misusing the Issue tracker. My POV is that something is breaking on babel-jest, and that the config is not really that complicated (although verbose), so my first reaction was to ask here in the hopes that someone more experienced than me could spot something, even if it wasn't a proper fix, at least a hint.
Anyway, sorry again, and thank you for your help.
@leftdevel did you solve this?
@sohibul. Yes, I had the wrong jest-cli version. If you check my package.json you'd notice some jest-cli and jest-webpack entries at version 0.8.2. For some reason npm install didn't complain, I guess the jest package should make sure the right dep versions are met. Let me know if that helps.