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

Figure out how to test for errors and warnings in the browser console and build test(s) #74

Closed
jschuurk-kr opened this issue Jun 18, 2024 · 6 comments · Fixed by #89
Closed
Assignees

Comments

@jschuurk-kr
Copy link
Contributor

jschuurk-kr commented Jun 18, 2024

Example currently in application: "Warning: Encountered two children with the same key, proxyCertificates. "

branch to explore solutions: 74-test-for-console-errors-and-warnings

Conclusion as implemented in linked PR: use vitest-fail-on-console.

No need to implement any tests. All vitest tests will now fail when there are console errors or warnings. Pasting non-numbers twice in the Voters and Voters page does result in an error, but improving that functionality and its tests are for issue #73.

@jschuurk-kr jschuurk-kr self-assigned this Jun 18, 2024
@jschuurk-kr jschuurk-kr converted this from a draft issue Jun 18, 2024
@praseodym
Copy link
Contributor

We could consider doing this in Playwright (e.g. microsoft/playwright#27277) or with Vitest (e.g. onConsoleLog).

@lkleuver
Copy link
Contributor

I think this is the tooltip code that will change short term.

@jschuurk-kr
Copy link
Contributor Author

jschuurk-kr commented Jun 19, 2024

Options with vitest:

  1. onConsoleLog. Throwing an error in vite.config.ts does not fail the test, but stops the tests with an unhandled rejection. Vitest does not seem to allow importing expect into its config file.
  2. A spy on console.error() and console.warn().
  3. vitest-fail-on-console. It's not a lot of code and has a single dependency we already have, i.e. chalk.

@jschuurk-kr
Copy link
Contributor Author

jschuurk-kr commented Jun 19, 2024

Option with Playwright is to define a throwOnConsole() function and call it at the start of every test. Haven't tried yet to run it in a beforeEach or to add to an override of page.

Two challenges with testing copy/paste with Playwright (because it's a good way to trigger a console error through the tooltip):

  • Haven't gotten copy/paste to work on Safari. Seems not supported and only doable through a workaround.
  • Running all the tests results in "Error: write EPIPE" messages.

@jschuurk-kr
Copy link
Contributor Author

So far I'm preferring the vitest option over the Playwright one:

  • easier to enable for all tests thanks to vitest-fail-on-console
  • output of failing test is more readable
  • higher coverage: I expect us to cover significantly more functionality with Vitest/(React)TestingLibrary than with Playwright.

@jschuurk-kr jschuurk-kr moved this from Current to In Progress in Abacus Development Jun 20, 2024
@jschuurk-kr
Copy link
Contributor Author

jschuurk-kr commented Jun 20, 2024

Playwright output - calling throwOnConsole() at the start of the test

Error: Warning: Encountered two children with the same key, %s. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.%s pollCards

followed by 34 lines of stacktrace.

Using the solution in the Playwright issue comment, where you override the test fixture, you get even more output. Or if you change expect(messages).toEqual([]); to expect(messages.length).toBe(0);, it doesn't tell you what the error was.

Vitest output - using vitest-fail-on-console:

Warning: Encountered two children with the same key, pollCards. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

followed by 18 lines of stacktrace.

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

Successfully merging a pull request may close this issue.

3 participants