Skip to content

Commit

Permalink
Only take “JavaScript disabled” screenshots for components with JS
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Sep 22, 2022
1 parent 290cae0 commit dc34836
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/govuk/components/all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@
const { fetch } = require('undici')
const { WebSocket } = require('ws')

const { allComponents } = require('../../../lib/file-helper')
const { allComponents, getFiles } = require('../../../lib/file-helper')

const configPaths = require('../../../config/paths.js')

const PORT = configPaths.ports.test
const baseUrl = 'http://localhost:' + PORT

describe('Components', () => {
let componentsJavaScript

beforeAll(async () => {
componentsJavaScript = allComponents

// Get file listing per component
.map((component) => [component, getFiles(`${configPaths.components}${component}`)])

// Filter for "JavaScript enabled" via `${component}.mjs`
.filter(([component, entries]) => entries.includes(`${component}.mjs`))

// Component names only
.map(([component]) => component)
})

describe('Generate screenshots for Percy visual regression', () => {
let percySnapshot

Expand All @@ -26,8 +41,8 @@ describe('Components', () => {
it('with JavaScript disabled', async () => {
await page.setJavaScriptEnabled(false)

// Screenshot each component
for (const component of allComponents) {
// Screenshot only components with JavaScript support
for (const component of componentsJavaScript) {
await page.goto(baseUrl + '/components/' + component + '/preview', { waitUntil: 'load' })
await percySnapshot(page, 'no-js: ' + component)
}
Expand Down

0 comments on commit dc34836

Please sign in to comment.