@wdio/image-comparison-core
Version:
Image comparison core module for @wdio/visual-service - WebdriverIO visual testing framework
21 lines (20 loc) • 692 B
JavaScript
/**
* Wait for the fonts to be loaded, do this for a max of 11 seconds
*
* NOTE: writing this with promises instead of async/await because it fails with
* `javascript error: __awaiter is not defined` when running in the browser
*/
export default function waitForFonts() {
return new Promise((resolve, reject) => {
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => {
reject(new Error('Font loading timed out'));
}, 11000);
});
Promise.race([document.fonts.ready, timeoutPromise])
.then(() => {
resolve('All fonts have loaded');
})
.catch(reject);
});
}