Skip to content

Commit

Permalink
Merge 46f716d into 1c3a545
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed Feb 18, 2020
2 parents 1c3a545 + 46f716d commit fe10a68
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
16 changes: 13 additions & 3 deletions lib/rules/no-hooks-for-single-case.js
Expand Up @@ -31,7 +31,17 @@ module.exports = {
const options = context.options[0] || {};
const allowedHooks = options.allow || [];
const settings = context.settings;
const layers = [];
let layers = [];

function increaseTestCount() {
layers = layers.map((layer) => {
return {
describeNode: layer.describeNode,
hookNodes: layer.hookNodes,
testCount: layer.testCount + 1
};
});
}

function popLayer(node) {
const layer = layers[layers.length - 1];
Expand Down Expand Up @@ -59,13 +69,13 @@ module.exports = {

CallExpression(node) {
if (astUtil.isDescribe(node, additionalSuiteNames(settings))) {
layers[layers.length - 1].testCount += 1;
increaseTestCount();
layers.push(newDescribeLayer(node));
return;
}

if (astUtil.isTestCase(node)) {
layers[layers.length - 1].testCount += 1;
increaseTestCount();
}

if (astUtil.isHookIdentifier(node.callee)) {
Expand Down
27 changes: 14 additions & 13 deletions test/rules/no-hooks-for-single-case.js
Expand Up @@ -84,6 +84,20 @@ ruleTester.run('no-hooks-for-single-case', rules['no-hooks-for-single-case'], {
' });',
'});'
].join('\n'),
[
'describe(function() {',
' describe(function() {',
' it(function() {});',
' it(function() {});',
' });',
' afterEach(function() {});',
'});'
].join('\n'),
[
'it(function() {});',
'it(function() {});',
'afterEach(function() {});'
].join('\n'),
{
code: [
'describe(function() {',
Expand Down Expand Up @@ -262,19 +276,6 @@ ruleTester.run('no-hooks-for-single-case', rules['no-hooks-for-single-case'], {
].join('\n'),
errors: [ { message: 'Unexpected use of Mocha `before` hook for a single test case', column: 9, line: 5 } ]
},
{
code: [
'describe(function() {',
' before(function() {});',
' describe(function() {',
' before(function() {});',
' it(function() {});',
' it(function() {});',
' });',
'});'
].join('\n'),
errors: [ { message: 'Unexpected use of Mocha `before` hook for a single test case', column: 5, line: 2 } ]
},
{
code: [
'describe(function() {',
Expand Down

0 comments on commit fe10a68

Please sign in to comment.