@@ -3,6 +3,9 @@ import path from 'path';
3
3
import webpack from 'webpack' ;
4
4
import simpleConfig from './cases/simple/webpack.config' ;
5
5
import multipleInstanceConfig from './cases/multiple-instance/webpack.config' ;
6
+ import jsWithImportConfig from './cases/js-with-import/webpack.config' ;
7
+ import webWorkerConfig from './cases/web-worker/webpack.config' ;
8
+ import inlineWebWorkerConfig from './cases/inline-web-worker/webpack.config' ;
6
9
7
10
describe ( 'HtmlInlineScriptPlugin' , ( ) => {
8
11
it ( 'should build simple webpack config without error' , async ( ) => {
@@ -25,6 +28,11 @@ describe('HtmlInlineScriptPlugin', () => {
25
28
'utf8' ,
26
29
) ;
27
30
expect ( result ) . toBe ( expected ) ;
31
+
32
+ const expectedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/simple/expected/' ) ) ;
33
+ const generatedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/simple/dist/' ) ) ;
34
+ expect ( expectedFileList . sort ( ) ) . toEqual ( generatedFileList . sort ( ) ) ;
35
+
28
36
resolve ( true ) ;
29
37
} ) ;
30
38
} ) ;
@@ -65,6 +73,122 @@ describe('HtmlInlineScriptPlugin', () => {
65
73
) ;
66
74
67
75
expect ( result2 ) . toBe ( expected2 ) ;
76
+
77
+ const expectedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/multiple-instance/expected/' ) ) ;
78
+ const generatedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/multiple-instance/dist/' ) ) ;
79
+ expect ( expectedFileList . sort ( ) ) . toEqual ( generatedFileList . sort ( ) ) ;
80
+
81
+ resolve ( true ) ;
82
+ } ) ;
83
+ } ) ;
84
+
85
+ await webpackPromise ;
86
+ } ) ;
87
+
88
+ it ( 'should build webpack config having JS file with import without error' , async ( ) => {
89
+ const webpackPromise = new Promise ( ( resolve ) => {
90
+ const compiler = webpack ( jsWithImportConfig ) ;
91
+
92
+ compiler . run ( ( error , stats ) => {
93
+ expect ( error ) . toBeNull ( ) ;
94
+
95
+ const statsErrors = stats ?. compilation . errors ;
96
+ expect ( statsErrors ?. length ) . toBe ( 0 ) ;
97
+
98
+ const result1 = fs . readFileSync (
99
+ path . join ( __dirname , 'cases/js-with-import/dist/index.html' ) ,
100
+ 'utf8' ,
101
+ ) ;
102
+
103
+ const expected1 = fs . readFileSync (
104
+ path . join ( __dirname , 'cases/js-with-import/expected/index.html' ) ,
105
+ 'utf8' ,
106
+ ) ;
107
+
108
+ expect ( result1 ) . toBe ( expected1 ) ;
109
+
110
+ const expectedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/js-with-import/expected/' ) ) ;
111
+ const generatedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/js-with-import/dist/' ) ) ;
112
+ expect ( expectedFileList . sort ( ) ) . toEqual ( generatedFileList . sort ( ) ) ;
113
+
114
+ resolve ( true ) ;
115
+ } ) ;
116
+ } ) ;
117
+
118
+ await webpackPromise ;
119
+ } ) ;
120
+
121
+ it ( 'should build webpack config having web worker without error' , async ( ) => {
122
+ const webpackPromise = new Promise ( ( resolve ) => {
123
+ const compiler = webpack ( webWorkerConfig ) ;
124
+
125
+ compiler . run ( ( error , stats ) => {
126
+ expect ( error ) . toBeNull ( ) ;
127
+
128
+ const statsErrors = stats ?. compilation . errors ;
129
+ expect ( statsErrors ?. length ) . toBe ( 0 ) ;
130
+
131
+ const result1 = fs . readFileSync (
132
+ path . join ( __dirname , 'cases/web-worker/dist/index.html' ) ,
133
+ 'utf8' ,
134
+ ) ;
135
+
136
+ const expected1 = fs . readFileSync (
137
+ path . join ( __dirname , 'cases/web-worker/expected/index.html' ) ,
138
+ 'utf8' ,
139
+ ) ;
140
+
141
+ expect ( result1 ) . toBe ( expected1 ) ;
142
+
143
+ const result2 = fs . readFileSync (
144
+ path . join ( __dirname , 'cases/web-worker/dist/test.worker.js' ) ,
145
+ 'utf8' ,
146
+ ) ;
147
+
148
+ const expected2 = fs . readFileSync (
149
+ path . join ( __dirname , 'cases/web-worker/expected/test.worker.js' ) ,
150
+ 'utf8' ,
151
+ ) ;
152
+
153
+ expect ( result2 ) . toBe ( expected2 ) ;
154
+
155
+ const expectedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/web-worker/expected/' ) ) ;
156
+ const generatedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/web-worker/dist/' ) ) ;
157
+ expect ( expectedFileList . sort ( ) ) . toEqual ( generatedFileList . sort ( ) ) ;
158
+
159
+ resolve ( true ) ;
160
+ } ) ;
161
+ } ) ;
162
+
163
+ await webpackPromise ;
164
+ } ) ;
165
+
166
+ it ( 'should build webpack config having inline web worker without error' , async ( ) => {
167
+ const webpackPromise = new Promise ( ( resolve ) => {
168
+ const compiler = webpack ( inlineWebWorkerConfig ) ;
169
+
170
+ compiler . run ( ( error , stats ) => {
171
+ expect ( error ) . toBeNull ( ) ;
172
+
173
+ const statsErrors = stats ?. compilation . errors ;
174
+ expect ( statsErrors ?. length ) . toBe ( 0 ) ;
175
+
176
+ const result1 = fs . readFileSync (
177
+ path . join ( __dirname , 'cases/inline-web-worker/dist/index.html' ) ,
178
+ 'utf8' ,
179
+ ) ;
180
+
181
+ const expected1 = fs . readFileSync (
182
+ path . join ( __dirname , 'cases/inline-web-worker/expected/index.html' ) ,
183
+ 'utf8' ,
184
+ ) ;
185
+
186
+ expect ( result1 ) . toBe ( expected1 ) ;
187
+
188
+ const expectedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/inline-web-worker/expected/' ) ) ;
189
+ const generatedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/inline-web-worker/dist/' ) ) ;
190
+ expect ( expectedFileList . sort ( ) ) . toEqual ( generatedFileList . sort ( ) ) ;
191
+
68
192
resolve ( true ) ;
69
193
} ) ;
70
194
} ) ;
0 commit comments