-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathlib.spec.js
109 lines (103 loc) · 3.62 KB
/
lib.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"use strict";
const path = require("upath");
var assert = require("assert");
const lib = require("./lib");
describe("canIncludePath", () => {
it("no patterns excludes a fila", () => {
assert.ok(!lib.canIncludePath([], [], "excludeme.txt"));
});
it("should exclude a dot file", () => {
assert.ok(!lib.canIncludePath([], [], ".gitignore"));
});
it("should exclude a directory", () => {
assert.ok(!lib.canIncludePath([], [], ".excludeme"));
});
it("should exclude a file in a directory", () => {
assert.ok(!lib.canIncludePath([], [], ".excludeme/text.txt"));
});
it("should include a file in a directory", () => {
assert.ok(
lib.canIncludePath(["includeme/*"], [], "includeme/text.txt")
);
});
it("should include a file in dot directory", () => {
assert.ok(lib.canIncludePath([".git/**/*"], [], ".git/xx/ignore"));
});
it("should respect a partial wildcard", () => {
assert.ok(
lib.canIncludePath(["includeme/*.txt"], [], "includeme/text.txt")
);
});
it("should exclude a dot file by default", () => {
assert.ok(!lib.canIncludePath(["*"], [], ".gitignore"));
});
it("dot file must be explicitly included", () => {
assert.ok(lib.canIncludePath([".*"], [], ".gitignore"));
});
it("should respect an exclude", () => {
assert.ok(!lib.canIncludePath(["*"], ["*.txt"], "excludeme.txt"));
});
it("should handle an undefined exclude", () => {
assert.ok(lib.canIncludePath(["*"], undefined, "excludeme.txt"));
});
});
describe("dirParseSync", () => {
it("should throw on a bad start directory", () => {
const testDir = "./throw";
assert.throws(() => lib.parseLocal(["*"], testDir, testDir), Error);
});
it("should traverse simple directory", () => {
const rootDir = path.join(__dirname, "../test/simple");
assert.deepEqual(lib.parseLocal(["*"], [], rootDir, "/"), {
"/": ["test-inside-root.txt"],
inner: ["test-inside-root.excl"],
});
});
it("should respect a negate (!)", () => {
const rootDir = path.join(__dirname, "../test/simple");
assert.deepEqual(lib.parseLocal(["!*.excl"], [], rootDir, "/"), {
"/": ["test-inside-root.txt"],
});
});
it("should respect excludes (directory)", () => {
const rootDir = path.join(__dirname, "../test/local");
assert.deepEqual(
lib.parseLocal(
[".*", "*", "*/**"],
[".*", "*", "*/**"],
rootDir,
"/"
),
{ "/": [] }
);
});
it("should traverse test directory", () => {
const rootDir = path.join(__dirname, "../test/local");
let exp2 = Object.assign(exp, {
[path.join("folderA/folderB/FolderC")]: ["test-inside-c.txt"],
});
assert.deepEqual(
lib.parseLocal(["*"], [".excludeme/**/*"], rootDir, "/"),
exp2
);
});
it("should exclude dot files/dirs", () => {
const rootDir = path.join(__dirname, "../test/test2");
const res = lib.parseLocal(
["*", "*/**"],
["n_modules/**/*", "n_modules/**/.*"],
rootDir,
"/"
);
assert.deepEqual(res, { "/": [], src: ["index.js"] });
});
});
let exp = {
"/": ["test-inside-root.txt"],
folderA: ["test-inside-a.txt"],
[path.join("folderA/folderB")]: ["test-inside-b.txt"],
[path.join("folderA/folderB/emptyC/folderD")]: [
"test-inside-d-1.txt",
"test-inside-d-2.txt",
],
};