@@ -4,6 +4,7 @@ import fs from 'fs'
44import http from 'node:http'
55import puppeteer from 'puppeteer-extra'
66import { parseArticle } from '../index.js'
7+ import jpeg from 'jpeg-js'
78
89// Silent socket to suppress parser status logs during tests
910const quietSocket = { emit : ( ) => { } }
@@ -77,6 +78,43 @@ test('parseArticle captures a screenshot when enabled', { timeout: TEST_TIMEOUT
7778 assert . ok ( Buffer . from ( article . screenshot , 'base64' ) . length > 1000 )
7879} )
7980
81+ test ( 'parseArticle screenshot occurs after consent dismissal' , { timeout : TEST_TIMEOUT } , async ( t ) => {
82+ const html = `<!doctype html><html><head><title>Consent</title></head>
83+ <body style="margin:0">
84+ <div id="overlay" style="position:fixed;top:0;left:0;width:100vw;height:100vh;background:red;display:flex;align-items:center;justify-content:center;">
85+ <button id="accept">accept</button>
86+ </div>
87+ <article style="width:100vw;height:100vh;background:green"></article>
88+ <script>document.getElementById('accept').addEventListener('click',()=>document.getElementById('overlay').remove())</script>
89+ </body></html>`
90+ const server = http . createServer ( ( req , res ) => { res . end ( html ) } )
91+ await new Promise ( resolve => server . listen ( 0 , resolve ) )
92+ const { port } = server . address ( )
93+ const url = `http://127.0.0.1:${ port } `
94+ let article
95+ try {
96+ article = await parseArticle ( {
97+ url,
98+ enabled : [ 'screenshot' ] ,
99+ timeoutMs : PARSE_TIMEOUT ,
100+ contentWaitSelectors : [ 'article' ] ,
101+ contentWaitTimeoutMs : 1 ,
102+ skipReadabilityWait : true ,
103+ puppeteer : { launch : { headless : true , args : [ '--no-sandbox' , '--disable-setuid-sandbox' ] } }
104+ } , quietSocket )
105+ } catch ( err ) {
106+ t . skip ( 'puppeteer unavailable: ' + err . message )
107+ server . close ( )
108+ return
109+ }
110+ server . close ( )
111+ const buf = Buffer . from ( article . screenshot , 'base64' )
112+ const { width, height, data } = jpeg . decode ( buf )
113+ const mid = ( ( Math . floor ( height / 2 ) * width ) + Math . floor ( width / 2 ) ) * 4
114+ const r = data [ mid ] , g = data [ mid + 1 ] , b = data [ mid + 2 ]
115+ assert . ok ( g > r && g > b , `expected green to dominate, got r=${ r } g=${ g } b=${ b } ` )
116+ } )
117+
80118test ( 'parseArticle uses rules overrides for title and content' , { timeout : TEST_TIMEOUT } , async ( t ) => {
81119 const longText = 'Incorrect ' . repeat ( 30 )
82120 const html = `<html><head><title>Wrong</title></head><body><article><p>${ longText } </p></article></body></html>`
0 commit comments