eslint-plugin-playwright
eslint-plugin-playwright copied to clipboard
`no-standalone-expect`: False positive when there are multiple `describe` blocks
If using nested describe blocks to organize multiple sets of tests, the expect calls within the it tests in the describe blocks after the first, are causing no-standalone-expect to flag them incorrectly.
describe('base', () => {
it('top level test', async () => {
expect... // << this one doesn't flag
});
describe('nested', () => {
it('nested test', async () => {
expect... // << this one flags no-standalone-expect (false positive)
});
});
});
Note: if the test function is test instead of it, then it also doesn't flag. It only seems to impact tests that use it
Interesting, sounds like an issue with the aliases not applying in all instances for some reason.
@michaelfaith I was unable to reproduce this. Could you create a reproduction code sandbox?
Closing due to lack of reproduction steps
@mskelton Sorry for not responding sooner. I can upload a reproduction, but a really simple recreation that might help shows how simply aliasing the test import breaks this test:
This isn't exactly the same as our issue; I still need to dig into our set up to see what we're doing in terms of aliasing, but this is a simple recreation.
It's also worth noting that it broke the expect-expect test too. That "basic test without expect" it should have a violation that it didn't report here.
@michaelfaith I'm guessing you didn't configure global aliases in your config.
https://github.com/playwright-community/eslint-plugin-playwright#aliased-playwright-globals
@michaelfaith I'm guessing you didn't configure global aliases in your config.
https://github.com/playwright-community/eslint-plugin-playwright#aliased-playwright-globals
I did not. Is that necessary even for local import aliases, like this? I confirmed that if I add the following, it works as expected.
settings: {
playwright: {
globalAliases: {
test: ['it'],
},
},
},
@michaelfaith Yes, it's necessary even with import aliases. The primary reason for this is that imports often can come from files which define fixtures, so the import source isn't always just @playwright/test, so auto-detecting it is not something that can always be done.