Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Running Jest tests I got "The body of the arrow function supplied to idx must be a single expression" #19

Closed
davscro opened this issue May 9, 2017 · 13 comments

Comments

@davscro
Copy link

davscro commented May 9, 2017

The body of the arrow function supplied to `idx` must be a single expression (without curly braces).
        36 |            })
        37 |                    .then(res => {
      > 38 |                            const similarItems = idx(res, _ => _.data.similarDeals) || [];
           |                                                               ^
        39 |                            if (similarItems.length) {
        40 | 
        41 |                                    const converted = similarItems.map(item => {

@yungsters
Copy link
Contributor

@davscro What version of babel-plugin-idx are you using? This should have been fixed by 2b4c33c.

@davscro
Copy link
Author

davscro commented May 11, 2017

hi @yungsters ,

"name": "babel-plugin-idx",
 "version": "1.5.1",

"name": "idx", 
"version": "1.5.0"

When I run tests directly from Webstorm everything is OK
screen shot 2017-05-11 at 10 16 41
screen shot 2017-05-11 at 10 17 06

But from console with yarn test i got an error:
Here is the test step: "test": "rimraf results && rimraf coverage && jest --config jest.config.json --coverage --bail"
screen shot 2017-05-11 at 10 18 54

@yungsters
Copy link
Contributor

@davscro Can you share the contents of your jest.config.json?

@davscro
Copy link
Author

davscro commented May 25, 2017

Sure @yungsters
jest.config.json

	"setupTestFrameworkScriptFile": "<rootDir>/setup-jasmine-env.js",
	"coverageReporters": [
		"text-summary",
		"html",
		"cobertura"
	],
	"setupFiles": [
		"<rootDir>/test-setup.js"
	],
	"snapshotSerializers": [
		"<rootDir>/node_modules/enzyme-to-json/serializer"
	],
	"globals": {
		"__DEV__": true
	},
	"coverageThreshold": {
		"global": {
			"branches": 35,
			"functions": 50,
			"lines": 55,
			"statements": 50
		}
	}
}

setup-jasmine-env.js

/* eslint-disable no-undef */
const jasmineReporters = require('jasmine-reporters');

jasmine.VERBOSE = true;
jasmine.getEnv().addReporter(
	new jasmineReporters.JUnitXmlReporter({
		consolidateAll: false,
		savePath: './results',
		filePrefix: 'test-results'
	})
);

test-setup.js

window.matchMedia = window.matchMedia || function() {
	return {
		matches : false,
		addListener : function() {},
		removeListener: function() {}
	};
};

@michalkvasnicak
Copy link

I have the same problem. When I remove --coverage from command, everything works just fine.

@yungsters
Copy link
Contributor

Interesting! I wonder if a coverage plugin is injecting extra AST nodes into the arrow function.

Thanks for that insight. I'll need to brainstorm with @cpojer about how to best proceed.

@jsdario
Copy link

jsdario commented Jun 11, 2017

Is there anyway to work this around? I had the issue above a long time running, I thought to maybe implement a function identical to idx locally rather using the babel plugin.

@yungsters
Copy link
Contributor

Hmm... this is an unfortunate collision between the two plugins. I don't have time to dig into this, but if we could identify the output of the coverage plugin, we can add a special case in babel-plugin-idx to ignore the extra nodes introduced by the coverage plugin.

Open to other ideas, too.

@JanPeter
Copy link

JanPeter commented Sep 7, 2017

Isn't idx just a "hopefully" temporary wrapper around the new optional chaining proposal? If there is currently a babel implementation of the optional chaining proposal, it would be interesting if jest coverage would work with them.

Correct me if I'm wrong, but at least to me it seems that the babel implementation shouldn't be that different?

@dolphin278
Copy link

dolphin278 commented Oct 17, 2017

const f = () => 'a';

turns during jest run with coverage into

() => {/* istanbul ignore next */++cov_14mnsv87h8.f[0];++cov_14mnsv87h8.s[1];return 'a';}

So, when this transformation applied to idx's fake function argument, it violates idx's assertions (not a single stmt, curly braces, referencing values other than single argument's properties, etc).

@dolphin278
Copy link

Looks like babel 7 could solve this issue - it puts each plugin on separate compilation pass, which may prevent conflict between idx babel plugin and instanbul plugin, that included by babel-jest in babel config when we run jest with --coverage.

mrtnzlml added a commit to kiwicom/mobile that referenced this issue Oct 30, 2017
…ibly nullable properties on a JavaScript objects

This also disables Jest code coverage because of babel plugins
conflict. See: facebook/idx#19
@jsdario
Copy link

jsdario commented Nov 29, 2017

You can also use the following workaround jestjs/jest#3549 (comment)

TL;DR use the idx as a package, but don't take the compilation step for the test phase

@yungsters
Copy link
Contributor

This issue is almost a year old now. I'm going to close it out, but please do file a new one if this is still a problem (with Babel 7).

tbergquist-godaddy pushed a commit to kiwicom/mobile that referenced this issue Jan 24, 2019
…ibly nullable properties on a JavaScript objects

This also disables Jest code coverage because of babel plugins
conflict. See: facebook/idx#19
smith added a commit to smith/kibana that referenced this issue Oct 11, 2019
When running Jest with `--coverage`, modules using idx fail with the error shown in facebook/idx#19.

Change the babel configuration so that is `NODE_ENV=test`, the idx plugin is not loaded.
smith added a commit to elastic/kibana that referenced this issue Oct 14, 2019
When running Jest with `--coverage`, modules using idx fail with the error shown in facebook/idx#19.

Change the babel configuration so that is `NODE_ENV=test`, the idx plugin is not loaded.
smith added a commit to smith/kibana that referenced this issue Oct 14, 2019
When running Jest with `--coverage`, modules using idx fail with the error shown in facebook/idx#19.

Change the babel configuration so that is `NODE_ENV=test`, the idx plugin is not loaded.
smith added a commit to elastic/kibana that referenced this issue Oct 14, 2019
When running Jest with `--coverage`, modules using idx fail with the error shown in facebook/idx#19.

Change the babel configuration so that is `NODE_ENV=test`, the idx plugin is not loaded.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants