Skip to content

Commit

Permalink
feat: fixed failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
veritem committed Apr 3, 2022
1 parent 6cf3679 commit 9c239a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/rules/no-skipped-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const invalids = [
]


it.skip(RULE_NAME, () => {
it(RULE_NAME, () => {
const ruleTester: RuleTester = new RuleTester({
parser: require.resolve("@typescript-eslint/parser"),
})
Expand Down
70 changes: 14 additions & 56 deletions src/rules/no-skipped-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,22 @@ export default createEslintRule<Options, MessageIds>({
},
defaultOptions: [],
create: (context) => {
let suiteDepth = 0;
let testDepth = 0;

return {
'CallExpression[callee.name="describe"]'() {
suiteDepth++;
},
'CallExpression[callee.name=/^(it|test)$/]'() {
testDepth++;
},
'CallExpression[callee.name=/^(it|test)$/][arguments.length<2]'(node) {
context.report({ messageId: "noSkippedTests", node });
},
CallExpression(node) {


//@ts-ignore
const functionName = (node.callee.name || '').toLowerCase()

// prevent duplicate warnings for it.each()()
if (node.callee.type === 'CallExpression') {
return;
}

//TODO test for skipped tests

console.log(functionName)

switch (functionName) {
case 'describe.skip.each':
case 'xdescribe.each':
case 'describe.skip':
context.report({ messageId: "noSkippedTests", node });
break;
case 'it.skip':
case 'it.concurrent.skip':
case 'test.skip':
case 'test.concurrent.skip':
case 'it.skip.each':
case 'test.skip.each':
case 'xit.each':
case 'xtest.each':
context.report({ messageId: "noSkippedTests", node });
break;
ExpressionStatement(node) {
if (node.expression.type === 'CallExpression') {
const { callee } = node.expression;
if (callee.type === 'MemberExpression' && callee.object.type === 'Identifier' && callee.object.name === 'it' && callee.property.type === 'Identifier' && callee.property.name === 'skip') {
context.report({
node,
messageId: 'noSkippedTests',
//TODO: make this fix work
// fix: (fixer) => {
// return fixer.removeRange([node.range[0], args[0].range[1]]);
// }
});
}
}
},
'CallExpression[callee.name="xdescribe"]'(node) {
context.report({ messageId: "noSkippedTests", node });
},
'CallExpression[callee.name=/^(xit|xtest)$/]'(node) {
context.report({ messageId: "noSkippedTests", node });
},
'CallExpression[callee.name="describe"]:exit'() {
suiteDepth--;
},
'CallExpression[callee.name=/^(it|test)$/]:exit'() {
testDepth--;
},
}
}
}
})

0 comments on commit 9c239a1

Please sign in to comment.