-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlayers.test.js
More file actions
127 lines (103 loc) · 4.33 KB
/
layers.test.js
File metadata and controls
127 lines (103 loc) · 4.33 KB
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
120
121
122
123
124
125
126
127
const { ESLint } = require("eslint");
const assert = require("assert");
const { configLib } = require("../../utils");
const cfg = require("./");
const eslint = new ESLint({
useEslintrc: false,
baseConfig: configLib.setParser(
configLib.mockImports(cfg)
),
});
describe("Import boundaries between layers", () => {
describe("IDDQD boundaries", () => {
it("should lint without errors in GodMode for _computed entities", async () => {
const report = await eslint.lintText(`
import { userModel } from "entities/user";
import { getUser } from "shared/api/user-api";
`,
{filePath: "src/entities/_computed/UserPost/model.js"});
assert.strictEqual(report[0].errorCount, 0);
});
it("should lint with errors for computed entities", async () => {
const report = await eslint.lintText(`
import { userModel } from "entities/user";
`,
{filePath: "src/entities/computed/UserPost/model.js"});
assert.strictEqual(report[0].errorCount, 1);
});
it("should lint without errors in GodMode for pages", async () => {
const report = await eslint.lintText(`
import { FooPage } from "pages/foo";
import { BagFeature } from "features/bag";
import { format } from "shared/lib/format";
import { BarPage } from "../bar";
`,
{filePath: "src/pages/_router/private.routes.js"});
assert.strictEqual(report[0].errorCount, 0);
});
it("should lint with errors in GodMode for upper layers", async () => {
const report = await eslint.lintText(`
import { MainPage } from "pages/main";
import { UserFeature } from "features/user";
`,
{filePath: "src/entities/_computed/UserPost/model.js"});
assert.strictEqual(report[0].errorCount, 2);
});
it("should lint with errors without GodMode for pages", async () => {
const report = await eslint.lintText(`
import { FooPage } from "pages/foo";
`,
{filePath: "src/pages/router/private.routes.js"});
assert.strictEqual(report[0].errorCount, 1);
});
})
it("should lint with cross-import errors.", async () => {
const wrongImports = [
`import { getRoute } from "pages/auth";`,
`import { getStore } from "app/store";`,
];
const report = await eslint.lintText(wrongImports.join("\n"), {
filePath: "src/shared/lib/index.js",
});
assert.strictEqual(report[0].errorCount, wrongImports.length);
});
it("should lint without errors.", async () => {
const validCodeSnippet = [
`import { sessionModel } from "entities/session";`,
`import { Form, Button } from "shared/ui";`,
].join("\n");
const report = await eslint.lintText(validCodeSnippet, {
filePath: "src/app/ui/app.js",
});
assert.strictEqual(report[0].errorCount, 0);
});
it("should lint without errors when import from shared.", async () => {
const validCodeSnippet = [
`import { API_TOKEN } from "shared/config"`,
`import { Form } from "shared/ui";`,
].join("\n");
const report = await eslint.lintText(validCodeSnippet, {
filePath: "src/shared/ui/button.js",
});
assert.strictEqual(report[0].errorCount, 0);
});
it("should lint without errors when import from app.", async () => {
const validCodeSnippet = [
`import "app/styles/styles.css"`,
`import { withProviders } from "app/providers"`,
].join("\n");
const report = await eslint.lintText(validCodeSnippet, {
filePath: "src/app/ui/app.tsx",
});
assert.strictEqual(report[0].errorCount, 0);
});
it("should lint with errors when import from app.", async () => {
const wrongImports = [
`import { withProviders } from "app/providers"`,
];
const report = await eslint.lintText(wrongImports.join("\n"), {
filePath: "src/features/add-user/model.tsx",
});
assert.strictEqual(report[0].errorCount, wrongImports.length);
});
});