Last active
May 27, 2022 14:15
-
-
Save russHyde/2bf7b80481de9866aee023531a2c298b to your computer and use it in GitHub Desktop.
Notes on puppeteer / jest tests
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
# Run the test file multiple times, break when it fails to pass | |
TEST_PATTERN="xxx" | |
for i in {1..10}; do | |
npx jest ${TEST_PATTERN} --silent --runInBand; | |
if [[ "$?" != 0 ]]; then echo "Failed after $i attempts" && break; fi; | |
done |
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
/** | |
* Wait for an event to be signalled to the browser by the (shiny) app | |
* | |
* Useful events: | |
* - "shiny:idle" - indicates that the server is idle | |
* - "shiny:visualchange" - indicates that an output is resized / hidden / shown | |
* | |
* Source: https://github.com/puppeteer/puppeteer/issues/2455 | |
* | |
* @param {Page} page | |
* @param {string} event | |
* @param {number} timeout | |
*/ | |
async function waitForEvent(page, event, timeout = 5000) { | |
return Promise.race([ | |
page.evaluate( | |
(event) => | |
new Promise((resolve) => | |
document.addEventListener(event, resolve, { once: true }) | |
), | |
event | |
), | |
page.waitForTimeout(timeout), | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FIrst block from https://stackoverflow.com/a/55937841/1845650
Unfortunately the implementation from that SO post fails: