import { JSDOM } from 'jsdom'; import { waitForAmazonDetailPageReady } from '../src/page-worker/web-injectors/amazon-detail-page-ready'; const installDom = (html: string, url = 'https://www.amazon.com/dp/B0DMNDL5NH') => { const dom = new JSDOM(html, { url }); Object.defineProperty(dom.window.document, 'readyState', { configurable: true, value: 'complete', }); Object.assign(globalThis, { document: dom.window.document, window: dom.window }); Object.assign(dom.window.HTMLElement.prototype, { scrollIntoView: () => undefined }); return dom; }; const main = async () => { const modernDetail = installDom('Ready product'); await waitForAmazonDetailPageReady(); modernDetail.window.close(); const legacyDetail = installDom('Legacy product'); await waitForAmazonDetailPageReady(); legacyDetail.window.close(); const signIn = installDom('
Sign in
', 'https://www.amazon.com/ap/signin'); await waitForAmazonDetailPageReady().then( () => { throw new Error('Sign-in page should fail immediately'); }, (error) => { if (!String(error).includes('需要重新登录')) throw error; }, ); signIn.window.close(); const captcha = installDom(''); await waitForAmazonDetailPageReady().then( () => { throw new Error('Captcha page should fail immediately'); }, (error) => { if (!String(error).includes('验证码')) throw error; }, ); captcha.window.close(); console.log('Amazon detail page readiness tests passed.'); }; void main();