Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
webpack/test/Stats.test.js at master · zen-java/webpack · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
zen-java
/
webpack
Public
forked from
webpack/webpack
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
webpack
/
test
/
Stats.test.js
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
183 lines (173 loc) · 5.61 KB
master
Breadcrumbs
webpack
/
test
/
Stats.test.js
Copy path
Top
File metadata and controls
Code
Blame
183 lines (173 loc) · 5.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*globals describe it */
"use strict"
;
require
(
"should"
)
;
const
path
=
require
(
"path"
)
;
const
fs
=
require
(
"fs"
)
;
const
webpack
=
require
(
"../lib/webpack"
)
;
const
base
=
path
.
join
(
__dirname
,
"statsCases"
)
;
const
outputBase
=
path
.
join
(
__dirname
,
"js"
,
"stats"
)
;
const
tests
=
fs
.
readdirSync
(
base
)
.
filter
(
testName
=>
fs
.
existsSync
(
path
.
join
(
base
,
testName
,
"index.js"
)
)
||
fs
.
existsSync
(
path
.
join
(
base
,
testName
,
"webpack.config.js"
)
)
)
;
const
Stats
=
require
(
"../lib/Stats"
)
;
describe
(
"Stats"
,
(
)
=>
{
tests
.
forEach
(
testName
=>
{
it
(
"should print correct stats for "
+
testName
,
(
done
)
=>
{
let
options
=
{
entry
:
"./index"
,
output
:
{
filename
:
"bundle.js"
}
}
;
if
(
fs
.
existsSync
(
path
.
join
(
base
,
testName
,
"webpack.config.js"
)
)
)
{
options
=
require
(
path
.
join
(
base
,
testName
,
"webpack.config.js"
)
)
;
}
(
Array
.
isArray
(
options
)
?
options
:
[
options
]
)
.
forEach
(
(
options
)
=>
{
if
(
!
options
.
context
)
options
.
context
=
path
.
join
(
base
,
testName
)
;
if
(
!
options
.
output
)
options
.
output
=
options
.
output
||
{
}
;
if
(
!
options
.
output
.
path
)
options
.
output
.
path
=
path
.
join
(
outputBase
,
testName
)
;
}
)
;
const
c
=
webpack
(
options
)
;
const
compilers
=
c
.
compilers
?
c
.
compilers
:
[
c
]
;
compilers
.
forEach
(
(
c
)
=>
{
const
ifs
=
c
.
inputFileSystem
;
c
.
inputFileSystem
=
Object
.
create
(
ifs
)
;
c
.
inputFileSystem
.
readFile
=
function
(
)
{
const
args
=
Array
.
prototype
.
slice
.
call
(
arguments
)
;
const
callback
=
args
.
pop
(
)
;
ifs
.
readFile
.
apply
(
ifs
,
args
.
concat
(
[
(
err
,
result
)
=>
{
if
(
err
)
return
callback
(
err
)
;
callback
(
null
,
result
.
toString
(
"utf-8"
)
.
replace
(
/
\r
/
g
,
""
)
)
;
}
]
)
)
;
}
;
c
.
apply
(
new
webpack
.
optimize
.
OccurrenceOrderPlugin
(
)
)
;
}
)
;
c
.
run
(
(
err
,
stats
)
=>
{
if
(
err
)
return
done
(
err
)
;
if
(
/
e
r
r
o
r
$
/
.
test
(
testName
)
)
{
stats
.
hasErrors
(
)
.
should
.
be
.
equal
(
true
)
;
}
else
if
(
stats
.
hasErrors
(
)
)
{
done
(
new
Error
(
stats
.
toJson
(
)
.
errors
.
join
(
"\n\n"
)
)
)
;
}
let
toStringOptions
=
{
colors
:
false
}
;
let
hasColorSetting
=
false
;
if
(
typeof
options
.
stats
!==
"undefined"
)
{
toStringOptions
=
options
.
stats
;
hasColorSetting
=
typeof
options
.
stats
.
colors
!==
"undefined"
;
}
if
(
Array
.
isArray
(
options
)
&&
!
toStringOptions
.
children
)
{
toStringOptions
.
children
=
options
.
map
(
o
=>
o
.
stats
)
;
}
let
actual
=
stats
.
toString
(
toStringOptions
)
;
(
typeof
actual
)
.
should
.
be
.
eql
(
"string"
)
;
if
(
!
hasColorSetting
)
{
actual
=
actual
.
replace
(
/
\u001b
\[
[
0
-
9
;
]
*
m
/
g
,
""
)
.
replace
(
/
[
0
-
9
]
+
(
\s
?
m
s
)
/
g
,
"X$1"
)
;
}
else
{
actual
=
actual
.
replace
(
/
\u001b
\[
1
m
\u001b
\[
(
[
0
-
9
;
]
*
)
m
/
g
,
"<CLR=$1,BOLD>"
)
.
replace
(
/
\u001b
\[
1
m
/
g
,
"<CLR=BOLD>"
)
.
replace
(
/
\u001b
\[
3
9
m
\u001b
\[
2
2
m
/
g
,
"</CLR>"
)
.
replace
(
/
\u001b
\[
(
[
0
-
9
;
]
*
)
m
/
g
,
"<CLR=$1>"
)
.
replace
(
/
[
0
-
9
]
+
(
<
\/
C
L
R
>
)
?
(
\s
?
m
s
)
/
g
,
"X$1$2"
)
;
}
actual
=
actual
.
replace
(
/
\r
\n
?
/
g
,
"\n"
)
.
replace
(
/
[
\t
]
*
V
e
r
s
i
o
n
:
.
+
\n
/
g
,
""
)
.
replace
(
path
.
join
(
base
,
testName
)
,
"Xdir/"
+
testName
)
.
replace
(
/
d
e
p
e
n
d
e
n
c
i
e
s
:
X
m
s
/
g
,
""
)
;
const
expected
=
fs
.
readFileSync
(
path
.
join
(
base
,
testName
,
"expected.txt"
)
,
"utf-8"
)
.
replace
(
/
\r
/
g
,
""
)
;
if
(
actual
!==
expected
)
{
fs
.
writeFileSync
(
path
.
join
(
base
,
testName
,
"actual.txt"
)
,
actual
,
"utf-8"
)
;
}
else
if
(
fs
.
existsSync
(
path
.
join
(
base
,
testName
,
"actual.txt"
)
)
)
{
fs
.
unlinkSync
(
path
.
join
(
base
,
testName
,
"actual.txt"
)
)
;
}
actual
.
should
.
be
.
eql
(
expected
)
;
done
(
)
;
}
)
;
}
)
;
}
)
;
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
)
;
}
)
;
}
)
;
}
)
;
}
)
;
You can’t perform that action at this time.