-
-
Notifications
You must be signed in to change notification settings - Fork 450
/
PluginBuildDir.test.js
85 lines (66 loc) · 2.38 KB
/
PluginBuildDir.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
const path = require("path");
const fs = require("fs-extra");
const PluginBuildDir = require("../PluginBuildDir");
const logger = require("../../utils/logger");
jest.mock("fs-extra");
jest.mock("../../utils/logger");
describe("PluginBuildDir", () => {
describe("#constructor", () => {
it("should set the next config directory", () => {
const nextConfigDir = "/path/to/nextApp";
const pluginBuildDir = new PluginBuildDir(nextConfigDir);
expect(pluginBuildDir.nextConfigDir).toEqual(nextConfigDir);
});
});
describe("When a new instance is created", () => {
let pluginBuildDir;
let nextConfigDir;
beforeEach(() => {
nextConfigDir = "path/to/nextApp";
pluginBuildDir = new PluginBuildDir(nextConfigDir);
});
it("should have buildDir at same level as next config.", () => {
expect(pluginBuildDir.buildDir).toEqual(
path.join(nextConfigDir, PluginBuildDir.BUILD_DIR_NAME)
);
});
it("should have posixBuildDir regardless the platform", () => {
expect(pluginBuildDir.posixBuildDir).toEqual(
`path/to/nextApp/${PluginBuildDir.BUILD_DIR_NAME}`
);
});
});
describe("#setupBuildDir", () => {
it("should call fs emptyDir to create dir if doesnt exist or cleanup", () => {
expect.assertions(1);
fs.emptyDir.mockResolvedValueOnce();
const nextConfigDir = "path/to/nextApp";
pluginBuildDir = new PluginBuildDir(nextConfigDir);
return pluginBuildDir.setupBuildDir().then(() => {
expect(fs.emptyDir).toBeCalledWith(pluginBuildDir.buildDir);
});
});
});
describe("#removeBuildDir", () => {
it("should log when it starts removing", () => {
expect.assertions(1);
fs.remove.mockResolvedValueOnce();
const nextConfigDir = "path/to/nextApp";
pluginBuildDir = new PluginBuildDir(nextConfigDir);
return pluginBuildDir.removeBuildDir().then(() => {
expect(logger.log).toBeCalledWith(
expect.stringContaining("Cleaning up")
);
});
});
it("should call fs remove", () => {
expect.assertions(1);
fs.remove.mockResolvedValueOnce();
const nextConfigDir = "path/to/nextApp";
pluginBuildDir = new PluginBuildDir(nextConfigDir);
return pluginBuildDir.removeBuildDir().then(() => {
expect(fs.remove).toBeCalledWith(pluginBuildDir.buildDir);
});
});
});
});