Skip to content

Commit

Permalink
review feedback, force test to use C:\\ on linux as well
Browse files Browse the repository at this point in the history
  • Loading branch information
nickharris committed Mar 28, 2020
1 parent c4b191d commit ef9da19
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions tests/lib/cli-engine/config-array/ignore-pattern.js
Expand Up @@ -6,6 +6,7 @@

const assert = require("assert");
const path = require("path");
const sinon = require("sinon");
const { IgnorePattern } = require("../../../../lib/cli-engine/config-array/ignore-pattern");

describe("IgnorePattern", () => {
Expand Down Expand Up @@ -56,15 +57,10 @@ describe("IgnorePattern", () => {
/**
* performs static createIgnre assertions against the cwd.
* @param {string} cwd cwd to be the base path for assertions
* @param {Function} ignores the ignore pattern
* @returns {void}
*/
function assertions(cwd) {
const basePath1 = path.join(cwd, "foo/bar");
const basePath2 = path.join(cwd, "abc/");
const ignores = IgnorePattern.createIgnore([
new IgnorePattern(["*.js", "/*.ts", "!a.*", "!/b.*"], basePath1),
new IgnorePattern(["*.js", "/*.ts", "!a.*", "!/b.*"], basePath2)
]);
function assertions(cwd, ignores) {
const patterns = [
["a.js", false],
["a.ts", false],
Expand Down Expand Up @@ -127,14 +123,41 @@ describe("IgnorePattern", () => {
});
}

assertions(process.cwd());
const basePath1 = path.join(process.cwd(), "foo/bar");
const basePath2 = path.join(process.cwd(), "abc/");
const ignores = IgnorePattern.createIgnore([
new IgnorePattern(["*.js", "/*.ts", "!a.*", "!/b.*"], basePath1),
new IgnorePattern(["*.js", "/*.ts", "!a.*", "!/b.*"], basePath2)
]);

assertions(process.cwd(), ignores);

let didThrow = false;

try {
assertions(path.parse(process.cwd()).root);
if (process.platform !== "win32") {
sinon.stub(process, "platform").returns("win32");
sinon.stub(path, "sep").returns("\\");
sinon.replace(path, "isAbsolute", pth => {
if (pth === "C:") {
throw Error("getCommonAncestor should never return C:, it should instead return C:\\");
} else {
return true;
}
});
}
const bp1 = path.join("C:\\", "foo\\bar");
const bp2 = path.join("C:\\", "abc\\");
const ig = IgnorePattern.createIgnore([
new IgnorePattern(["*.js", "/*.ts", "!a.*", "!/b.*"], bp1),
new IgnorePattern(["*.js", "/*.ts", "!a.*", "!/b.*"], bp2)
]);

assertions("C:\\", ig);
} catch {
didThrow = true;
} finally {
sinon.restore();
}

assert.ok(!didThrow, "with two patterns the common ancestor is the root of the drive should not throw exception \"'newBasePath' should be an absolute path\"");
Expand Down

0 comments on commit ef9da19

Please sign in to comment.