@@ -7,6 +7,7 @@ const sinon = require("sinon");
77
88const webpack = require ( "../" ) ;
99const WebpackOptionsDefaulter = require ( "../lib/WebpackOptionsDefaulter" ) ;
10+ const Compiler = require ( "../lib/Compiler" ) ;
1011
1112describe ( "Compiler" , ( ) => {
1213 function compile ( entry , options , callback ) {
@@ -164,6 +165,29 @@ describe("Compiler", () => {
164165 done ( ) ;
165166 } ) ;
166167 } ) ;
168+ describe ( "constructor" , ( ) => {
169+ let compiler ;
170+ beforeEach ( ( ) => {
171+ compiler = webpack ( {
172+ entry : "./c" ,
173+ context : path . join ( __dirname , "fixtures" ) ,
174+ output : {
175+ path : "/" ,
176+ pathinfo : true ,
177+ }
178+ } ) ;
179+ } ) ;
180+ describe ( "parser" , ( ) => {
181+ describe ( "apply" , ( ) => {
182+ it ( "invokes sets a 'compilation' plugin" , ( done ) => {
183+ compiler . plugin = sinon . spy ( ) ;
184+ compiler . parser . apply ( ) ;
185+ compiler . plugin . callCount . should . be . exactly ( 1 ) ;
186+ done ( ) ;
187+ } ) ;
188+ } ) ;
189+ } ) ;
190+ } ) ;
167191 describe ( "methods" , ( ) => {
168192 let compiler ;
169193 beforeEach ( ( ) => {
@@ -236,6 +260,31 @@ describe("Compiler", () => {
236260 done ( ) ;
237261 } ) ;
238262 } ) ;
263+ describe ( "createChildCompiler" , ( ) => {
264+ it ( "defaults cache.children if none exists yet" , ( done ) => {
265+ const mockPlugin = sinon . spy ( ) ;
266+ class fakePlugin {
267+ apply ( ) {
268+ mockPlugin ( ) ;
269+ }
270+ }
271+ compiler . cache = { } ;
272+ compiler . createChildCompiler ( { } , "compiler9000" , 0 , { } , [ new fakePlugin ( ) ] ) ;
273+ mockPlugin . callCount . should . be . exactly ( 1 ) ;
274+ compiler . cache . children . should . match ( { } ) ;
275+ done ( ) ;
276+ } ) ;
277+ it ( "defaults cache.children[compilerName] if none exists yet" , ( done ) => {
278+ compiler . cache = {
279+ children : { } ,
280+ } ;
281+ compiler . createChildCompiler ( { } , "compiler9000" , 0 , { } , null ) ;
282+ compiler . cache . children . should . match ( {
283+ compiler9000 : [ ] ,
284+ } ) ;
285+ done ( ) ;
286+ } ) ;
287+ } ) ;
239288 } ) ;
240289 describe ( "Watching" , ( ) => {
241290 let compiler ;
@@ -249,6 +298,14 @@ describe("Compiler", () => {
249298 }
250299 } ) ;
251300 } ) ;
301+ describe ( "static method" , ( ) => {
302+ it ( "should have an accessible static method, Watching" , ( done ) => {
303+ const actual = Compiler . Watching ( compiler , 1000 , err => err ) ;
304+ actual . running . should . be . exactly ( true ) ;
305+ actual . constructor . name . should . be . exactly ( "Watching" ) ;
306+ done ( ) ;
307+ } ) ;
308+ } ) ;
252309 describe ( "constructor" , ( ) => {
253310 it ( "constructs Watching.watchOptions correctly when passed a number, string, or object for watchOptions" , ( done ) => {
254311 const Watching1 = compiler . watch ( 1000 , err => err ) ;
0 commit comments