-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
80 lines (68 loc) · 2.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
const { expect, it } = require("@jest/globals");
const manager = require("./index");
beforeEach(() => manager.setUp());
afterEach(() => manager.tearDown());
it("requires cleanly", () => {
expect(manager).toBeTruthy();
});
describe("install", () => {
it("installs one package", () => {
manager.install("apple");
const list = manager.list();
expect(list).toMatchObject(["apple"]);
});
});
describe("depend", () => {
it("remembers dependencies", () => {
manager.depend("apple", "banana");
manager.install("apple");
const list = manager.list();
expect(list).toEqual(expect.arrayContaining(["apple", "banana"]));
expect(list).toHaveLength(2);
});
it("doesn't install a dependency twice", () => {
manager.depend("apple", "banana");
manager.install("banana");
// some hasty implementations will install banana twice with this command
manager.install("apple");
const list = manager.list();
expect(list).toEqual(expect.arrayContaining(["apple", "banana"]));
expect(list).toHaveLength(2);
});
it("supports multiple dependencies", () => {
manager.depend("apple", "banana", "carrot");
manager.install("apple");
const list = manager.list();
expect(list).toEqual(expect.arrayContaining(["apple", "banana", "carrot"]));
expect(list).toHaveLength(3);
});
});
describe("remove", () => {
it("removes packages", () => {
manager.install("apple");
manager.install("banana");
manager.remove("banana");
const list = manager.list();
expect(list).toMatchObject(["apple"]);
});
it("won't remove a required package", () => {
manager.depend("apple", "banana", "carrot");
manager.install("apple");
manager.remove("banana");
const list = manager.list();
expect(list).toEqual(expect.arrayContaining(["apple", "banana", "carrot"]));
expect(list).toHaveLength(3);
});
});
describe("gotchas", () => {
it("remembers user-required packages", () => {
manager.depend("apple", "banana", "carrot");
manager.install("banana");
manager.install("apple");
manager.remove("apple");
// the user remove apple, but not banana. They still would like to have banana installed
const list = manager.list();
expect(list).toEqual(expect.arrayContaining(["banana", "carrot"]));
expect(list).toHaveLength(2);
});
});