Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
In the process of updating stylelint-config-wordpress to use @wordpress/scripts ESLint reports a bunch of no-undef errors for the _test_ files in the /__tests__/ folder, for example:
/Users/netweb/Code/WordPress/stylelint-config-wordpress/__tests__/index.test.js
9:1 error 'describe' is not defined no-undef
12:2 error 'beforeEach' is not defined no-undef
19:2 error 'it' is not defined no-undef
21:4 error 'expect' is not defined no-undef
Describe the solution you'd like
A clear and concise description of what you want to happen.
The @wordpress/scripts package already includes Jest for running unit and e2e tests and as such I would expect that writing tests with Jest should include the ESLint Jest rules also.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
The alternate solution is to install eslint-plugin-jest in the stylelint-config-wordpress repo instead and add an ESLint configuration.
The #17027 PR comes close to solving the above solution by adding a new ESLint ruleset @wordpress/eslint-plugin/test-unit that includes Jest.
The issue with that as it currently stands is it does not inherit the current @wordpress/eslint-plugin/recommended ruleset.
cc @gziolo
The issue with that as it currently stands is it does not inherit the current @wordpress/eslint-plugin/recommended ruleset.
In #17033, there is change to the recommended config included as well. It adds all Jest related rules to all files which Jest would match as test files. So it sort of works the other way around than you propose. I has the same issue when trying to add tests to Gutenberg examples repository here: https://github.com/WordPress/gutenberg-examples/issues/84.
In #17033, there is change to the recommended config included as well. It adds all Jest related rules to all files which Jest would match as test files.
Thanks, but I don't see any changes to the "recommended config" in this PR
I meant changes highlighted here: https://github.com/WordPress/gutenberg/pull/17027#discussion_r314637653. I shared a wrong PR 馃檭
I hope to release the next major version of @wordpress/scripts next Wednesday/Thursday which should fix it. Let鈥檚 reopen only in case when it doesn鈥檛 work as expected afterward.
@ntwb - new major version of @wordpress/scripts is out but it doesn't work for test files out of the box and I can't figure out why. If I copy https://github.com/WordPress/gutenberg/blob/master/packages/scripts/config/.eslintrc.js to the root of my project it works perfectly fine. There might be some bug in Eslint with how overrides are resolved inside config files located in node_modules folder. Can you double-check if it works for you?
Related PR where I test it: https://github.com/WordPress/gutenberg-examples/pull/87
I filed a new issue in ESLint: eslint/eslint#12278.
It looks like the fix in ESLint is going to be breaking change and would eventually land in 7.0: https://github.com/eslint/rfcs/pull/37. We will need a temporary fix. I think it's fine to always enable configs for unit and e2e tests in @wordpress/scripts for the time being.
Not sure on the timeline but there is broad support for a rework of the ESLint configuration as outlined in https://github.com/eslint/rfcs/pull/9
That, if agreed to would also land in a _major_ release of ESLint, possibly 7.0
It only confirms my assumption that we need to have a working solution in the meantime as it might take months before we see 7.0 :)
A temporary workaround is ready with https://github.com/WordPress/gutenberg/pull/17744. I don't think it makes sense to wait until ESLint 7.0 is out as it might take some time.
Should we close it now that #17744 was merged? We will be able to revisit it after eslint/rfcs#37 is implemented but it might take months.
Yup, closing 馃憤馃徏
The upstream issue was fixed https://github.com/eslint/eslint/pull/12887 in ESLint but we need until v7.0.0 is out.