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

feat: Dedicated --show-warnings command for test runner #35464

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

agg23
Copy link
Contributor

@agg23 agg23 commented Apr 2, 2025

Introduces a dedicated --show-warnings command to the test runner. This concludes the initial pass of #35443 for v1.52.

Every test run only shows a single line with information about warnings:

  6 warnings. Run "npx playwright test --show-warnings" for more information.
Screenshot 2025-04-02 at 12 46 04 PM

There is now a --show-warnings option for playwright test that displays all warnings in the last test run. It stores this information in the same .last-run.json as the suite failures. Warning listings are deduped and codeframes are shown, when available:

Screenshot 2025-04-02 at 12 48 19 PM

@@ -134,4 +140,82 @@ export class Runner {
]);
return { status };
}

async printWarnings(lastRun: LastRunReporter) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not really sure this is the right place for this to live. This is where the other test parsing paths live, so I put it here for now, but I'm open to suggestions on where to move it.

Copy link
Contributor

github-actions bot commented Apr 2, 2025

Test results for "tests 1"

4 failed
❌ [playwright-test] › tests/runner.spec.ts:877:5 › should --show-warnings @macos-latest-node18-1
❌ [playwright-test] › tests/runner.spec.ts:877:5 › should --show-warnings @ubuntu-latest-node18-1
❌ [playwright-test] › tests/runner.spec.ts:877:5 › should --show-warnings @ubuntu-latest-node20-1
❌ [playwright-test] › tests/runner.spec.ts:877:5 › should --show-warnings @windows-latest-node18-1

3 flaky ⚠️ [firefox-page] › tests/page/page-evaluate.spec.ts:424:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-screenshot.spec.ts:345:5 › page screenshot › should work while navigating @webkit-ubuntu-22.04-node18
⚠️ [playwright-test] › tests/ui-mode-test-output.spec.ts:80:5 › should show console messages for test @windows-latest-node18-1

39017 passed, 805 skipped
✔️✔️✔️

Merge workflow run.

@@ -415,6 +425,7 @@ const testOptions: [string, string][] = [
['--reporter <reporter>', `Reporter to use, comma-separated, can be ${builtInReporters.map(name => `"${name}"`).join(', ')} (default: "${defaultReporter}")`],
['--retries <retries>', `Maximum retry count for flaky tests, zero for no retries (default: no retries)`],
['--shard <shard>', `Shard tests and execute only the selected shard, specify in the form "current/all", 1-based, for example "3/5"`],
['--show-warnings', `Show all warning messages collected in the last test run. Does not execute tests.`],
Copy link
Contributor

Choose a reason for hiding this comment

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

  • I wonder whether we want a mode where warnings are printed inline, and also fail the test run, for the strict mode on CI.
  • How many warnings do we get for npm run ctest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not seen any unawaited promise warnings anywhere in our repo. Just reran ctest to verify and no warnings were captured.

const testRun = new TestRun(this._config, reporter);
const status = await runTasks(testRun, [
...createPluginSetupTasks(this._config),
createLoadTask('in-process', { failOnLoadErrors: true, filterOnly: false })
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... If we store warnings in .last-run.json, why do we need to load any tests? I'd think we have all the information needed for the warning in the json, so we can just print it? If so, I'd put all this logic into a separate file warnings.ts and let it manage both the "warnings data in last-run.json" and the terminal output.

That said, I think we should make warnings conveniently available to other reporters. For example, do we want to show warning per test result in the html reporter, or do we want a similar summary? If we want a summary, perhaps generate it and attach? Needs brainstorming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Storing all of the necessary test information is valid, but I didn't want to deviate significantly from the current patterns. If we did store more information than just test ID, would we store code frames? Or would we just store the test name and still fetch the code frame at runtime?


You don't consider the annotation reporter API to be sufficient? A reporter can read all warning annotations onEnd.

const lastRun = new LastRunReporter(config);
const runner = new Runner(config, lastRun);

if (opts.showWarnings) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we go with this approach:

  • handle --show-warnings before UI mode;
  • perhaps do not filter projects, files, etc;
  • throw when --show-warnings is used together with --list, --ui or PWTEST_WATCH.

@@ -41,7 +46,8 @@ export class FloatingPromiseScope {
}
});

this._floatingCalls.add(promise);
const location = filteredLocation(captureRawStack());
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Let's pass the location from outside. I am pretty sure we do already capture location for all the callers.
  • I see that filteredLocation function has sneaked in, unused! Let's remove it!

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.

2 participants