import { JSDOM } from 'jsdom'; import { collectAmazonNextReviewPageUrl, isAmazonReviewRatingFilterIgnored, waitForAmazonReviewPageReady, } from '../src/page-worker/web-injectors/amazon-review-page'; const installDom = (html: string, url = 'https://www.amazon.com/product-reviews/B08XM6S6ZL') => { 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 () => { if ( !isAmazonReviewRatingFilterIgnored( [{ rating: '5.0 out of 5 stars' }, { rating: '3.0 out of 5 stars' }], 3, ) ) { throw new Error('Mixed ratings must be detected when Amazon ignores filterByStar'); } if ( isAmazonReviewRatingFilterIgnored( [{ rating: '3.0 out of 5 stars' }, { rating: '3.0 out of 5 stars' }], 3, ) ) { throw new Error('A correctly filtered review page must not be treated as limited'); } const readyDom = installDom('
'); await waitForAmazonReviewPageReady({}); readyDom.window.close(); const paginationDom = installDom( '