Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded for compatibility with Cucumber v8.9.1 + dependencies updated #266

Merged
merged 3 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// most folder contexts extend rules in a language-specific way (e.g. src, lambda) so these are a catch-all for other folders
"root":true,
"extends": [
"./coding-standards/eslint/.eslintrc.json"
]
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
test/report/*.html
test/report/*.json
*.log
.DS_Store
/samples/.DS_Store
templates/.DS_Store
templates/_common/.DS_Store
test/.DS_Store
test/features/.DS_Store
Comment on lines +6 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All those should be on your global git configuration, not in the repository.
It does not make sense to start ignoring leftovers made by each operating system or IDE.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 6.0.0 (Mar-02-2023)
* upgraded to be compatible with cucumber v8.9.1
* upgraded all other dependencies to their latest versions


### 5.1.0 (Dec-15-2019)

* Bootstrap theme filters [#198](https://github.com/gkushang/cucumber-html-reporter/pull/198) by [@srbarrios](https://github.com/srbarrios/)
Expand Down
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

***Generate Cucumber HTML reports with pie charts***

[![Build Status](https://travis-ci.org/gkushang/cucumber-html-reporter.svg?branch=develop)](https://travis-ci.org/gkushang/cucumber-html-reporter) [![npm](https://img.shields.io/npm/v/cucumber-html-reporter.svg)](https://www.npmjs.com/package/cucumber-html-reporter) [![Dependency Status](https://david-dm.org/gkushang/cucumber-html-reporter.svg)](https://david-dm.org/gkushang/cucumber-html-reporter) [![Code Climate](https://codeclimate.com/github/gkushang/cucumber-html-reporter/badges/gpa.svg)](https://codeclimate.com/github/gkushang/cucumber-html-reporter) [![License](https://img.shields.io/npm/l/cucumber-html-reporter.svg)](LICENSE) [![contributors](https://img.shields.io/github/contributors/gkushang/cucumber-html-reporter.svg)](https://github.com/gkushang/cucumber-html-reporter/graphs/contributors)
[![Build Status](https://travis-ci.org/gkushang/cucumber-html-reporter.svg?branch=develop)](https://travis-ci.org/gkushang/cucumber-html-reporter) [![npm](https://img.shields.io/npm/v/cucumber-html-reporter.svg)](https://www.npmjs.com/package/cucumber-html-reporter) [![Code Climate](https://codeclimate.com/github/gkushang/cucumber-html-reporter/badges/gpa.svg)](https://codeclimate.com/github/gkushang/cucumber-html-reporter) [![License](https://img.shields.io/npm/l/cucumber-html-reporter.svg)](LICENSE) [![contributors](https://img.shields.io/github/contributors/gkushang/cucumber-html-reporter.svg)](https://github.com/gkushang/cucumber-html-reporter/graphs/contributors)


> Available HTML themes: `['bootstrap', 'hierarchy', 'foundation', 'simple']`
Expand Down Expand Up @@ -30,7 +30,8 @@ npm install cucumber-html-reporter --save-dev

***Notes:***

* Latest version supports Cucumber 3
* Latest version supports Cucumber 8
* Install `[email protected]` for cucumber version `< Cucumber@8`
* Install `[email protected]` for cucumber version `< Cucumber@3`
* Install `[email protected]` for cucumber version `< Cucumber@2`
* Install `[email protected]` for node version <0.12
Expand All @@ -40,7 +41,7 @@ npm install cucumber-html-reporter --save-dev

Let's get you started:

1. Install the package through npm
1. Install the package through npm or yarn
2. Create an index.js and specify the options. Example of `bootstrap` theme:

```js
Expand Down Expand Up @@ -249,12 +250,15 @@ Pass the _Key-Value_ pair as per your need, as shown in below example,

Capture and Attach screenshots to the Cucumber Scenario and HTML report will render the screenshot image

**for Cucumber V1**
**for Cucumber V8**
```javascript

driver.takeScreenshot().then(function (buffer) {
return scenario.attach(new Buffer(buffer, 'base64'), 'image/png');
};
let world = this;

return driver.takeScreenshot().then((screenShot) => {
// screenShot is a base-64 encoded PNG
world.attach(screenShot, 'image/png');
});

```

Expand All @@ -269,6 +273,15 @@ Capture and Attach screenshots to the Cucumber Scenario and HTML report will ren

```

**for Cucumber V1**
```javascript

driver.takeScreenshot().then(function (buffer) {
return scenario.attach(new Buffer(buffer, 'base64'), 'image/png');
};

```

#### Attach Plain Text to HTML report

Attach plain-texts/data to HTML report to help debug/review the results
Expand Down
51 changes: 51 additions & 0 deletions coding-Standards/eslint/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"root": true,
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaVersion":2017,
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module"
},
"plugins": ["import", "prettier"],
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"rules": {
"prettier/prettier": [
"warn",
{
"singleQuote": true,
"printWidth": 120
}
],
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn",
"linebreak-style": [ "error", "unix" ],
"no-console": [ 0, "error" ],
"indent": [ "error", 2 ],
"semi": [ "error", "always" ],
"quotes":["error", "single"]
},
"globals": {
"noImplicitAny": "readonly",
"noImplicitThis": "readonly",
"strictNullChecks": "readonly",
"strictFunctionTypes": "readonly",
"noEmit": "readonly",
"forceConsistentCasingInFileNames": "readonly"
}
}
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

'use strict';

var reporter = require('./lib/reporter');
const reporter = require('./lib/reporter');

function generateReport(options, callback) {
return reporter.generate(options, callback);
return reporter.generate(options, callback);
}

module.exports = {
generate: generateReport
generate: generateReport,
};
170 changes: 83 additions & 87 deletions lib/hierarchyReporter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

var _ = require('lodash');
var path = require('path');
// const _ = require('lodash');
const path = require('path');

/**
* hierarchyReporter.js
Expand All @@ -11,119 +9,117 @@ var path = require('path');
* but they will be harmlessly ignored by other report types
*/

/**
* Review each feature in the suite, and find the common baseDir that is shared by all of them.
* We will later use this as the basis from which to construct the feature hierarchy--
* the basedir prefix needs to be removed since it is not important.
*/
var getBaseDir = function (suite) {
var baseDir = [];
module.exports = {
/**
* Review each feature in the suite, and find the common baseDir that is shared by all of them.
* We will later use this as the basis from which to construct the feature hierarchy--
* the basedir prefix needs to be removed since it is not important.
*/
getBaseDir: function (suite) {
let baseDir = [];
suite.features.forEach(function (feature) {
var uriParts = feature.uri.split(path.sep);
if (!baseDir.length) {
baseDir = uriParts;
} else {
for (var i = uriParts.length; i > 0; i--) {
if ((baseDir.length > i) && (baseDir[i] !== uriParts[i])) {
baseDir.length = i;
}
}
}
baseDir = feature.uri.split(path.sep);
// let uriParts = feature.uri.split(path.sep);
// if (!baseDir?.length) {
// baseDir = uriParts;
// // console.log('this is the result 1 ===> ', suite);
// } else {
// for (let i = uriParts.length; i > 0; i--) {
// // for (let i = 0, l = uriParts.length; i < l; i++) {
// if ((baseDir.length > i) && (baseDir[i] !== uriParts[i])) {
// baseDir.length = i;
// // console.log('this is the result ===> ', baseDir.length = i)
// }
// }
// }
});
return baseDir.join(path.sep);
};
},

/**
* Given a feature, remove the basedir prefix and the feature name suffix from its URI
* and return the remaining folders (if any) in an array. If the feature is at the top-level,
* it will return []
* For example:
* @param featureUri: '/home/cstrong/myproj/test/features/authentication/login/guestLogin.feature'
* @param baseDir: '/home/cstrong/myproj/test/features'
* @returns [ 'authentication', 'login' ]
*/
var getFeatureHierarchy = function (featureUri, baseDir) {
var noBaseDir = featureUri.slice(baseDir.length + 1);
var noBadChars = noBaseDir.split('=').join('_');
var featureDirs = noBadChars.split(path.sep);
/**
* Given a feature, remove the basedir prefix and the feature name suffix from its URI
* and return the remaining folders (if any) in an array. If the feature is at the top-level,
* it will return []
* For example:
* @param featureUri: '/home/cstrong/myproj/test/features/authentication/login/guestLogin.feature'
* @param baseDir: '/home/cstrong/myproj/test/features'
* @returns [ 'authentication', 'login' ]
*/
getFeatureHierarchy: function (featureUri, baseDir) {
let noBaseDir = featureUri.slice(baseDir.length + 1);
let noBadChars = noBaseDir.split('=').join('_');
let featureDirs = noBadChars.split(path.sep);

// remove the feature name itself
featureDirs.length = featureDirs.length - 1;

return featureDirs;
};
},

/**
* Given the top-level suite and the hierarchy to build, recursively create the hierarchy
* of sub-suites (if needed) and return the lowest level sub-suite.
*
* @param suite
* @param hierarchy e.g. [ 'authentication', 'login' ]
* @returns suite object or null if there is no hierarchy
*/
var findOrCreateSubSuite = function (suite, hierarchy) {

/*
/**
* Given the top-level suite and the hierarchy to build, recursively create the hierarchy
* of sub-suites (if needed) and return the lowest level sub-suite.
*
* @param suite
* @param hierarchy e.g. [ 'authentication', 'login' ]
* @returns suite object or null if there is no hierarchy
*/
findOrCreateSubSuite: function (suite, hierarchy) {
/**
Create a new sub-suite correspond to a folder name. The suite will contain the features that are defined
within that folder, and/or sub-suites corresponding to any sub-folders that themselves may contain features.
A sub-suite has a reference to its parent suite, so that we can easily aggregate statistics of passed and failed
tests up the hierarchy.
*/
function newSubSuite(name, parent) {
return {
name: {
plain: name,
sanitized: name
},
passed: 0,
failed: 0,
ambiguous: 0,
skipped: 0,
parent: parent,
features: [],
suites: []
};
return {
name: {
plain: name,
sanitized: name,
},
passed: 0,
failed: 0,
ambiguous: 0,
skipped: 0,
parent: parent,
features: [],
suites: [],
};
}

if (hierarchy.length < 1) {
return null;
return null;
}
var subSuiteName = hierarchy[0];
let subSuiteName = hierarchy[0];
if (!suite.suites) {
suite.suites = [];
suite.suites = [];
}
var subSuite = suite.suites.find(function (s) {
return s.name.plain === subSuiteName;
let subSuite = suite.suites.find(function (s) {
return s.name.plain === subSuiteName;
});
if (!subSuite) {
subSuite = newSubSuite(subSuiteName, suite);
suite.suites.push(subSuite);
let subSuite = newSubSuite(subSuiteName, suite);
suite.suites.push(subSuite);
}
if (hierarchy.length === 1) {
return subSuite;
return subSuite;
} else {
return findOrCreateSubSuite(subSuite, hierarchy.slice(1));
return this.findOrCreateSubSuite(subSuite, hierarchy.slice(1));
}
};
},

/**
* Increment stat such as failed, ambiguous or passed for the current suite
* and follow the parent attribute (if any) recursively up the tree, incrementing all.
* That way the top level suite accumulates all results from child and grandchild suites
*
* @param subSuite
* @param attrName ('passed', 'failed', 'ambiguous', or 'skipped')
*/
var recursivelyIncrementStat = function (subSuite, attrName) {
/**
* Increment stat such as failed, ambiguous or passed for the current suite
* and follow the parent attribute (if any) recursively up the tree, incrementing all.
* That way the top level suite accumulates all results from child and grandchild suites
*
* @param subSuite
* @param attrName ('passed', 'failed', 'ambiguous', or 'skipped')
*/
recursivelyIncrementStat: function (subSuite, attrName) {
subSuite[attrName] = subSuite[attrName] + 1;
if (subSuite.parent) {
recursivelyIncrementStat(subSuite.parent, attrName);
this.recursivelyIncrementStat(subSuite.parent, attrName);
}
};

module.exports = {
getBaseDir: getBaseDir,
getFeatureHierarchy: getFeatureHierarchy,
findOrCreateSubSuite: findOrCreateSubSuite,
recursivelyIncrementStat: recursivelyIncrementStat
},
};
Loading