Skip to content

Commit

Permalink
release 2.2.1 [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgruber committed Jun 9, 2017
1 parent 67b3eef commit 9ac7314
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### [2.2.1](https://github.com/adamgruber/mochawesome/releases/tag/2.2.1)
- Separated out before and after hooks
- Bumped mochawesome-report-generator dependency to 2.1.0

### [2.2.0](https://github.com/adamgruber/mochawesome/releases/tag/2.2.0)
- Enable using `addContext` in `beforeEach` and `afterEach` test hooks
- Fix a bug where you could pass an object with empty title string to `addContext`
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mochawesome
Mochawesome is a custom reporter for use with the Javascript testing framework, [mocha][]. It runs on Node.js (>=4) and generates a full fledged HTML/CSS report that helps visualize your test suites.

## :tada: Latest Changes
- Display before and after hooks alongside your tests
- Use `addContext` in `beforeEach` and `afterEach` test hooks
- New [options](#options): `overwrite` and `timestamp`

Expand Down
6 changes: 4 additions & 2 deletions dist/mochawesome.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ function Mochawesome(runner, options) {
var allPasses = [];
var endCalled = false;

// Add a unique identifier to each test
// Add a unique identifier to each test/hook
runner.on('test', function (test) {
return test.uuid = uuid.v4();
});

runner.on('hook', function (hook) {
return hook.uuid = uuid.v4();
});
// Add test to array of all tests
runner.on('test end', function (test) {
return allTests.push(test);
Expand Down
25 changes: 8 additions & 17 deletions dist/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,11 @@ function cleanTest(test) {
isHook: test.type === 'hook'
};

cleaned.skipped = !cleaned.pass && !cleaned.fail && !cleaned.pending;
cleaned.skipped = !cleaned.pass && !cleaned.fail && !cleaned.pending && !cleaned.isHook;

return cleaned;
}

/**
* Filters all failed hooks from suite
* And concatenates them to a single array
*
* @param {Object} suite
*/
function getFailedHooks(suite) {
var failedHooks = [].concat(suite._afterAll, suite._afterEach, suite._beforeAll, suite._beforeEach);
return _.filter(failedHooks, { state: 'failed' });
}

/**
* Mutates the suite object to add properties needed to render
* the template and remove unused properties.
Expand All @@ -183,7 +172,8 @@ function getFailedHooks(suite) {
*/
function cleanSuite(suite, totalTestsRegistered) {
suite.uuid = uuid.v4();
var failedHooks = _.map(getFailedHooks(suite), cleanTest);
var beforeHooks = _.map([].concat(suite._beforeAll, suite._beforeEach), cleanTest);
var afterHooks = _.map([].concat(suite._afterAll, suite._afterEach), cleanTest);
var cleanTests = _.map(suite.tests, cleanTest);
var passingTests = _.filter(cleanTests, { state: 'passed' });
var failingTests = _.filter(cleanTests, { state: 'failed' });
Expand All @@ -197,16 +187,18 @@ function cleanSuite(suite, totalTestsRegistered) {

totalTestsRegistered.total += suite.tests.length;

suite.beforeHooks = beforeHooks;
suite.afterHooks = afterHooks;
suite.tests = cleanTests;
suite.failedHooks = failedHooks;
suite.fullFile = suite.file || '';
suite.file = suite.file ? suite.file.replace(process.cwd(), '') : '';
suite.passes = passingTests;
suite.failures = failingTests;
suite.pending = pendingTests;
suite.skipped = skippedTests;
suite.hasBeforeHooks = suite.beforeHooks.length > 0;
suite.hasAfterHooks = suite.afterHooks.length > 0;
suite.hasTests = suite.tests.length > 0;
suite.hasFailedHooks = suite.failedHooks.length > 0;
suite.hasSuites = suite.suites.length > 0;
suite.totalTests = suite.tests.length;
suite.totalPasses = passingTests.length;
Expand All @@ -220,7 +212,7 @@ function cleanSuite(suite, totalTestsRegistered) {
suite.duration = duration;
suite.rootEmpty = suite.root && suite.totalTests === 0;

removeAllPropsFromObjExcept(suite, ['title', 'fullFile', 'file', 'tests', 'failedHooks', 'suites', 'passes', 'failures', 'pending', 'skipped', 'hasTests', 'hasFailedHooks', 'hasSuites', 'totalTests', 'totalPasses', 'totalFailures', 'totalPending', 'totalSkipped', 'hasPasses', 'hasFailures', 'hasPending', 'hasSkipped', 'root', 'uuid', 'duration', 'rootEmpty', '_timeout']);
removeAllPropsFromObjExcept(suite, ['title', 'fullFile', 'file', 'beforeHooks', 'afterHooks', 'tests', 'suites', 'passes', 'failures', 'pending', 'skipped', 'hasBeforeHooks', 'hasAfterHooks', 'hasTests', 'hasSuites', 'totalTests', 'totalPasses', 'totalFailures', 'totalPending', 'totalSkipped', 'hasPasses', 'hasFailures', 'hasPending', 'hasSkipped', 'root', 'uuid', 'duration', 'rootEmpty', '_timeout']);
}

/**
Expand Down Expand Up @@ -255,6 +247,5 @@ module.exports = {
cleanCode: cleanCode,
cleanTest: cleanTest,
cleanSuite: cleanSuite,
getFailedHooks: getFailedHooks,
traverseSuites: traverseSuites
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mochawesome",
"version": "2.2.0",
"version": "2.2.1",
"description": "A Gorgeous HTML/CSS Reporter for Mocha.js",
"scripts": {
"lint": "eslint src test",
Expand Down Expand Up @@ -56,7 +56,7 @@
"diff": "^3.0.0",
"json-stringify-safe": "^5.0.1",
"lodash": "^4.17.3",
"mochawesome-report-generator": "^2.0.2",
"mochawesome-report-generator": "^2.1.0",
"uuid": "^3.0.1"
},
"peerDependencies": {
Expand Down

0 comments on commit 9ac7314

Please sign in to comment.