eslint-plugin-playwright icon indicating copy to clipboard operation
eslint-plugin-playwright copied to clipboard

`no-standalone-expect`: False positive when there are multiple `describe` blocks

Open michaelfaith opened this issue 1 year ago • 1 comments
trafficstars

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

michaelfaith avatar May 07 '24 14:05 michaelfaith

Interesting, sounds like an issue with the aliases not applying in all instances for some reason.

mskelton avatar May 07 '24 16:05 mskelton

@michaelfaith I was unable to reproduce this. Could you create a reproduction code sandbox?

mskelton avatar Jun 09 '24 13:06 mskelton

Closing due to lack of reproduction steps

mskelton avatar Jun 28 '24 16:06 mskelton

@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:

image

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.

michaelfaith avatar Jun 28 '24 21:06 michaelfaith

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 avatar Jun 28 '24 21:06 michaelfaith

@michaelfaith I'm guessing you didn't configure global aliases in your config.

https://github.com/playwright-community/eslint-plugin-playwright#aliased-playwright-globals

mskelton avatar Jul 01 '24 18:07 mskelton

@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 avatar Jul 01 '24 22:07 michaelfaith

@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.

mskelton avatar Jul 02 '24 02:07 mskelton