Skip to content

Commit

Permalink
feat(failed-scenarios): Add --fail parameter to generateReport command
Browse files Browse the repository at this point in the history
  • Loading branch information
flegall committed Aug 10, 2017
1 parent 5be5756 commit 82b781a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
3 changes: 2 additions & 1 deletion js-given/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"installJGivenReport": "node tools/installJGivenReport.js",
"postinstall": "yarn installProtractor && yarn installJGivenReport",
"pretest": "node src/cli.es5.js clean",
"test": "yarn allTests || yarn generateReport",
"test": "yarn allTests || yarn generateReportFail",
"posttest": "yarn generateReport && yarn build",
"allTests": "yarn test_jest && yarn test_mocha && yarn test_jasmine && yarn test_ava && yarn test_protractor && yarn test_type_definitions",
"test_mocha": "mocha --opts spec/support/mocha-default.opts spec",
Expand All @@ -20,6 +20,7 @@
"test_type_definitions": "(cd type-definitions/tests && ../../../node_modules/.bin/flow)",
"testWatch": "yarn test_jest -- --watch",
"generateReport": "node src/cli.es5.js report",
"generateReportFail": "node src/cli.es5.js report --fail",
"coverage": "yarn test_jest -- --coverage",
"__doBuild": "rm -vfr dist && yarn buildLib && yarn buildCli && cp type-definitions/*.js.flow type-definitions/*.d.ts dist",
"build": "check-node-version -q --node '< 6.0' || (yarn __doBuild && yarn __doPreparePublish -- alpha)",
Expand Down
15 changes: 11 additions & 4 deletions js-given/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ import yargs from 'yargs';

import { generateJGivenReport, cleanReports } from './generateJGivenReport';

const [command] = yargs
const { argv } = yargs
.usage('Usage: $0 <command>')
.command('report', 'Generate the reports')
.command('report', 'Generate the reports', yars => {
return yargs.option('fail', {
describe: 'Generates the reports but return -1',
});
})
.command('clean', 'Remove the reports and intermediary files')
.demandCommand(1).argv._;
.demandCommand(1);

const [command] = argv._;

if (command === 'report') {
generateJGivenReport();
const fail: boolean = !!argv.fail;
generateJGivenReport(fail);
}

if (command === 'clean') {
Expand Down
22 changes: 7 additions & 15 deletions js-given/src/generateJGivenReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { ReportModel } from './jgivenReport/ReportModel';
import type { ScenarioModel } from './jgivenReport/ScenarioModel';
import type { StepModel } from './jgivenReport/StepModel';

export async function generateJGivenReport(): Promise<void> {
export async function generateJGivenReport(fail: boolean): Promise<void> {
try {
if (!directoryExists(`./${REPORTS_DESTINATION}`)) {
console.log(
Expand All @@ -22,17 +22,17 @@ export async function generateJGivenReport(): Promise<void> {
}

await installJGivenReportApp();
const someScenariosHaveFailed = generateJGivenReportDataFiles();
generateJGivenReportDataFiles();

console.log(`jsGiven report available in ./jGiven-report`);

if (someScenariosHaveFailed) {
process.exit(1);
}
} catch (error) {
console.log(error);
process.exit(-1);
}

if (fail) {
process.exit(1);
}
}

export async function cleanReports(): Promise<void> {
Expand Down Expand Up @@ -93,7 +93,7 @@ export function generateJGivenReportDataFiles(
filter?: (fileName: string) => boolean = () => true,
reportPrefix: string = '.',
jsGivenReportsDir: string = REPORTS_DESTINATION
): boolean {
) {
const files = fs.readdirSync(`${jsGivenReportsDir}`).filter(filter);
const scenarioReports: ScenarioReport[] = files.map(file =>
JSON.parse(fs.readFileSync(`${jsGivenReportsDir}/${file}`, 'utf-8'))
Expand Down Expand Up @@ -129,14 +129,6 @@ export function generateJGivenReportDataFiles(
`jgivenReport.addZippedScenarios('${base64}');\n`,
'utf-8'
);

const someScenariosHaveFailed = scenarioModels.some(scenarioModel =>
scenarioModel.scenarios.some(
scenario => scenario.executionStatus === 'FAILED'
)
);

return someScenariosHaveFailed;
}

function removeDir(dir: string): Promise<void> {
Expand Down

0 comments on commit 82b781a

Please sign in to comment.