forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStats.unittest.js
89 lines (85 loc) · 2.34 KB
/
Stats.unittest.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
86
87
88
89
/*globals describe it */
"use strict";
require("should");
const Stats = require("../lib/Stats");
describe("Stats", () => {
describe("Error Handling", () => {
describe("does have", () => {
it("hasErrors", () => {
const mockStats = new Stats({
errors: ["firstError"],
hash: "1234"
});
mockStats.hasErrors().should.be.ok();
});
it("hasWarnings", () => {
const mockStats = new Stats({
warnings: ["firstError"],
hash: "1234"
});
mockStats.hasWarnings().should.be.ok();
});
});
describe("does not have", () => {
it("hasErrors", () => {
const mockStats = new Stats({
errors: [],
hash: "1234"
});
mockStats.hasErrors().should.not.be.ok();
});
it("hasWarnings", () => {
const mockStats = new Stats({
warnings: [],
hash: "1234"
});
mockStats.hasWarnings().should.not.be.ok();
});
});
it("formatError handles string errors", () => {
const mockStats = new Stats({
errors: ["firstError"],
warnings: [],
assets: [],
entrypoints: {},
chunks: [],
modules: [],
children: [],
hash: "1234",
mainTemplate: {
getPublicPath: () => "path"
}
});
const obj = mockStats.toJson();
obj.errors[0].should.be.equal("firstError");
});
});
describe("Presets", () => {
describe("presetToOptions", () => {
it("returns correct object with 'Normal'", () => {
Stats.presetToOptions("Normal").should.eql({});
});
it("truthy values behave as 'normal'", () => {
const normalOpts = Stats.presetToOptions("normal");
Stats.presetToOptions("pizza").should.eql(normalOpts);
Stats.presetToOptions(true).should.eql(normalOpts);
Stats.presetToOptions(1).should.eql(normalOpts);
Stats.presetToOptions("verbose").should.not.eql(normalOpts);
Stats.presetToOptions(false).should.not.eql(normalOpts);
});
it("returns correct object with 'none'", () => {
Stats.presetToOptions("none").should.eql({
all: false
});
});
it("falsy values behave as 'none'", () => {
const noneOpts = Stats.presetToOptions("none");
Stats.presetToOptions("").should.eql(noneOpts);
Stats.presetToOptions(null).should.eql(noneOpts);
Stats.presetToOptions().should.eql(noneOpts);
Stats.presetToOptions(0).should.eql(noneOpts);
Stats.presetToOptions(false).should.eql(noneOpts);
});
});
});
});