Skip to content

Conversation

evnchn
Copy link
Collaborator

@evnchn evnchn commented Oct 6, 2025

Motivation

As I discovered in #5143, current screen tests let javascript errors slide.

Real motivation: #5146 stale and merge-conflict. I stole the PR desription from there, if it isn't obvious

Implementation

Simple addition to the teardown of screen which checks for javascript errors.

But in line 91 I did {js_errors} instead. Maybe that's why in #5146 we have WAY MORE logs than what we should expect.

Progress

  • I chose a meaningful title that completes the sentence: "If applied, this PR will..."
  • The implementation is complete.
    • We'll see the pipeline.
  • Pytests are not necessary.
  • Documentation is not necessary.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements JavaScript error detection in screen tests to prevent JavaScript errors from silently failing during testing. The main purpose is to ensure that tests fail when JavaScript errors occur, improving test reliability and catching frontend issues early.

Key changes:

  • Added JavaScript error checking in the test teardown process
  • Added an allow_js_errors flag to selectively disable error checking for tests that expect JS errors
  • Updated specific tests to allow JS errors where they are expected (error pages, sanitization tests, etc.)

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
nicegui/testing/screen_plugin.py Added JavaScript error detection logic in test teardown
nicegui/testing/screen.py Added allow_js_errors flag to Screen class
tests/test_storage.py Allowed JS errors for storage test that accesses missing route
tests/test_page.py Allowed JS errors for exception handling and timeout tests
tests/test_html.py Allowed JS errors for HTML sanitization test
tests/test_endpoint_docs.py Added proper page definitions to prevent JS errors
tests/test_element.py Removed emoji from valid tags list
tests/test_chat_message.py Allowed JS errors for chat message test
nicegui/elements/echart/echart.js Fixed potential undefined access with optional chaining

js_errors = [e for e in browser_logs if str(e.get('level', '')).upper() in (
'SEVERE', 'ERROR')]
if js_errors and not screen_.allow_js_errors:
pytest.fail(f'JavaScript console errors:\n{js_errors}', pytrace=False)
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

The error message format {js_errors} will display the raw list representation which is hard to read. Consider formatting the errors more clearly, such as joining individual error messages or extracting relevant fields like message and source.

Suggested change
pytest.fail(f'JavaScript console errors:\n{js_errors}', pytrace=False)
formatted_errors = "\n".join(
f"- {e.get('message', str(e))}" for e in js_errors
)
pytest.fail(f'JavaScript console errors:\n{formatted_errors}', pytrace=False)

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do not do that. Want full context.


screen.open('/')
assert get_openapi_paths() == set()
assert get_openapi_paths() == {'/'}
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

This assertion change from set() to {'/'} suggests the test expectation has changed. However, the test name test_endpoint_documentation_page_only implies it should only document pages, but now it expects the root path to be documented. Verify this is the intended behavior.

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Intended behaviour. Since added @ui.page('/') to all tests, thetest_endpoint_documentation_page_only would have {'/'} in get_openapi_paths()

@falkoschindler falkoschindler added testing Type/scope: Pytests and test fixtures review Status: PR is open and needs review labels Oct 8, 2025
@falkoschindler falkoschindler added this to the 3.1 milestone Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review Status: PR is open and needs review testing Type/scope: Pytests and test fixtures

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants