@@ -20,6 +20,91 @@ describe("Plugin options", () => {
2020 expect ( ( ) => new BundleAnalyzerPlugin ( ) ) . not . toThrow ( ) ;
2121 } ) ;
2222 } ) ;
23+
24+ describe ( "statsOptions" , ( ) => {
25+ const expectedAnalyzerStatsOptions = {
26+ all : false ,
27+ assets : true ,
28+ cachedAssets : true ,
29+ cachedModules : true ,
30+ cached : true ,
31+ children : true ,
32+ chunks : true ,
33+ chunkModules : true ,
34+ chunkModulesSpace : Number . POSITIVE_INFINITY ,
35+ depth : true ,
36+ entrypoints : true ,
37+ errors : false ,
38+ errorsCount : false ,
39+ ids : true ,
40+ modules : true ,
41+ modulesSpace : Number . POSITIVE_INFINITY ,
42+ nestedModules : true ,
43+ nestedModulesSpace : Number . POSITIVE_INFINITY ,
44+ runtimeModules : false ,
45+ source : false ,
46+ warnings : false ,
47+ warningsCount : false ,
48+ } ;
49+
50+ async function runPluginDoneHook ( plugin , stats ) {
51+ let doneHook ;
52+ const compiler = {
53+ hooks : {
54+ done : {
55+ tapAsync : jest . fn ( ( name , callback ) => {
56+ doneHook = callback ;
57+ } ) ,
58+ } ,
59+ } ,
60+ outputFileSystem : {
61+ constructor : {
62+ name : "MemoryFileSystem" ,
63+ } ,
64+ } ,
65+ outputPath : path . resolve ( __dirname , "./output" ) ,
66+ } ;
67+
68+ plugin . apply ( compiler ) ;
69+
70+ await new Promise ( ( resolve , reject ) => {
71+ doneHook ( stats , ( error ) => {
72+ if ( error ) {
73+ reject ( error ) ;
74+ } else {
75+ resolve ( ) ;
76+ }
77+ } ) ;
78+ } ) ;
79+ }
80+
81+ it . each ( [
82+ [ "server" , "startAnalyzerServer" ] ,
83+ [ "static" , "generateStaticReport" ] ,
84+ [ "json" , "generateJSONReport" ] ,
85+ ] ) (
86+ "should use analyzer stats options in %s mode" ,
87+ async ( analyzerMode , methodName ) => {
88+ const statsJson = { assets : [ ] } ;
89+ const stats = {
90+ toJson : jest . fn ( ( ) => statsJson ) ,
91+ } ;
92+ const plugin = new BundleAnalyzerPlugin ( {
93+ analyzerMode,
94+ openAnalyzer : false ,
95+ statsOptions : { all : false , assets : false } ,
96+ } ) ;
97+ const analyzerMethod = jest
98+ . spyOn ( plugin , methodName )
99+ . mockResolvedValue ( ) ;
100+
101+ await runPluginDoneHook ( plugin , stats ) ;
102+
103+ expect ( stats . toJson ) . toHaveBeenCalledWith ( expectedAnalyzerStatsOptions ) ;
104+ expect ( analyzerMethod ) . toHaveBeenCalledWith ( statsJson ) ;
105+ } ,
106+ ) ;
107+ } ) ;
23108} ) ;
24109
25110describe ( "Plugin" , ( ) => {
0 commit comments