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

Update Puppeteer render() to bypass Review app #4345

Merged
merged 8 commits into from
Oct 20, 2023
Merged

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Oct 16, 2023

Part of #4103

Updates our render() test helper from Puppeteer (previously renderAndInitialise()) so it doesn’t send a request to the Review app, but instead runs against local preview of the component.

This is a first step towards restoring tests failing when components throw by having them not run against review app pages (which run initAll(), which logs errors)

By initialising individual components we ensure that future errors cause tests to fail

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 16, 2023 15:19 Inactive
@github-actions
Copy link

github-actions bot commented Oct 16, 2023

📋 Stats

File sizes

File Size
dist/govuk-frontend-4.7.0.min.css 120.66 KiB
dist/govuk-frontend-4.7.0.min.js 51.56 KiB
dist/govuk-frontend-ie8-4.7.0.min.css 81.59 KiB
packages/govuk-frontend/dist/govuk/all.bundle.js 75.58 KiB
packages/govuk-frontend/dist/govuk/all.bundle.mjs 70.95 KiB
packages/govuk-frontend/dist/govuk/all.mjs 3.8 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs 359 B
packages/govuk-frontend/dist/govuk/govuk-frontend.min.css 113.99 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.js 37.06 KiB
packages/govuk-frontend/dist/govuk/i18n.mjs 5.3 KiB

Modules

File Size
all.mjs 67.27 KiB
components/accordion/accordion.mjs 20.15 KiB
components/button/button.mjs 4.16 KiB
components/character-count/character-count.mjs 20.41 KiB
components/checkboxes/checkboxes.mjs 5.3 KiB
components/error-summary/error-summary.mjs 5.46 KiB
components/exit-this-page/exit-this-page.mjs 15.47 KiB
components/header/header.mjs 3.3 KiB
components/notification-banner/notification-banner.mjs 4 KiB
components/radios/radios.mjs 4.3 KiB
components/skip-link/skip-link.mjs 3.29 KiB
components/tabs/tabs.mjs 9.05 KiB

View stats and visualisations on the review app


Action run for 9f3ab07

@colinrotherham colinrotherham force-pushed the render-template branch 2 times, most recently from f34d290 to 11e07aa Compare October 16, 2023 15:49
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 16, 2023 15:51 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 18, 2023 10:49 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 18, 2023 13:11 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 18, 2023 13:42 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 18, 2023 14:52 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 18, 2023 14:57 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 18, 2023 15:12 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 18, 2023 16:01 Inactive
@colinrotherham colinrotherham changed the base branch from render-template to flag-errors October 18, 2023 16:05
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 19, 2023 07:22 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 19, 2023 07:32 Inactive
@colinrotherham colinrotherham force-pushed the flag-errors branch 2 times, most recently from 0ebeb59 to 9187532 Compare October 19, 2023 16:59
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 20, 2023 09:11 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 20, 2023 10:16 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 20, 2023 11:24 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 20, 2023 12:38 Inactive
Base automatically changed from flag-errors to main October 20, 2023 13:14
Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

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

That's a neat step towards adressing #2565 🥳 Overall looks good and I think I followed OK, just want to confirm why a few things are happening. Don't think there'll be any blocker for the answers, but feels useful to have a trace of why things changed in a couple of places 😊

jest-puppeteer.config.js Show resolved Hide resolved
shared/helpers/puppeteer.js Show resolved Hide resolved
shared/helpers/puppeteer.js Show resolved Hide resolved
shared/helpers/puppeteer.js Outdated Show resolved Hide resolved
shared/helpers/puppeteer.js Outdated Show resolved Hide resolved
shared/helpers/puppeteer.js Outdated Show resolved Hide resolved
shared/helpers/puppeteer.js Outdated Show resolved Hide resolved
shared/helpers/puppeteer.js Show resolved Hide resolved
By passing a base to `new URL()` we can switch between the Review app and `file://` URLs
This prevents page and asset requests from hitting the Review app entirely
Since fonts are downloaded asynchronously, we should await the `document.fonts.ready` promise since further network requests may not be available once the page has loads

Similarly, some components are made visible after initialising JavaScript (or new elements created and inserted) so we should wait for additional font downloads to complete there too

E.g. GDS Transport Light may have loaded already, but GDS Transport Bold may be requested on demand as required
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 20, 2023 15:46 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4345 October 20, 2023 15:56 Inactive
Comment on lines +94 to +99
// Mock preview HTTP response
page.once('request', (request) =>
request.respond({
body: renderPreview(componentName, renderOptions),
contentType: 'text/html'
})
Copy link
Member

Choose a reason for hiding this comment

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

Nice one, that makes things tidier for the handler serving the assets 😊

@colinrotherham colinrotherham merged commit 891b112 into main Oct 20, 2023
43 checks passed
@colinrotherham colinrotherham deleted the puppeteer-render branch October 20, 2023 16:11
@colinrotherham colinrotherham linked an issue Oct 23, 2023 that may be closed by this pull request
1 task
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.

Restore ability for tests to fail when component initialisation throws
3 participants