Skip to content

Commit

Permalink
test: Local generate report (#43)
Browse files Browse the repository at this point in the history
* fix: removing uneeded config from  existing tests

* test: generate report local

* feat: exit code 1 if fs fails
  • Loading branch information
L0wry authored and shendriksen committed Jun 25, 2018
1 parent 8c251bc commit 35a4893
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
File renamed without changes.
13 changes: 13 additions & 0 deletions e2eTests/generateHtmlReport/generateReportConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"gridUrl": "http://selenium.com:4444/wd/hub",
"baseline": "./e2eTests/generateHtmlReport/baseline",
"latest": "./e2eTests/generateHtmlReport/mockImages",
"generatedDiffs": "./e2eTests/generateHtmlReport/generatedDiffs",
"report": "./e2eTests/generateHtmlReport/reports",
"scenarios": [
{
"url": "http:/google.com/",
"label": "homepage"
}]
}

37 changes: 37 additions & 0 deletions e2eTests/generateHtmlReport/generateReportLocal.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* globals expect */

import path from 'path';
import fs from 'fs';
import { execSync } from 'child_process';
import config from './generateReportConfig';

describe('e2e Tests for generating html report locally', () => {
let dirPath;

beforeEach(() => {
dirPath = path.resolve(config.report);

if (fs.existsSync(dirPath)) {
const files = fs.readdirSync(dirPath);
files.forEach(file => fs.unlinkSync(`${dirPath}/${file}`));
fs.rmdirSync(dirPath);
}
});
it('generates the report', () => {
let exitCode = 0;

try {
const stdout = execSync(
'node ./lib/bin/run.js generate-report --browser chrome --config e2eTests/generateHtmlReport/generateReportConfig.json'
).toString();
//pipe stdout to Jest console
console.log(stdout);
} catch (error) {
exitCode = error.status;
}

expect(exitCode).toEqual(0);
const latestDirFiles = fs.readdirSync(dirPath);
expect(latestDirFiles).toEqual(['index.html']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from 'fs';
import { execSync } from 'child_process';
import config from './snapConfig';

describe('e2e Tests taking snaps', () => {
describe('e2e Tests taking snaps locally', () => {
let dirPath;

beforeEach(() => {
Expand Down
2 changes: 0 additions & 2 deletions e2eTests/updateBaseline/updateBaselineConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
{
"url": "http://cps-render-ci.elb.tnl-dev.ntch.co.uk/",
"label": "homepage",
"height": 2400,
"width": 1024,
"removeSelectors": ["#ad-header", ".AD"],
"cookies": [
{
Expand Down
13 changes: 9 additions & 4 deletions src/generateReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ const writeReport = (config, reportsData) => {
const reportPresentation = compileTemplate({ reportsData });
const reportDir = path.resolve(config.report);

if (!fs.existsSync(reportDir)) fs.mkdirSync(reportDir);
fs.writeFileSync(`${reportDir}/index.html`, reportPresentation);
logger.info('generate-report', 'successfully created report!');
return `${reportDir}/index.html`;
try {
if (!fs.existsSync(reportDir)) fs.mkdirSync(reportDir);
fs.writeFileSync(`${reportDir}/index.html`, reportPresentation);
logger.info('generate-report', 'successfully created report!');
return `${reportDir}/index.html`;
} catch (err) {
logger.error(err);
process.exitCode = 1;
}
};

const generateRemoteReport = async config => {
Expand Down

0 comments on commit 35a4893

Please sign in to comment.