1 | 'use strict';
|
2 |
|
3 | const astUtil = require('../util/ast');
|
4 | const { additionalSuiteNames } = require('../util/settings');
|
5 |
|
6 | module.exports = function (context) {
|
7 | const settings = context.settings;
|
8 | const testSuiteStack = [];
|
9 |
|
10 | return {
|
11 | CallExpression(node) {
|
12 | if (astUtil.isDescribe(node, additionalSuiteNames(settings))) {
|
13 | testSuiteStack.push(node);
|
14 | return;
|
15 | }
|
16 |
|
17 | if (!astUtil.isHookIdentifier(node.callee)) {
|
18 | return;
|
19 | }
|
20 |
|
21 | if (testSuiteStack.length === 0) {
|
22 | context.report({
|
23 | node: node.callee,
|
24 | message: `Unexpected use of Mocha \`${ node.callee.name }\` hook outside of a test suite`
|
25 | });
|
26 | }
|
27 | },
|
28 |
|
29 | 'CallExpression:exit'(node) {
|
30 | if (testSuiteStack[testSuiteStack.length - 1] === node) {
|
31 | testSuiteStack.pop();
|
32 | }
|
33 | }
|
34 | };
|
35 | };
|