no-disabled-tests.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _utils = require("./utils");
  7. var _default = (0, _utils.createRule)({
  8. name: __filename,
  9. meta: {
  10. docs: {
  11. category: 'Best Practices',
  12. description: 'Disallow disabled tests',
  13. recommended: 'warn'
  14. },
  15. messages: {
  16. missingFunction: 'Test is missing function argument',
  17. skippedTestSuite: 'Skipped test suite',
  18. skippedTest: 'Skipped test',
  19. pending: 'Call to pending()',
  20. pendingSuite: 'Call to pending() within test suite',
  21. pendingTest: 'Call to pending() within test',
  22. disabledSuite: 'Disabled test suite',
  23. disabledTest: 'Disabled test'
  24. },
  25. schema: [],
  26. type: 'suggestion'
  27. },
  28. defaultOptions: [],
  29. create(context) {
  30. let suiteDepth = 0;
  31. let testDepth = 0;
  32. return {
  33. 'CallExpression[callee.name="describe"]'() {
  34. suiteDepth++;
  35. },
  36. 'CallExpression[callee.name=/^(it|test)$/]'() {
  37. testDepth++;
  38. },
  39. 'CallExpression[callee.name=/^(it|test)$/][arguments.length<2]'(node) {
  40. context.report({
  41. messageId: 'missingFunction',
  42. node
  43. });
  44. },
  45. CallExpression(node) {
  46. const functionName = (0, _utils.getNodeName)(node.callee); // prevent duplicate warnings for it.each()()
  47. if (node.callee.type === 'CallExpression') {
  48. return;
  49. }
  50. switch (functionName) {
  51. case 'describe.skip.each':
  52. case 'xdescribe.each':
  53. case 'describe.skip':
  54. context.report({
  55. messageId: 'skippedTestSuite',
  56. node
  57. });
  58. break;
  59. case 'it.skip':
  60. case 'it.concurrent.skip':
  61. case 'test.skip':
  62. case 'test.concurrent.skip':
  63. case 'it.skip.each':
  64. case 'test.skip.each':
  65. case 'xit.each':
  66. case 'xtest.each':
  67. context.report({
  68. messageId: 'skippedTest',
  69. node
  70. });
  71. break;
  72. }
  73. },
  74. 'CallExpression[callee.name="pending"]'(node) {
  75. if ((0, _utils.scopeHasLocalReference)(context.getScope(), 'pending')) {
  76. return;
  77. }
  78. if (testDepth > 0) {
  79. context.report({
  80. messageId: 'pendingTest',
  81. node
  82. });
  83. } else if (suiteDepth > 0) {
  84. context.report({
  85. messageId: 'pendingSuite',
  86. node
  87. });
  88. } else {
  89. context.report({
  90. messageId: 'pending',
  91. node
  92. });
  93. }
  94. },
  95. 'CallExpression[callee.name="xdescribe"]'(node) {
  96. context.report({
  97. messageId: 'disabledSuite',
  98. node
  99. });
  100. },
  101. 'CallExpression[callee.name=/^(xit|xtest)$/]'(node) {
  102. context.report({
  103. messageId: 'disabledTest',
  104. node
  105. });
  106. },
  107. 'CallExpression[callee.name="describe"]:exit'() {
  108. suiteDepth--;
  109. },
  110. 'CallExpression[callee.name=/^(it|test)$/]:exit'() {
  111. testDepth--;
  112. }
  113. };
  114. }
  115. });
  116. exports.default = _default;