diff --git a/examples/specs/404.js b/examples/specs/404.js index 4c795f2..03059c7 100644 --- a/examples/specs/404.js +++ b/examples/specs/404.js @@ -2,4 +2,11 @@ module.exports = { path: 'non-existent-path', + run: async page => { + /** + * page variable is Puppeteer's page object + * https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page + */ + await page.waitForSelector('body'); + }, }; diff --git a/lib/rediff.js b/lib/rediff.js index 3677536..0b1f67d 100644 --- a/lib/rediff.js +++ b/lib/rediff.js @@ -54,6 +54,7 @@ const generateJobQueue = () => { viewport: { width: viewports[viewport].width, height: viewports[viewport].height, + deviceScaleFactor: viewports[viewport].deviceScaleFactor, }, timeout: config.timeout || 5000, url: config.environments[env].baseUrl + spec.path, @@ -61,6 +62,7 @@ const generateJobQueue = () => { css: customCss, run: spec.run, cropArea: spec.cropArea, + fullPage: spec.fullPage, output: outputFile, }); screenshots[env] = outputFile; @@ -167,7 +169,6 @@ const removeFiles = files => { const processJob = (jobs, test, specName) => { const images = envNames.concat(['diff']).map(env => test.screenshots[env]); - const loImages = images.map(image => image.replace(/\.png$/, '.jpg')); const workerPromises = jobs.map(job => worker.addSpec(job, handleError.bind(null, job, 'TestRunner'))); @@ -193,13 +194,13 @@ const run = (cfg, specList) => { envNames = Object.keys(config.environments); queue = generateJobQueue(); - reporter.initialize( - config, - queue.map(item => item.spec) - ); + reporter.initialize(config, queue.map(item => item.spec)); + + console.log(`Starting tests with concurrency ${config.concurrency}`); - Promise.map(queue, processJobSet) - .then(() => console.log('Test completed.')); + Promise.map(queue, processJobSet, { + concurrency: config.concurrency, + }).then(() => console.log('Test completed.')); }; module.exports = run; diff --git a/lib/reporter.js b/lib/reporter.js index 4894b51..df65e81 100644 --- a/lib/reporter.js +++ b/lib/reporter.js @@ -41,9 +41,7 @@ const initialize = (cfg, specsData) => { metadata = { tests: { - count: specs - .map(spec => spec.tests.total) - .reduce(util.sum), + count: specs.map(spec => spec.tests.total).reduce(util.sum), completed: 0, failing: 0, }, diff --git a/lib/worker.js b/lib/worker.js index be5d34b..2c239d0 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -31,12 +31,18 @@ Worker.prototype = { options: { timeout: spec.timeout, 'user-agent': spec.userAgent, + 'inject-css': spec.css, + 'crop-area': spec.cropArea, + fullPage: spec.fullPage, + run: String(spec.run), width: spec.viewport.width, height: spec.viewport.height, + deviceScaleFactor: spec.viewport.deviceScaleFactor, }, }; - console.log(`Generating screenshot of ${spec.url} with options`, body.options); + console.log(`Generating screenshot of ${spec.url} with viewport ${JSON.stringify(spec.viewport)}`); + fetch(`${this.config.nojsSucksBaseUrl}/v1/screenshot`, { method: 'POST', body: JSON.stringify(body), @@ -54,7 +60,7 @@ Worker.prototype = { }) .then(res => res.buffer()) .then(buffer => { - console.log(`Request succeeded, saving to ${spec.output}`); + console.log(`Request to ${spec.url} succeeded, saving to ${spec.output}`); return writeFile(spec.output, buffer); }) diff --git a/package.json b/package.json index f334713..e06fdec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rediff", - "version": "1.0.1", + "version": "1.0.2", "description": "Perceptual difference testing tool based on Pediff", "author": "Lukasz Blacha ", "contributors": [