Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

2.2 KB
Raw Blame
"use strict";

var path = require("node:path").posix;
var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
var resolvePath = helpers.resolveFixturePath;

describe("--ignore", function () {
  /*
   * Runs mocha in {path} with the given args.
   * Calls handleResult with the result.
   *
   * @param {string} fixture
   * @param {string[]} args
   * @param {function} handleResult
   * @param {function} done
   */
  function runMochaTest(fixture, args, handleResult, done) {
    runMochaJSON(fixture, args, function (err, res) {
      if (err) {
        return done(err);
      }

      handleResult(res);
      done();
    });
  }

  it("should ignore specific files", function (done) {
    var fixtures = path.join("options", "ignore", "*.fixture.js");
    runMochaTest(
      fixtures,
      [
        "--ignore",
        resolvePath(path.join("options", "ignore", "fail.fixture.js")).replace(
          /\\/g,
          "/",
        ),
      ],
      function (res) {
        expect(res, "to have passed")
          .and("to have run test", "should find this test")
          .and("not to have pending tests");
      },
      done,
    );
  });

  it("should ignore globbed files", function (done) {
    var fixtures = path.join("options", "ignore", "**", "*.fixture.js");
    runMochaTest(
      fixtures,
      ["--ignore", "**/fail.fixture.js"],
      function (res) {
        expect(res, "to have passed")
          .and("not to have pending tests")
          .and("to have passed test count", 2);
      },
      done,
    );
  });

  it("should ignore multiple patterns", function (done) {
    var fixtures = path.join("options", "ignore", "**", "*.fixture.js");
    runMochaTest(
      fixtures,
      [
        "--ignore",
        resolvePath(path.join("options", "ignore", "fail.fixture.js")).replace(
          /\\/g,
          "/",
        ),
        "--ignore",
        resolvePath(
          path.join("options", "ignore", "nested", "fail.fixture.js"),
        ).replace(/\\/g, "/"),
      ],
      function (res) {
        expect(res, "to have passed")
          .and("not to have pending tests")
          .and("to have passed test count", 2);
      },
      done,
    );
  });
});