diff --git a/__tests__/reporters/json.test.ts b/__tests__/reporters/json.test.ts index 4ffb9a5b0..7f29b0f8c 100644 --- a/__tests__/reporters/json.test.ts +++ b/__tests__/reporters/json.test.ts @@ -108,7 +108,6 @@ describe('json reporter', () => { journey: j1, status: 'succeeded', step: step('s1', () => {}), - screenshot: 'dummy', url: 'dummy', start: 0, end: 10, @@ -157,7 +156,6 @@ describe('json reporter', () => { journey: j1, status: 'failed', step: step('s2', () => {}), - screenshot: 'dummy2', url: 'dummy2', start: 11, end: 20, @@ -201,7 +199,6 @@ describe('json reporter', () => { journey: j1, status: 'failed', step: step('s2', () => {}), - screenshot: data, start: 11, end: 20, }); diff --git a/src/core/runner.ts b/src/core/runner.ts index 8c14c4910..477cf6a23 100644 --- a/src/core/runner.ts +++ b/src/core/runner.ts @@ -217,6 +217,11 @@ export default class Runner { const buffer = await driver.page.screenshot({ type: 'png', }); + /** + * Write the screenshot image buffer with additional details (step + * information) which could be extracted at the end of + * each journey without impacting the step timing information + */ const fileName = now().toString() + '.json'; writeFileSync( join(this.screenshotPath, fileName), diff --git a/src/reporters/json.ts b/src/reporters/json.ts index 6444eaf26..0b33d2bdf 100644 --- a/src/reporters/json.ts +++ b/src/reporters/json.ts @@ -23,7 +23,7 @@ * */ -import { readFileSync } from 'fs'; +import { existsSync, readFileSync } from 'fs'; import { join } from 'path'; import sharp from 'sharp'; import { createHash } from 'crypto'; @@ -287,6 +287,12 @@ async function processScreenshot(screenshot: Buffer) { blob: buf.toString('base64'), id: hash, }); + /** + * We dont write the width, height of individual blocks on the + * reference as we use similar sized blocks for each extraction, + * we would need to send the width and height here if we decide to + * go with dynamic block extraction. + */ reference.blocks.push({ hash, top, @@ -298,17 +304,24 @@ async function processScreenshot(screenshot: Buffer) { return { blocks, reference, blob_mime: 'image/webp' }; } +/** + * Get all the screenshots from the cached screenshot location + * at the end of each journey and construct equally sized blocks out + * of the individual screenshot image. + */ async function gatherScreenshots(screenshotsPath: string) { const screenshots: Array = []; - await totalist(screenshotsPath, async (_, absPath) => { - const content = readFileSync(absPath, 'utf8'); - const { step, data } = JSON.parse(content); - const result = await processScreenshot(Buffer.from(data, 'base64')); - screenshots.push({ - step, - ...result, + if (existsSync(CACHE_PATH)) { + await totalist(screenshotsPath, async (_, absPath) => { + const content = readFileSync(absPath, 'utf8'); + const { step, data } = JSON.parse(content); + const result = await processScreenshot(Buffer.from(data, 'base64')); + screenshots.push({ + step, + ...result, + }); }); - }); + } return screenshots; }