Skip to content

Commit

Permalink
Merge pull request #7 from Schibsted-Tech-Polska/interactive-tests
Browse files Browse the repository at this point in the history
Interactive tests
  • Loading branch information
domeq authored Oct 24, 2017
2 parents d03ce29 + 97f5d13 commit e891d4f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
7 changes: 7 additions & 0 deletions examples/specs/404.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
},
};
15 changes: 8 additions & 7 deletions lib/rediff.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ 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,
userAgent: viewports[viewport].userAgent,
css: customCss,
run: spec.run,
cropArea: spec.cropArea,
fullPage: spec.fullPage,
output: outputFile,
});
screenshots[env] = outputFile;
Expand Down Expand Up @@ -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')));
Expand All @@ -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;
4 changes: 1 addition & 3 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
10 changes: 8 additions & 2 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"contributors": [
Expand Down

0 comments on commit e891d4f

Please sign in to comment.