@@ -2,16 +2,7 @@ import type { Finding } from './types.d.js';
22import AxeBuilder from '@axe-core/playwright'
33import playwright from 'playwright' ;
44import { AuthContext } from './AuthContext.js' ;
5- import fs from "node:fs" ;
6- import path from "node:path" ;
7- import crypto from "node:crypto" ;
8-
9- // Use GITHUB_WORKSPACE to ensure screenshots are saved in the workflow workspace root
10- // where the artifact upload step can find them
11- const SCREENSHOT_DIR = path . join (
12- process . env . GITHUB_WORKSPACE || process . cwd ( ) ,
13- ".screenshots" ,
14- ) ;
5+ import { generateScreenshots } from "./generateScreenshots.js" ;
156
167export async function findForUrl (
178 url : string ,
@@ -31,33 +22,10 @@ export async function findForUrl(
3122 let findings : Finding [ ] = [ ] ;
3223 try {
3324 const rawFindings = await new AxeBuilder ( { page } ) . analyze ( ) ;
34- let screenshotId : string | undefined ;
3525
26+ let screenshotId : string | undefined ;
3627 if ( includeScreenshots ) {
37- // Ensure screenshot directory exists
38- if ( ! fs . existsSync ( SCREENSHOT_DIR ) ) {
39- fs . mkdirSync ( SCREENSHOT_DIR , { recursive : true } ) ;
40- console . log ( `Created screenshot directory: ${ SCREENSHOT_DIR } ` ) ;
41- } else {
42- console . log ( `Using existing screenshot directory ${ SCREENSHOT_DIR } ` ) ;
43- }
44-
45- try {
46- const screenshotBuffer = await page . screenshot ( {
47- fullPage : true ,
48- type : "png" ,
49- } ) ;
50-
51- screenshotId = crypto . randomUUID ( ) ;
52- const filename = `${ screenshotId } .png` ;
53- const filepath = path . join ( SCREENSHOT_DIR , filename ) ;
54-
55- fs . writeFileSync ( filepath , screenshotBuffer ) ;
56- console . log ( `Screenshot saved: ${ filename } ` ) ;
57- } catch ( error ) {
58- console . error ( "Failed to capture/save screenshot:" , error ) ;
59- screenshotId = undefined ;
60- }
28+ screenshotId = await generateScreenshots ( page ) ;
6129 }
6230
6331 findings = rawFindings . violations . map ( ( violation ) => ( {
0 commit comments