1+ /* globals describe, it, beforeEach */
12"use strict" ;
23
34const should = require ( "should" ) ;
4- const path = require ( "path " ) ;
5+ const sinon = require ( "sinon " ) ;
56const Chunk = require ( "../lib/Chunk" ) ;
67
78describe ( "Chunk" , ( ) => {
@@ -25,7 +26,7 @@ describe("Chunk", () => {
2526 describe ( "entry" , ( ) => {
2627 it ( "returns an error if get entry" , ( ) =>
2728 should ( ( ) => {
28- const entryTest = ChunkInstance . entry ;
29+ ChunkInstance . entry ;
2930 } ) . throw ( "Chunk.entry was removed. Use hasRuntime()" ) ) ;
3031
3132 it ( "returns an error if set an entry" , ( ) =>
@@ -37,7 +38,7 @@ describe("Chunk", () => {
3738 describe ( "initial" , ( ) => {
3839 it ( "returns an error if get initial" , ( ) =>
3940 should ( ( ) => {
40- const initialTest = ChunkInstance . initial ;
41+ ChunkInstance . initial ;
4142 } ) . throw ( "Chunk.initial was removed. Use isInitial()" ) ) ;
4243
4344 it ( "returns an error if set an initial" , ( ) =>
@@ -84,4 +85,82 @@ describe("Chunk", () => {
8485 should ( ChunkInstance . canBeIntegrated ( other ) ) . be . true ( ) ;
8586 } ) ;
8687 } ) ;
88+
89+ describe ( "removeModule" , function ( ) {
90+ let module ;
91+ let removeChunkSpy ;
92+ beforeEach ( function ( ) {
93+ removeChunkSpy = sinon . spy ( ) ;
94+ module = {
95+ removeChunk : removeChunkSpy
96+ } ;
97+ } ) ;
98+ describe ( "and the chunk does not contain this module" , function ( ) {
99+ it ( "returns false" , function ( ) {
100+ ChunkInstance . removeModule ( module ) . should . eql ( false ) ;
101+ } ) ;
102+ } ) ;
103+ describe ( "and the chunk does contain this module" , function ( ) {
104+ beforeEach ( function ( ) {
105+ ChunkInstance . modules = [ module ] ;
106+ } ) ;
107+ it ( "calls module.removeChunk with itself and returns true" , function ( ) {
108+ ChunkInstance . removeModule ( module ) . should . eql ( true ) ;
109+ removeChunkSpy . callCount . should . eql ( 1 ) ;
110+ removeChunkSpy . args [ 0 ] [ 0 ] . should . eql ( ChunkInstance ) ;
111+ } ) ;
112+ } ) ;
113+ } ) ;
114+
115+ describe ( "removeChunk" , function ( ) {
116+ let chunk ;
117+ let removeParentSpy ;
118+ beforeEach ( function ( ) {
119+ removeParentSpy = sinon . spy ( ) ;
120+ chunk = {
121+ removeParent : removeParentSpy
122+ } ;
123+ } ) ;
124+ describe ( "and the chunk does not contain this chunk" , function ( ) {
125+ it ( "returns false" , function ( ) {
126+ ChunkInstance . removeChunk ( chunk ) . should . eql ( false ) ;
127+ } ) ;
128+ } ) ;
129+ describe ( "and the chunk does contain this module" , function ( ) {
130+ beforeEach ( function ( ) {
131+ ChunkInstance . chunks = [ chunk ] ;
132+ } ) ;
133+ it ( "calls module.removeChunk with itself and returns true" , function ( ) {
134+ ChunkInstance . removeChunk ( chunk ) . should . eql ( true ) ;
135+ removeParentSpy . callCount . should . eql ( 1 ) ;
136+ removeParentSpy . args [ 0 ] [ 0 ] . should . eql ( ChunkInstance ) ;
137+ } ) ;
138+ } ) ;
139+ } ) ;
140+
141+ describe ( "removeParent" , function ( ) {
142+ let chunk ;
143+ let removeChunkSpy ;
144+ beforeEach ( function ( ) {
145+ removeChunkSpy = sinon . spy ( ) ;
146+ chunk = {
147+ removeChunk : removeChunkSpy
148+ } ;
149+ } ) ;
150+ describe ( "and the chunk does not contain this chunk" , function ( ) {
151+ it ( "returns false" , function ( ) {
152+ ChunkInstance . removeParent ( chunk ) . should . eql ( false ) ;
153+ } ) ;
154+ } ) ;
155+ describe ( "and the chunk does contain this module" , function ( ) {
156+ beforeEach ( function ( ) {
157+ ChunkInstance . parents = [ chunk ] ;
158+ } ) ;
159+ it ( "calls module.removeChunk with itself and returns true" , function ( ) {
160+ ChunkInstance . removeParent ( chunk ) . should . eql ( true ) ;
161+ removeChunkSpy . callCount . should . eql ( 1 ) ;
162+ removeChunkSpy . args [ 0 ] [ 0 ] . should . eql ( ChunkInstance ) ;
163+ } ) ;
164+ } ) ;
165+ } ) ;
87166} ) ;
0 commit comments