1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const isNil = require('ramda/src/isNil');
|
9 | const astUtil = require('../util/ast');
|
10 | const { additionalSuiteNames } = require('../util/settings');
|
11 |
|
12 | const defaultSuiteLimit = 1;
|
13 |
|
14 | module.exports = function (context) {
|
15 | const stack = [];
|
16 | const topLevelDescribes = [];
|
17 | const options = context.options[0] || {};
|
18 | const settings = context.settings;
|
19 | let suiteLimit;
|
20 |
|
21 | if (isNil(options.limit)) {
|
22 | suiteLimit = defaultSuiteLimit;
|
23 | } else {
|
24 | suiteLimit = options.limit;
|
25 | }
|
26 |
|
27 | return {
|
28 | CallExpression(node) {
|
29 | if (astUtil.isDescribe(node, additionalSuiteNames(settings))) {
|
30 | stack.push(node);
|
31 | }
|
32 | },
|
33 |
|
34 | 'CallExpression:exit'(node) {
|
35 | if (astUtil.isDescribe(node, additionalSuiteNames(settings))) {
|
36 | if (stack.length === 1) {
|
37 | topLevelDescribes.push(node);
|
38 | }
|
39 |
|
40 | stack.pop(node);
|
41 | }
|
42 | },
|
43 |
|
44 | 'Program:exit'() {
|
45 | if (topLevelDescribes.length > suiteLimit) {
|
46 | context.report({
|
47 | node: topLevelDescribes[suiteLimit],
|
48 | message: `The number of top-level suites is more than ${ suiteLimit }.`
|
49 | });
|
50 | }
|
51 | }
|
52 | };
|
53 | };
|