@@ -17,8 +17,16 @@ describe('"esModule" option', () => {
1717 'lazySingletonStyleTag' ,
1818 'linkTag' ,
1919 ] ;
20+ const commonjsExports = {
21+ styleTag : 'module.exports = content.locals || {}' ,
22+ singletonStyleTag : 'module.exports = content.locals || {}' ,
23+ lazyStyleTag : 'module.exports = exported' ,
24+ lazySingletonStyleTag : 'module.exports = exported' ,
25+ } ;
2026
2127 injectTypes . forEach ( ( injectType ) => {
28+ const commonjsExport = commonjsExports [ injectType ] ;
29+
2230 it ( `should work when not specified and when the "injectType" option is "${ injectType } "` , async ( ) => {
2331 const entry = getEntryByInjectType ( 'simple.js' , injectType ) ;
2432 const compiler = getCompiler ( entry , { injectType } ) ;
@@ -37,8 +45,12 @@ describe('"esModule" option', () => {
3745 const compiler = getCompiler ( entry , { injectType, esModule : true } ) ;
3846 const stats = await compile ( compiler ) ;
3947
40- runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom ) => {
48+ runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom , bundle ) => {
4149 expect ( dom . serialize ( ) ) . toMatchSnapshot ( 'DOM' ) ;
50+
51+ if ( commonjsExport ) {
52+ expect ( bundle ) . not . toEqual ( expect . stringContaining ( commonjsExport ) ) ;
53+ }
4254 } ) ;
4355
4456 expect ( getWarnings ( stats ) ) . toMatchSnapshot ( 'warnings' ) ;
@@ -74,8 +86,12 @@ describe('"esModule" option', () => {
7486 ) ;
7587 const stats = await compile ( compiler ) ;
7688
77- runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom ) => {
89+ runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom , bundle ) => {
7890 expect ( dom . serialize ( ) ) . toMatchSnapshot ( 'DOM' ) ;
91+
92+ if ( commonjsExport ) {
93+ expect ( bundle ) . not . toEqual ( expect . stringContaining ( commonjsExport ) ) ;
94+ }
7995 } ) ;
8096
8197 expect ( getWarnings ( stats ) ) . toMatchSnapshot ( 'warnings' ) ;
@@ -117,8 +133,12 @@ describe('"esModule" option', () => {
117133 ) ;
118134 const stats = await compile ( compiler ) ;
119135
120- runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom ) => {
136+ runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom , bundle ) => {
121137 expect ( dom . serialize ( ) ) . toMatchSnapshot ( 'DOM' ) ;
138+
139+ if ( commonjsExport ) {
140+ expect ( bundle ) . not . toEqual ( expect . stringContaining ( commonjsExport ) ) ;
141+ }
122142 } ) ;
123143
124144 expect ( getWarnings ( stats ) ) . toMatchSnapshot ( 'warnings' ) ;
@@ -130,8 +150,12 @@ describe('"esModule" option', () => {
130150 const compiler = getCompiler ( entry , { injectType, esModule : false } ) ;
131151 const stats = await compile ( compiler ) ;
132152
133- runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom ) => {
153+ runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom , bundle ) => {
134154 expect ( dom . serialize ( ) ) . toMatchSnapshot ( 'DOM' ) ;
155+
156+ if ( commonjsExport ) {
157+ expect ( bundle ) . toEqual ( expect . stringContaining ( commonjsExport ) ) ;
158+ }
135159 } ) ;
136160
137161 expect ( getWarnings ( stats ) ) . toMatchSnapshot ( 'warnings' ) ;
@@ -167,8 +191,12 @@ describe('"esModule" option', () => {
167191 ) ;
168192 const stats = await compile ( compiler ) ;
169193
170- runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom ) => {
194+ runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom , bundle ) => {
171195 expect ( dom . serialize ( ) ) . toMatchSnapshot ( 'DOM' ) ;
196+
197+ if ( commonjsExport ) {
198+ expect ( bundle ) . toEqual ( expect . stringContaining ( commonjsExport ) ) ;
199+ }
172200 } ) ;
173201
174202 expect ( getWarnings ( stats ) ) . toMatchSnapshot ( 'warnings' ) ;
@@ -210,8 +238,12 @@ describe('"esModule" option', () => {
210238 ) ;
211239 const stats = await compile ( compiler ) ;
212240
213- runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom ) => {
241+ runInJsDom ( 'main.bundle.js' , compiler , stats , ( dom , bundle ) => {
214242 expect ( dom . serialize ( ) ) . toMatchSnapshot ( 'DOM' ) ;
243+
244+ if ( commonjsExport ) {
245+ expect ( bundle ) . toEqual ( expect . stringContaining ( commonjsExport ) ) ;
246+ }
215247 } ) ;
216248
217249 expect ( getWarnings ( stats ) ) . toMatchSnapshot ( 'warnings' ) ;
0 commit comments