-
Notifications
You must be signed in to change notification settings - Fork 7
/
mod.test.ts
57 lines (52 loc) · 1.65 KB
/
mod.test.ts
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
import { context } from "../../../../../cli/src/plugin/mod.ts";
import { assertEquals, deepMerge, WalkEntry } from "../../../../../cli/deps.ts";
import { introspect } from "./mod.ts";
const fakeContext = (
{
withStylelint = true,
devDependencies = true,
} = {},
) => {
return deepMerge(
context,
{
files: {
each: async function* (glob: string): AsyncIterableIterator<WalkEntry> {
if (glob === "**/package.json") {
yield {
name: "package.json",
path: "fake-path",
isFile: true,
isSymlink: false,
isDirectory: false,
};
}
return;
},
// deno-lint-ignore require-await
readJSON: async (path: string): Promise<Record<string, unknown>> => {
const deps = { stylelint: "1.0.0" };
if (!withStylelint) return {};
if (path === "fake-path") {
return devDependencies
? { devDependencies: deps }
: { dependencies: deps };
}
return {};
},
},
},
);
};
Deno.test("Plugins > _shared > Stylelint - at devDependecies", async () => {
const result = await introspect(fakeContext());
assertEquals(result, { name: "stylelint" });
});
Deno.test("Plugins > _shared > Stylelint - at dependecies", async () => {
const result = await introspect(fakeContext({ devDependencies: false }));
assertEquals(result, { name: "stylelint" });
});
Deno.test("Plugins > _shared > Stylelint - not present", async () => {
const result = await introspect(fakeContext({ withStylelint: false }));
assertEquals(result, null);
});