Skip to content
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

jest -t will create page for all skipped session #698

Closed
xuanzhaopeng opened this issue May 11, 2021 · 12 comments
Closed

jest -t will create page for all skipped session #698

xuanzhaopeng opened this issue May 11, 2021 · 12 comments

Comments

@xuanzhaopeng
Copy link

Describe the bug
In PlaywrightEnvironment, we init this.global.page in setup function, when I do jest -t "my test name", it will init page for ever skipped files which consumes a lot of time if I have 50 files but only run 1 file.

To Reproduce
Steps to reproduce the behavior:

Expected behavior
Is it possible to init everything in beforeAll? I noticed we could use skipInitialization , but how could I initialise programmatically in beforeAll?

@mmarkelov
Copy link
Member

@xuanzhaopeng I think this is duplicate #112
I looked through this issue, but there is some limitation from jest and our environment. Unfortunately we couldn't know the status of current test, during the setup of playwright environment

@mmarkelov mmarkelov mentioned this issue May 16, 2021
@mmarkelov
Copy link
Member

@xuanzhaopeng could you please check next version? I hope that i found out the way to skip it

@andrewgremlich
Copy link

andrewgremlich commented May 20, 2021

I'm not sure if this would be related. If it isn't, then I can make another issue.

I have a setupFilesAfterEnv option filled. In the file I have the following code...

beforeAll(() => {
  console.log(browser);

  await jestPlaywright.resetContext({
    storageState: JSON.parse(process.env.STORAGE || ""),
  });
});

If I run a command like jest file-to-be-tested.test.ts, the console.log(browser) does come up with a value.

But if I run a command like jest --testNamePattern <pattern> the console.log(browser) will come up as undefined.

I am using version 1.6.0-rc3

I'll take a look around and see what I can find as well.

@mmarkelov
Copy link
Member

@andrewgremlich i'll take a look

@andrewgremlich
Copy link

andrewgremlich commented May 20, 2021

On the topic of this same issue, when I do run with a --testNamePattern flag activated, I don't seem to be a browser instances per test.

@andrewgremlich
Copy link

ahhh, I see what you did @mmarkelov with the most recent commit for 1.6.0-rc3. I see what I kind find.

@andrewgremlich
Copy link

Couldn't find anything. There isn't a way to filter out tests that don't match the name pattern?

@mmarkelov
Copy link
Member

@andrewgremlich could you please try 1.6.0-rc4. Hope it will help

@andrewgremlich
Copy link

@mmarkelov , I think that did it! Thanks man! And it keeps extra browsers from popping up too.

@xuanzhaopeng
Copy link
Author

@xuanzhaopeng could you please check next version? I hope that i found out the way to skip it

I somehow missed your message, looks works fancy! But anyway I will also update it and check it!

Thanks a lot

@mmarkelov
Copy link
Member

should be fixed in 1.6.0

@kawazoe
Copy link

kawazoe commented Jun 18, 2021

@mmarkelov I was just trying to use the testNamePattern feature and I hit a snag that I think is related to this change.

All the test that are filtered out crashes trying to access page in describes because the variable isn't defined. I'm just trying to pass it to a page object, I don't do anything special with it.

For instance, using a testNamePattern that would skip this test:

describe('foobar', () => {
  let po: PageObject;

  beforeAll(async () => {
    po = new PageObject(page);
  });

  // ...
});

will crash with "page is not defined" when padding it to the PageObject constructor.

I'm on v1.6.1 so definitely after this fix.

As a workaround, I defined a global called 'page' to the value null in my jest config, but that's still a bit weird to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants