-
Notifications
You must be signed in to change notification settings - Fork 266
WORLDSERVICE-284 Automated testing to determine the weight of lite pages #12561
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
Merged
emilysaffron
merged 25 commits into
latest
from
SPIKE-WORLDSERVICE-284-automate-litepage-weight-test
Mar 27, 2025
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
bc09440
create lite page size checker script
emilysaffron a1ec735
await results
emilysaffron 0f0a9de
promisify curl
emilysaffron c610451
refactor script
emilysaffron b7c92c3
Merge branch 'latest' into SPIKE-WORLDSERVICE-284-automate-litepage-w…
emilysaffron 7245ac8
Update scripts/litePageSizeValidator/index.js
emilysaffron c5b4aff
Update scripts/litePageSizeValidator/index.js
emilysaffron f75d44b
Update scripts/litePageSizeValidator/index.js
emilysaffron 06c61f6
rename pagetypes
emilysaffron c8431ba
convert to bytes in seperate function
emilysaffron 9adddf3
return full urls in result
emilysaffron e009b97
rename function
emilysaffron 83d3a0a
Update scripts/litePageSizeValidator/index.js
emilysaffron 00087dc
Update scripts/litePageSizeValidator/index.js
emilysaffron 5220531
sort table response
emilysaffron c0a33a1
Update scripts/litePageSizeValidator/index.js
emilysaffron afb3b65
Merge branch 'latest' into SPIKE-WORLDSERVICE-284-automate-litepage-w…
emilysaffron 47f5850
handle non-200 status codes
emilysaffron 7072732
Merge branch 'SPIKE-WORLDSERVICE-284-automate-litepage-weight-test' o…
emilysaffron 25d61a3
Merge branch 'latest' into SPIKE-WORLDSERVICE-284-automate-litepage-w…
emilysaffron a55e14d
fix typo
emilysaffron 5ecd860
Merge branch 'latest' into SPIKE-WORLDSERVICE-284-automate-litepage-w…
emilysaffron 719e329
Merge branch 'latest' into SPIKE-WORLDSERVICE-284-automate-litepage-w…
HarveyPeachey 26f6865
remove 404ing paths
emilysaffron 732d81a
Merge branch 'SPIKE-WORLDSERVICE-284-automate-litepage-weight-test' o…
emilysaffron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /* eslint-disable no-console */ | ||
| const { exec } = require('child_process'); | ||
emilysaffron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const MAX_PAGE_SIZE_KB = 100; | ||
|
|
||
| const litePageSizeValidator = async () => { | ||
| const urlsToCheck = [ | ||
emilysaffron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { path: '/hindi', pageType: 'Home' }, | ||
| { path: '/mundo/articles/cddylv9g8z0o', pageType: 'Optimo Article' }, | ||
| { | ||
| path: '/nepali/bbc_nepali_radio/liveradio', | ||
| pageType: 'Live Radio', | ||
| }, | ||
| { | ||
| path: '/arabic/media-53135426', | ||
| pageType: 'CPS Media Article with Live Stream', | ||
| }, | ||
| { path: '/marathi/popular/read', pageType: 'Most Read' }, | ||
| { | ||
| path: '/gahuza/bbc_gahuza_radio/programmes/p0340x2m', | ||
| pageType: 'On Demand Audio - Brand', | ||
| }, | ||
| { | ||
| path: '/gahuza/bbc_gahuza_radio/w3ct1v5v', | ||
| pageType: 'On Demand Audio - Episode', | ||
| }, | ||
| { | ||
| path: '/gahuza/podcasts/p07yh8hb', | ||
| pageType: 'Podcast - Brand', | ||
| }, | ||
| { | ||
| path: '/gahuza/podcasts/p07yh8hb/p094vs2n', | ||
| pageType: 'Podcast - Episode', | ||
| }, | ||
| { | ||
| path: '/tigrinya/news-51249937', | ||
| pageType: 'CPS Media Article', | ||
| }, | ||
| { | ||
| path: '/hausa/articles/clm3n4pdeymo', | ||
| pageType: 'Optimo Media Article', | ||
| }, | ||
| { path: '/nepali/news-50627370', pageType: 'CPS Photo Gallery (PGL)' }, | ||
| { path: '/arabic/sports-54278377', pageType: 'CPS Story (STY)' }, | ||
| { path: '/korean/topics/cnwng7v0e54t', pageType: 'Topic' }, | ||
| { | ||
| path: '/urdu/live/c04z6x46l0vt', | ||
| pageType: 'Live', | ||
| nextjs: true, | ||
| }, | ||
| ]; | ||
|
|
||
| const getPageSizeInBytes = url => { | ||
| const checkStatus = `curl -s -w "%{http_code}" -o /dev/null ${url}`; | ||
| const getSize = `curl -s ${url} | gzip | wc -c`; | ||
| return new Promise(resolve => { | ||
| exec(checkStatus, (err, stdout) => { | ||
| const statusCode = stdout; | ||
| if (statusCode !== '200') { | ||
| resolve({ statusCode, sizeInBytes: null }); | ||
| } else { | ||
| exec(getSize, (sizeErr, sizeInBytes) => { | ||
| resolve({ statusCode, sizeInBytes }); | ||
| }); | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| const convertToKb = sizeInKb => { | ||
| return parseFloat((sizeInKb.trim() / 1024).toFixed(2)); | ||
| }; | ||
|
|
||
| const testResults = await Promise.all( | ||
| urlsToCheck.map(async ({ path, pageType, nextjs }) => { | ||
| const localUrl = `http://localhost:${nextjs ? 7081 : 7080}${path}.lite?renderer_env=live`; | ||
| const liveUrl = `https://www.bbc.com${path}.lite?renderer_env=live`; | ||
| const [ | ||
| { statusCode: localStatusCode, sizeInBytes: localPageSize }, | ||
| { statusCode: liveStatusCode, sizeInBytes: livePageSize }, | ||
| ] = await Promise.all([ | ||
| getPageSizeInBytes(localUrl), | ||
| getPageSizeInBytes(liveUrl), | ||
| ]); | ||
|
|
||
| const localSizeKb = localPageSize | ||
| ? convertToKb(localPageSize) | ||
| : `⚠️ Page returned ${localStatusCode} status code ⚠️ `; | ||
| const liveSizeKb = livePageSize | ||
| ? convertToKb(livePageSize) | ||
| : `⚠️ Page returned ${liveStatusCode} status code ⚠️ `; | ||
|
|
||
| const result = | ||
| localSizeKb > MAX_PAGE_SIZE_KB || localStatusCode !== '200' | ||
| ? '❌' | ||
| : '✅'; | ||
|
|
||
| console.table({ localUrl, localSizeKb, liveUrl, liveSizeKb }); | ||
|
|
||
| return { | ||
| pageType, | ||
| path, | ||
emilysaffron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| liveSizeKb, | ||
| localSizeKb, | ||
| result, | ||
| }; | ||
| }), | ||
| ); | ||
|
|
||
| console.table(testResults.sort((a, b) => b.localSizeKb - a.localSizeKb)); | ||
|
|
||
| const failures = testResults.filter(({ result }) => result === '❌'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy since this works and it is a developer script. Though I'm not sure I've seen a strict equality check against an emoji before! ===😄 |
||
|
|
||
| if (failures.length > 0) { | ||
| failures.forEach(({ path, localSizeKb }) => { | ||
| const error = | ||
| typeof localSizeKb !== 'number' | ||
| ? `⚠️ Requesting ${path}.litePage returned a non-200 status code` | ||
| : `⚠️ The page size for ${path}.lite is larger than the maximum allowed ${MAX_PAGE_SIZE_KB}`; | ||
| console.error(error); | ||
| }); | ||
| process.exitCode = 1; | ||
| } | ||
| }; | ||
|
|
||
| litePageSizeValidator(); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.