UNPKG

772 BJavaScriptView Raw
1'use strict';
2
3const {visitIf} = require('enhance-visitors');
4const createAvaRule = require('../create-ava-rule');
5const util = require('../util');
6
7const create = context => {
8 const ava = createAvaRule();
9 let nestedCount = 0;
10
11 return ava.merge({
12 CallExpression: visitIf([
13 ava.isInTestFile,
14 ava.isTestNode,
15 ])(node => {
16 nestedCount++;
17 if (nestedCount >= 2) {
18 context.report({
19 node,
20 message: 'Tests should not be nested.',
21 });
22 }
23 }),
24
25 'CallExpression:exit': visitIf([
26 ava.isInTestFile,
27 ava.isTestNode,
28 ])(() => {
29 nestedCount--;
30 }),
31 });
32};
33
34module.exports = {
35 create,
36 meta: {
37 type: 'problem',
38 docs: {
39 description: 'Ensure no tests are nested.',
40 url: util.getDocsUrl(__filename),
41 },
42 schema: [],
43 },
44};