Created
June 21, 2021 13:51
-
-
Save xavhan/b623ba2bfc694e70652e4057bf07775b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zx | |
// you need zx installed | |
// run with `zx smoketest.mjs` | |
const BASEURL = 'http://localhost:3000'; | |
const COMMON = [ | |
'header', | |
'footer', | |
] | |
const SMOKE_TEST_PLAN = [ | |
{ | |
page: 'home', | |
path: '/', | |
mandatoryBlocksIds: [ | |
...COMMON, | |
'spotlights-container', | |
'lvp-floor', | |
] | |
}, | |
{ | |
page: 'search results', | |
path: '/search?Ntt=btwin', | |
mandatoryBlocksIds: [ | |
...COMMON, | |
'listing-section', | |
] | |
}, | |
]; | |
const selectors = { | |
nrtid: (id) => `data-nrt="${id}"` | |
} | |
let html; | |
SMOKE_TEST_PLAN.forEach(async ({ page, path, mandatoryBlocksIds }) => { | |
let resp = await fetch(BASEURL + path) | |
if (resp.ok) { | |
html = await resp.text(); | |
} | |
const missings = mandatoryBlocksIds.reduce( | |
(missings, nrtIdentifier) => | |
html.includes(selectors.nrtid(nrtIdentifier)) ? missings : [...missings, nrtIdentifier], | |
[] | |
) | |
if (missings.length === 0) { | |
console.log(`✅ All good, page ${page} is OK`); | |
} else { | |
console.log(`💥 Page ${page} is missing the following blocks: ${missings.join(', ')}`); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment