@@ -20,6 +20,67 @@ describe("Plugin options", () => {
2020 expect ( ( ) => new BundleAnalyzerPlugin ( ) ) . not . toThrow ( ) ;
2121 } ) ;
2222 } ) ;
23+
24+ describe ( "statsOptions" , ( ) => {
25+ async function runPluginDoneHook ( plugin , stats ) {
26+ let doneHook ;
27+ const compiler = {
28+ hooks : {
29+ done : {
30+ tapAsync : jest . fn ( ( name , callback ) => {
31+ doneHook = callback ;
32+ } ) ,
33+ } ,
34+ } ,
35+ outputFileSystem : {
36+ constructor : {
37+ name : "MemoryFileSystem" ,
38+ } ,
39+ } ,
40+ outputPath : path . resolve ( __dirname , "./output" ) ,
41+ } ;
42+
43+ plugin . apply ( compiler ) ;
44+
45+ await new Promise ( ( resolve , reject ) => {
46+ doneHook ( stats , ( error ) => {
47+ if ( error ) {
48+ reject ( error ) ;
49+ } else {
50+ resolve ( ) ;
51+ }
52+ } ) ;
53+ } ) ;
54+ }
55+
56+ it . each ( [
57+ [ "server" , "startAnalyzerServer" ] ,
58+ [ "static" , "generateStaticReport" ] ,
59+ [ "json" , "generateJSONReport" ] ,
60+ ] ) (
61+ "should pass statsOptions to stats.toJson in %s mode" ,
62+ async ( analyzerMode , methodName ) => {
63+ const statsOptions = { all : false , assets : true } ;
64+ const statsJson = { assets : [ ] } ;
65+ const stats = {
66+ toJson : jest . fn ( ( ) => statsJson ) ,
67+ } ;
68+ const plugin = new BundleAnalyzerPlugin ( {
69+ analyzerMode,
70+ openAnalyzer : false ,
71+ statsOptions,
72+ } ) ;
73+ const analyzerMethod = jest
74+ . spyOn ( plugin , methodName )
75+ . mockResolvedValue ( ) ;
76+
77+ await runPluginDoneHook ( plugin , stats ) ;
78+
79+ expect ( stats . toJson ) . toHaveBeenCalledWith ( statsOptions ) ;
80+ expect ( analyzerMethod ) . toHaveBeenCalledWith ( statsJson ) ;
81+ } ,
82+ ) ;
83+ } ) ;
2384} ) ;
2485
2586describe ( "Plugin" , ( ) => {
0 commit comments