-
Notifications
You must be signed in to change notification settings - Fork 933
/
Copy pathindex.test.js
119 lines (94 loc) · 3.3 KB
/
index.test.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
110
111
112
113
114
115
116
117
118
119
import { test, expect, vi } from "vitest";
import path from "path";
import { fileURLToPath } from "url";
import { npm } from "@commitlint/test";
import config from "./index.js";
const __dirname = path.resolve(fileURLToPath(import.meta.url), "..");
test("exports rules key", () => {
expect(config).toHaveProperty("rules");
});
test("rules hold object", () => {
expect(config).toMatchObject({
rules: expect.any(Object),
});
});
test("rules contain scope-enum", () => {
expect(config).toMatchObject({
rules: {
"scope-enum": expect.anything(),
},
});
});
test("scope-enum is function", () => {
expect(config).toMatchObject({
rules: {
"scope-enum": expect.any(Function),
},
});
});
test("scope-enum does not throw for missing context", async () => {
const { "scope-enum": fn } = config.rules;
await expect(fn()).resolves.toBeTruthy();
});
test("scope-enum has expected severity", async () => {
const { "scope-enum": fn } = config.rules;
const [severity] = await fn();
expect(severity).toBe(2);
});
test("scope-enum has expected modifier", async () => {
const { "scope-enum": fn } = config.rules;
const [, modifier] = await fn();
expect(modifier).toBe("always");
});
test("returns empty value for empty lerna repository", async () => {
const { "scope-enum": fn } = config.rules;
const cwd = await npm.bootstrap("fixtures/empty", __dirname);
const [, , value] = await fn({ cwd });
expect(value).toEqual([]);
});
test("returns all packages for nested lerna packages repository", async () => {
const { "scope-enum": fn } = config.rules;
const cwd = await npm.bootstrap("fixtures/nested", __dirname);
const [, , value] = await fn({ cwd });
expect(value).toEqual(["nested-a", "nested-b", "nested-c"]);
});
test("returns expected value for basic lerna repository", async () => {
const { "scope-enum": fn } = config.rules;
const cwd = await npm.bootstrap("fixtures/basic", __dirname);
const [, , value] = await fn({ cwd });
expect(value).toEqual(["basic-a", "basic-b"]);
});
test("returns expected value for lerna repository containing modules", async () => {
const { "scope-enum": fn } = config.rules;
const cwd = await npm.bootstrap("fixtures/modules", __dirname);
const [, , value] = await fn({ cwd });
expect(value).toEqual(["modules-a"]);
});
test("returns expected value for scoped lerna repository", async () => {
const { "scope-enum": fn } = config.rules;
const cwd = await npm.bootstrap("fixtures/scoped", __dirname);
const [, , value] = await fn({ cwd });
expect(value).toEqual(["scoped-a", "scoped-b"]);
});
test("work with no declared packages", async () => {
const { "scope-enum": fn } = config.rules;
const cwd = await npm.bootstrap(
"fixtures/no-packages-declaration",
__dirname,
);
const [, , value] = await fn({ cwd });
expect(value).toEqual([]);
});
test("inform the user about the transition to config-workspace-scopes if the project is using native workspaces", async () => {
const { "scope-enum": fn } = config.rules;
const cwd = await npm.bootstrap(
"fixtures/transition-to-workspace-scopes",
__dirname,
);
const consoleWarnSpy = vi.spyOn(console, "warn");
const [, , value] = await fn({ cwd });
expect(consoleWarnSpy).toHaveBeenCalledWith(
expect.stringContaining(`It seems that you are using npm/yarn workspaces`),
);
expect(value).toEqual(["workspace-package"]);
});