Draft: Fail feature specs on unexpected browser console errors
What does this MR do and why?
Fails feature specs on unexpected browser console errors, with a baseline of the errors that specs log today.
Before, the config.after(:example, :js) hook in spec/support/capybara.rb called raise_if_unexpected_browser_console_output only when the example had already failed. A passing feature spec never checked the browser console. Vue 2 catches a component render error, logs it with console.error, and renders the component blank. The page still works, the spec passes, and the error is discarded. Vue 3 in the development build did not tolerate the same error and broke the page. So the Rapid Diffs reply placeholder crash (#628791 (closed)) surfaced only after the Vue 3 migration of the page merged, and the migration was reverted.
Changes:
spec/support/capybara.rb: the console check runs for every:jsexample, except when the exception isRSpec::Core::Pending::PendingExampleFixedError. The hook passes the example so the check knows the spec file path.spec/support/helpers/browser_console_helpers.rb,BROWSER_CONSOLE_ERROR_FILTER: ignores messages that come from the test environment, not from the application:Failed to load resource(Chrome logs every 4xx/5xx response as SEVERE; many specs assert on them)- Content Security Policy violations and refused connections (no network in CI: Snowplow, Zuora, OneTrust, Sentry envelope, media)
ArkoseLabs initialization error,googletagmanager.com[Sentry stub](the stub forwardscaptureExceptiontoconsole.error)/-/manifest.jsonsyntax error, GraphQL explorer embedded fontsuser_counts401 after the session endsDOMException: Transition was skipped, blockedbeforeunloadpanel- ActionCable WebSocket handshake failure
- New
spec/support/browser_console_allowlist.yml: known application errors that specs may still log. Keys per entry:pattern: regexp matched against the console message (required)specs: spec file paths or globs the entry applies to (required, so an entry never hides the error on other pages)vue: 2 or 3, to scope the entry to one Vue major version (optional)issue: full URL of the issue that tracks the fix (optional)
raise_if_unexpected_browser_console_outputallows a SEVERE message only when an entry's pattern matches, the current spec file matches one of the entry'sspecs, and thevueversion matches when set. The spec file comes frommetadata[:rerun_file_path], so examples from shared example groups are scoped to the spec file that includes them, not to the shared examples file.- New validator
spec/support_specs/browser_console_allowlist_spec.rb: only allowed keys, patterns compile,issueis a full gitlab.com URL when set,vueis 2 or 3 when set,specsis present and every glob matches at least one existing file (entries die with the specs they reference), no duplicate patterns.
Under Vue 2, [Vue warn] messages use console.error and are SEVERE. Under Vue 3 they use console.warn and are not. So prop-validation warnings fail only the Vue 2 jobs.
Related: !255205 (merged) installs a non-production Vue 3 errorHandler, so Vue 3 recovers from component errors like production and Vue 2 do. With it, Vue 3 errors also become console lines that this check catches.
The baseline
50 entries covering 199 spec files, generated from the traces of the reveal pipelines https://gitlab.com/gitlab-org/gitlab/-/pipelines/2843011566 and https://gitlab.com/gitlab-org/gitlab/-/pipelines/2843079787, and from this MR's first two pipelines https://gitlab.com/gitlab-org/gitlab/-/pipelines/2843143467 and https://gitlab.com/gitlab-org/gitlab/-/pipelines/2843157294. No entry has an issue yet. Each entry is an error to fix right away or to track in an issue; that decision is made per entry. #628901 catalogues every entry with job links, spec files, a likely cause and a suggested fix, and tells the history of how the list came to be.
Largest groups:
- Apollo
Missing field 'humanTimeEstimate' while writing result: boards sidebar, 8 spec files Uncaught ReferenceError: _this12 is not defined: analytics and compliance dashboards, 9 spec filesUncaught Error: No match for(vue: 3): merge request list filtering and sorting, 15 spec files, #628844 (closed)Uncaught ParametersMissing: Route missing required keys: id: Pages settingsUncaught RangeError: Invalid time value: branches pages- About 12
[Vue warn]: Invalid propvariants - The Rapid Diffs
__vnode(vue: 3) andreading 'id'crash, #628791 (closed)
Expected pipeline result: green when the baseline is complete. A red rspec system job means a console error that is not in the baseline: add an entry or fix the error.
References
- Catalogue of every baseline entry, with job links and suggested fixes: #628901
- Reveal MR whose pipelines produced the baseline: !255199
- Baseline pipeline: https://gitlab.com/gitlab-org/gitlab/-/pipelines/2843079787
- Rapid Diffs placeholder crash: #628791 (closed)
- Merge request list router error under Vue 3: #628844 (closed)
- Non-production Vue 3 errorHandler: !255205 (merged)
- Full-mount Jest spec for the Rapid Diffs bug class: !255198 (closed)
- Vue 3 migration (Code Review) epic: gitlab-org#23167
- Follow-up issues filed from baseline entries:
@gitlab/at.jsbump oncerenderViewtolerates a cleared query (thereading 'text'entry): #628981- GitLab UI,
GlBreadcrumbitems watcher after unmount (thereading 'clientWidth'entry): gitlab-org/gitlab-services/design.gitlab.com#3650 - GitLab UI,
GlDisclosureDropdownclick handler after unmount (part of thereading 'containsElement'entry): gitlab-org/gitlab-services/design.gitlab.com#3649 (closed) - GitLab UI, guard three async callbacks after unmount: gitlab-org/gitlab-services/design.gitlab.com#3651
Screenshots or screen recordings
No UI change.
How to set up and validate locally
- Run the validator:
bin/rspec spec/support_specs/browser_console_allowlist_spec.rb. - Run a feature spec that has a known console error and an allowlist entry, for example
bin/rspec spec/features/projects/branches_spec.rb. It passes. - Remove the
Invalid time valueentry fromspec/support/browser_console_allowlist.yml. Run the spec again. It fails withBrowserConsoleErrorand printsUncaught RangeError: Invalid time value.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.