| 44 | } |
| 45 | |
| 46 | export class SSDiff { |
| 47 | url1: any; |
| 48 | url2: any; |
| 49 | pathnames: any; |
| 50 | browser: any; |
| 51 | failInCaseOfDifferentSize: boolean; |
| 52 | debug: boolean; |
| 53 | outputFile: boolean; |
| 54 | browserConfig: BrowserConfig; |
| 55 | screenshotConfig: ScreenshotConfig; |
| 56 | pageConfig: PageConfig; |
| 57 | screenshotsFolder: string; // screenshots folder in the root of the project |
| 58 | todaysScreenshotFolder: string; // screenshots folder for the current date |
| 59 | diffScreenshots: string; // diff screenshots folder for the current date (this still remians, because we might store ss of domains separately) |
| 60 | fileNameDifferenceMap: Map<string, number> = new Map(); // result of the comparison |
| 61 | |
| 62 | constructor(config: SSDiffConfig) { |
| 63 | const defaultScreenshotConfig: ScreenshotConfig = { |
| 64 | type: "png", |
| 65 | }; |
| 66 | const defaultBrowserConfig: BrowserConfig = { |
| 67 | defaultViewport: { |
| 68 | width: 1294, |
| 69 | height: 1280, |
| 70 | }, |
| 71 | }; |
| 72 | const defaultPageConfig: PageConfig = { |
| 73 | waitUntil: "networkidle0", |
| 74 | timeout: 0, |
| 75 | }; |
| 76 | this.url1 = config.url1; |
| 77 | this.url2 = config.url2; |
| 78 | this.pathnames = config.pathnames; |
| 79 | this.failInCaseOfDifferentSize = config.failInCaseOfDifferentSize ?? false; |
| 80 | this.debug = config.debug ?? false; |
| 81 | this.outputFile = config.outputFile ?? false; |
| 82 | this.browserConfig = config.browserConfig ?? defaultBrowserConfig; |
| 83 | this.screenshotConfig = config.screenshotConfig ?? defaultScreenshotConfig; |
| 84 | this.pageConfig = config.pageConfig ?? defaultPageConfig; |
| 85 | this.browser = null; |
| 86 | this.screenshotsFolder = process.cwd() + "/screenshots"; |
| 87 | const todaysDate = new Date().toISOString().split("T")[0]; |
| 88 | this.todaysScreenshotFolder = this.screenshotsFolder + "/" + todaysDate; |
| 89 | this.diffScreenshots = this.todaysScreenshotFolder + "/diff"; |
| 90 | if (!fs.existsSync(this.diffScreenshots)) { |
| 91 | fs.mkdirSync(this.diffScreenshots, { recursive: true }); |
| 92 | this.log("Created diff folder for todays ss"); |
| 93 | } |
| 94 | } |
| 95 | log(text: string) { |
| 96 | if (this.debug) { |
| 97 | debugLogger.debug(text); |
| 98 | } |
| 99 | } |
| 100 | async puppeteer_browser_open() { |
| 101 | try { |
| 102 | if (!this.browser) { |
| 103 | this.browser = await puppeteer.launch(this.browserConfig); |
nothing calls this directly
no outgoing calls
no test coverage detected