no-skipped-tests

Try in Playground
playwright

oscar143

Best PracticeInformational

0

playwright

No CWE or CVE

Ensure tests are not skipped

Ast Rule: function call


no-skipped-tests

How to write a rule
// See https://doc.codiga.io/docs/rosie/ast/javascript/rosie-ast-javascript-functioncall/
function getFunctionName(node) {
  if (node.astType === "member") {
    return node.name.value;
  }

  if (node.astType === "string") {
    return node.value;
  }

  return "";
}

function visit(node, filename, code) {
  // only run inside spec files
  if (!filename.includes(".spec.") && !filename.includes(".test.")) return;

  // Check this is a function call and the function name is a simple string
  if (
    node.functionName &&
    node.functionName.astType === "member" &&
    getFunctionName(node.functionName) === "skip" &&
    (
      getFunctionName(node.functionName.parent) === "test" ||
      getFunctionName(node.functionName.parent) === "describe"
    )
  ) {
    const error = buildError(
      node.functionName.start.line,
      node.functionName.start.col,
      node.functionName.end.line,
      node.functionName.end.col,
      "Unexpected use of the `.skip()` annotation.",
      "INFORMATIONAL",
      "BEST_PRACTICE"
    );

    const editRemove = buildEditRemove(
      node.functionName.name.start.line,
      node.functionName.name.start.col - 1,
      node.functionName.name.end.line,
      node.functionName.name.end.col,
    );

    const fix = buildFix("Remove the `.skip()` annotation.", [editRemove]);

    addError(error.addFix(fix));
  }
}

test.spec.js

Expected test result: has error

Examples of incorrect code for this rule

test.skip('skip this test', async ({ page }) => {});

test.describe.skip('skip two tests', () => {
  test('one', async ({ page }) => {});
  test('two', async ({ page }) => {});
});

test.describe('skip test inside describe', () => {
  test.skip();
});

test.describe('skip test conditionally', async ({ browserName }) => {
  test.skip(browserName === 'firefox', 'Working on it');
});

test.spec.js

Expected test result: no error

Examples of correct code for this rule

test('this test', async ({ page }) => {});

test.describe('two tests', () => {
  test('one', async ({ page }) => {});
  test('two', async ({ page }) => {});
});
Add comment

Log in to add a comment


    Be the first one to leave a comment!

Codiga Logo
Codiga Hub
  • Rulesets
  • Playground
  • Snippets
  • Cookbooks
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.