Repository navigation
Expand file tree
/
Copy pathStats.unittest.js
More file actions
134 lines (131 loc) · 3.28 KB
/
Copy pathStats.unittest.js
File metadata and controls
134 lines (131 loc) · 3.28 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
128
129
130
131
132
133
134
/*globals describe it */
"use strict";
const Stats = require("../lib/Stats");
describe("Stats", () => {
describe("Error Handling", () => {
describe("does have", () => {
it("hasErrors", () => {
const mockStats = new Stats({
children: [],
errors: ["firstError"],
hash: "1234",
compiler: {
context: ""
}
});
expect(mockStats.hasErrors()).toBe(true);
});
it("hasWarnings", () => {
const mockStats = new Stats({
children: [],
warnings: ["firstError"],
hash: "1234",
compiler: {
context: ""
}
});
expect(mockStats.hasWarnings()).toBe(true);
});
});
describe("does not have", () => {
it("hasErrors", () => {
const mockStats = new Stats({
children: [],
errors: [],
hash: "1234",
compiler: {
context: ""
}
});
expect(mockStats.hasErrors()).toBe(false);
});
it("hasWarnings", () => {
const mockStats = new Stats({
children: [],
warnings: [],
hash: "1234",
compiler: {
context: ""
}
});
expect(mockStats.hasWarnings()).toBe(false);
});
});
describe("children have", () => {
it("hasErrors", () => {
const mockStats = new Stats({
children: [{
getStats: () => new Stats({
errors: ["firstError"],
hash: "5678"
}),
}],
errors: [],
hash: "1234"
});
expect(mockStats.hasErrors()).toBe(true);
});
it("hasWarnings", () => {
const mockStats = new Stats({
children: [{
getStats: () => new Stats({
warnings: ["firstError"],
hash: "5678"
}),
}],
warnings: [],
hash: "1234"
});
expect(mockStats.hasWarnings()).toBe(true);
});
});
it("formatError handles string errors", () => {
const mockStats = new Stats({
errors: ["firstError"],
warnings: [],
assets: [],
entrypoints: new Map(),
chunks: [],
modules: [],
children: [],
hash: "1234",
mainTemplate: {
getPublicPath: () => "path"
},
compiler: {
context: ""
}
});
const obj = mockStats.toJson();
expect(obj.errors[0]).toEqual("firstError");
});
});
describe("Presets", () => {
describe("presetToOptions", () => {
it("returns correct object with 'Normal'", () => {
expect(Stats.presetToOptions("Normal")).toEqual({});
});
it("truthy values behave as 'normal'", () => {
const normalOpts = Stats.presetToOptions("normal");
expect(Stats.presetToOptions("pizza")).toEqual(normalOpts);
expect(Stats.presetToOptions(true)).toEqual(normalOpts);
expect(Stats.presetToOptions(1)).toEqual(normalOpts);
expect(Stats.presetToOptions("verbose")).not.toEqual(normalOpts);
expect(Stats.presetToOptions(false)).not.toEqual(normalOpts);
});
it("returns correct object with 'none'", () => {
expect(Stats.presetToOptions("none")).toEqual({
all: false
});
});
it("falsy values behave as 'none'", () => {
const noneOpts = Stats.presetToOptions("none");
expect(Stats.presetToOptions("")).toEqual(noneOpts);
expect(Stats.presetToOptions(null)).toEqual(noneOpts);
expect(Stats.presetToOptions()).toEqual(noneOpts);
expect(Stats.presetToOptions(0)).toEqual(noneOpts);
expect(Stats.presetToOptions(false)).toEqual(noneOpts);
});
});
});
}, 10000);