-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
67 lines (52 loc) · 2.63 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
const { isNodeModulesImport } = require(".");
describe("isNodeModulesImport", () => {
describe("for a file inside project", () => {
test("returns false for relative non node_modules import path", () => {
expect(isNodeModulesImport(".", "./index.js")).toBe(false);
});
test("returns false for relative non node_modules import path", () => {
expect(isNodeModulesImport(".", "./index.js")).toBe(false);
});
test("returns true for one-level node_modules import path", () => {
expect(isNodeModulesImport(".", "prettier")).toBe(true);
});
test("returns false for one-level non-existent node_modules import path", () => {
expect(isNodeModulesImport(".", "react")).toBe(false);
});
test("returns true for two-level node_modules import path", () => {
expect(isNodeModulesImport(".", "prettier/plugins")).toBe(true);
});
test("returns true for relative node_modules import path", () => {
expect(isNodeModulesImport(".", "./node_modules/prettier")).toBe(true);
});
test("returns true for absolute node_modules import path", () => {
expect(isNodeModulesImport(".", `${__dirname}/node_modules/prettier`)).toBe(true);
});
test("returns false for absolute non node_modules import path", () => {
expect(isNodeModulesImport(".", `${__dirname}/index.js`)).toBe(false);
});
});
describe("for a file outside project", () => {
test("returns false for project one-level node_modules import path", () => {
expect(isNodeModulesImport("../index.js", "prettier")).toBe(false);
});
test("returns false for project two-level node_modules import path", () => {
expect(isNodeModulesImport("../index.js", "prettier/plugins")).toBe(false);
});
test("returns false for project relative node_modules import path", () => {
expect(isNodeModulesImport("../index.js", "./node_modules/prettier")).toBe(false);
});
test("returns false for project absolute non-existent node_modules import path", () => {
expect(isNodeModulesImport("../index.js", `${__dirname}/node_modules/react`)).toBe(false);
});
test("returns true for relative node_modules import path", () => {
expect(isNodeModulesImport("../index.js", "./is-node-modules-import/node_modules/prettier")).toBe(true);
});
test("returns true for absolute node_modules import path", () => {
expect(isNodeModulesImport("../index.js", `${__dirname}/node_modules/prettier`)).toBe(true);
});
test("returns false for absolute non node_modules import path", () => {
expect(isNodeModulesImport("../index.js", `${__dirname}/index.js`)).toBe(false);
});
});
});