New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tests that use callbacks #4881
Comments
SGTM. |
@jeddy3 Thanks for the feedback! There are many tests to be fixed, so I think it better to tackle this issue by multiple pull requests to help reviewers. |
I find 2 issues discussing similar problems to this issue:
Unfortunately, it seems there is not an easy way. 😓 |
FYI. If this ESLint rule (maybe |
Progress report (25 files left): $ git log --format=%H -1
e25b5a203deb63c642e0b3b4bbab8a320180725c
$ git grep -l -E '\.(then|catch|finally)' '**/*.test.js'
...
|
I wonder if it could be valuable for
@ybiquitous you should be able to create a file like this that calls That won't work if you have tests that don't use I'll try to see if I can get onto shipping |
@G-Rath Thank you for the advice! That’s also a nice idea (I didn't know such a way). 😄 But, I’m a bit concerned about the way that at least one So, I think it best if we can check them via ESLint. |
- Remove the `del` package that will be needless. - Use asnyc/await syntax for readability. (#4881) - Fix CSS code indent for consistency.
- Remove the `del` package that will be needless. - Use async/await syntax for readability. (#4881) - Fix CSS code indent for consistency.
- Remove the `del` package that will be needless. - Use async/await syntax for readability. (#4881) - Fix CSS code indent for consistency.
- Reduce redundant callbacks via `async/await` syntax. (#4881) - Use `fs.existsSync()` instead of `fs.access()`. See <https://nodejs.org/api/fs.html#fs_fs_existssync_path> - Fix the disabled test. (#5309) - Inline redundant local variables. - Make expectations using `typeof` more accurate.
* Refactor `lib/__tests__/standalone-cache.test.js` - Reduce redundant callbacks via `async/await` syntax. (#4881) - Use `fs.existsSync()` instead of `fs.access()`. See <https://nodejs.org/api/fs.html#fs_fs_existssync_path> - Fix the disabled test. (#5309) - Inline redundant local variables. - Make expectations using `typeof` more accurate. * Reduce local variables by improving `getConfig()`
I found a bug in the following test code using a callback:
stylelint/lib/utils/__tests__/isStandardSyntaxRule.test.js
Lines 58 to 62 in 9f93d1f
When I add
done()
to the test as follows, this test fails.Because this Less node
.mixin-name(@var);
is anAtRule
(notRule
), and thusexpect()
is not called in the callback passed tolessRules()
.When I rewrite the test without a callback as follows, the test fails still, though.
However, the failure is due to passing an
AtRule
toisStandardSyntaxRule()
, and I believe there is no such a case actually.(Perhaps, we can fix the failure by returning
false
ifrule.type !== 'rule'
.)There are such invalid test codes using a callback in the other test files, e.g.:
stylelint/lib/utils/__tests__/isStandardSyntaxAtRule.test.js
Lines 10 to 14 in 9f93d1f
Sadly, the ESLint
jest/no-test-callback
rule cannot detect such problematic code patterns... 😢(see https://github.com/jest-community/eslint-plugin-jest/blob/v23.18.2/docs/rules/no-test-callback.md)
None.
See the description above about the reproduction.
None.
The HEAD version.
Via Jest, e.g.
npx jest lib/utils/__tests__/isStandardSyntaxRule.test.js
No.
I think we should not use a callback in the test code as possible.
Or, if a callback is needed, we should wrap the callback with
return new Promise(done => {})
Some tests do not work correctly.
The text was updated successfully, but these errors were encountered: