Skip to content

Enhance the forbidOnly mode message to guide the user towards the configuration option#23146

Merged
dgozman merged 10 commits into
microsoft:mainfrom
TomasHubelbauer:patch-1
May 25, 2023
Merged

Enhance the forbidOnly mode message to guide the user towards the configuration option#23146
dgozman merged 10 commits into
microsoft:mainfrom
TomasHubelbauer:patch-1

Conversation

@TomasHubelbauer

Copy link
Copy Markdown
Contributor

Hi, I am putting this PR out as a feeler to see if there's interested in improving this error message, but the copy is by no means final and I am open to improvement suggestions.

My intention here is to:

  • Explain what a "focused item" is - that we're talking about a test and it being focused is most likely down it using only

    Are there other types of "items"? Are there other ways to make them focused other than only?

  • Explain why we're even in focused mode and how to control it

    The default scaffolded Playwright config file includes a forbidMode expression driven by whether CI=1 is set.
    I ran into this when trying to reproduce a CI issue locally so I had it set and unknowingly entered focus only mode.
    I wasn't aware this mode was a thing because I was using the default configuration from npm init and did not familiarize myself with all the options in it.

Is there a way to tell if we're in a TypeScript or JavaScript project in this function? I would use that to display the configuration file name with the right extension.

…figuration option

The message now explains what a focused item is (by using the `only` keyword which is more likely to trigger the realization in the user than the general name) as well as why the mode is configured (in the default configuration this is set to whether `CI=1` is set).

Signed-off-by: Tomáš Hübelbauer <tomas@hubelbauer.net>
@pavelfeldman

Copy link
Copy Markdown
Member

A couple of tests failed due to the change!

@TomasHubelbauer

Copy link
Copy Markdown
Contributor Author

@pavelfeldman Yeah I will adjust them, but I am curious if you have a better suggestion for the message copy as well as whether there is a way to distinguish whether the project is in TypeScript or JavaScript first. Do you have any input there?

@dgozman

dgozman commented May 22, 2023

Copy link
Copy Markdown
Collaborator

a better suggestion for the message copy

I'd recommend something like

Error: item focused with ".only" is not allowed, either by 'forbidOnly' option in 'playwright.config.[jt]s' or --forbid-only flag: "${title}"

Or you can even make it more specific, see below.

whether there is a way to distinguish whether the project is in TypeScript or JavaScript first.

In the createRootSuite() function you can access config file via testRun.config.config.configFile and check whether --forbid-only was specified via testRun.config.configCLIOverrides.forbidOnly. Note that config file is optional.

This should detect whether it is coming from the CLI or the config file.

Signed-off-by: Tomáš Hübelbauer <tomas@hubelbauer.net>
@TomasHubelbauer

Copy link
Copy Markdown
Contributor Author

@dgozman Is there any way to tell if the project was npm init'd with the language choice of JavaScript or TypeScript? That would help me print the right configuration file extension as a part of the message.

I have not updated the tests yet, will do so once I clone Playwright and figure out how to run the tests locally.

@TomasHubelbauer

Copy link
Copy Markdown
Contributor Author

Something weird is going on with the tests.

I am following CONTRIBUTING.md and it misses a step where I had to do npx playwright install before npm test would run but even after, npm test wants to run 9k tests and I only want to run these tests:

  • tests/playwright-test/reporter.spec.ts should report forbid-only error to reporter
  • tests/playwright-test/runner.spec.ts it should not allow a focused test when forbid-only is used

When I change either of the tests to test.only, it takes no effect, npm test still wants to run 9k tests. I notice the command shown for running specific tests uses playwright test not npm test so I try running that with npx playwright test and get an error in the line of:

Error: Requiring @playwright/test second time

I return to npm test --grep=reporter but still, 9k tests are scheduled to run.

What am I doing wrong?

@dgozman

dgozman commented May 22, 2023

Copy link
Copy Markdown
Collaborator

@dgozman Is there any way to tell if the project was npm init'd with the language choice of JavaScript or TypeScript?

Nope. But you can check configFile as I suggested above, or event print the path to it.

@TomasHubelbauer

Copy link
Copy Markdown
Contributor Author

Sorry, I misunderstood your suggestion at first! Now I get what you mean and how to get the right path.

@dgozman

dgozman commented May 22, 2023

Copy link
Copy Markdown
Collaborator

I am following CONTRIBUTING.md and it misses a step where I had to do npx playwright install before npm test

We should fix this! Send us a PR if you'd like 😄

When I change either of the tests to test.only, it takes no effect, npm test still wants to run 9k tests.

Right, that's test runner tests. You can run them with npm run ttest (note double t). This is probably missing from docs as well.

npm run ttest -- --grep "should report forbid-only error to reporter"

I try running that with npx playwright test

Yeah, that's not going to work. We are using complicated setup to run test runner tests, so npm run ttest is the way to go.

@TomasHubelbauer

TomasHubelbauer commented May 22, 2023

Copy link
Copy Markdown
Contributor Author

Send us a PR if you'd like 😄

I would! Will do.

npm run ttest -- --grep

Perfect, thanks, will also add to the PR!

One last thing: I will also add a note about needing to run npm run build before re-running the tests after making a change.

@TomasHubelbauer

Copy link
Copy Markdown
Contributor Author

Alright, this should be good to go. The tests are passing locally and we even tests the config file existing in one and not existing in the other and the error message reflecting that now. Thanks for engaging on this PR and all the useful tips!

@TomasHubelbauer

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@TomasHubelbauer

Copy link
Copy Markdown
Contributor Author

Need to fix this:

runner.spec.ts:60:5 › it should not allow a focused test when forbid-only is used 
Error: expect(received).toContain(expected) // indexOf
Expected substring: "Error: … the Playwright configuration file: \"tests/focused-test.spec.js i-am-focused\""
Received string:    "Error: … the Playwright configuration file: \"tests\\focused-test.spec.js i-am-focused\"·

I need to use platform-specific path separators to make this pass on Windows. Coming up next.

Comment thread packages/playwright-test/src/runner/loadUtils.ts Outdated
The path separator issue was tanking the tests on GitHub.
…expression

I forgot to assign the POSIX branch expression to `configFilePath`.
I misunderstood the Windows test failure before.
It was the title path failing the test actually not the confi file path. Duh.
Comment thread packages/playwright-test/src/runner/loadUtils.ts Outdated
@TomasHubelbauer

Copy link
Copy Markdown
Contributor Author

I am getting random test failures that seem unrelated and IDK how to fix them 😞

Comment thread packages/playwright-test/src/runner/loadUtils.ts Outdated
Comment thread tests/playwright-test/runner.spec.ts Outdated
We have another test that tests the CLI flag path.
This wasn't there before and Dmitry suggested we adjust the test instead.
Using this we should be able to make them work on both Unix and Windows.
Comment thread tests/playwright-test/runner.spec.ts
@TomasHubelbauer

Copy link
Copy Markdown
Contributor Author

There are again some failing tests on the CI but I do not think they relate to my changes.

@dgozman dgozman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! Looks great, merging in.

@dgozman dgozman merged commit e550df0 into microsoft:main May 25, 2023
@TomasHubelbauer TomasHubelbauer deleted the patch-1 branch May 25, 2023 20:33
@TomasHubelbauer

Copy link
Copy Markdown
Contributor Author

Thank you!!!

@github-actions

Copy link
Copy Markdown
Contributor

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

Successfully merging this pull request may close these issues.

3 participants