1
1
"use strict" ;
2
2
3
+ const path = require ( "path" ) ;
3
4
const webpack = require ( "webpack" ) ;
4
5
const Server = require ( "../../lib/Server" ) ;
5
6
const config = require ( "../fixtures/client-config/webpack.config" ) ;
6
7
const workerConfig = require ( "../fixtures/worker-config/webpack.config" ) ;
8
+ const workerConfigDevServerFalse = require ( "../fixtures/worker-config-dev-server-false/webpack.config" ) ;
7
9
const runBrowser = require ( "../helpers/run-browser" ) ;
8
10
const port = require ( "../ports-map" ) . target ;
9
11
12
+ const sortByTerm = ( data , term ) =>
13
+ data . sort ( ( a , b ) => ( a . indexOf ( term ) < b . indexOf ( term ) ? - 1 : 1 ) ) ;
14
+
10
15
describe ( "target" , ( ) => {
11
16
const targets = [
12
17
false ,
@@ -35,10 +40,7 @@ describe("target", () => {
35
40
}
36
41
: { } ) ,
37
42
} ) ;
38
- const devServerOptions = {
39
- port,
40
- } ;
41
- const server = new Server ( devServerOptions , compiler ) ;
43
+ const server = new Server ( { port } , compiler ) ;
42
44
43
45
await server . start ( ) ;
44
46
@@ -93,10 +95,58 @@ describe("target", () => {
93
95
94
96
it ( "should work using multi compiler mode with `web` and `webworker` targets" , async ( ) => {
95
97
const compiler = webpack ( workerConfig ) ;
96
- const devServerOptions = {
97
- port,
98
- } ;
99
- const server = new Server ( devServerOptions , compiler ) ;
98
+ const server = new Server ( { port } , compiler ) ;
99
+
100
+ await server . start ( ) ;
101
+
102
+ const { page, browser } = await runBrowser ( ) ;
103
+
104
+ try {
105
+ const pageErrors = [ ] ;
106
+ const consoleMessages = [ ] ;
107
+
108
+ page
109
+ . on ( "console" , ( message ) => {
110
+ consoleMessages . push ( message ) ;
111
+ } )
112
+ . on ( "pageerror" , ( error ) => {
113
+ pageErrors . push ( error ) ;
114
+ } ) ;
115
+
116
+ await page . goto ( `http://127.0.0.1:${ port } /` , {
117
+ waitUntil : "networkidle0" ,
118
+ } ) ;
119
+
120
+ expect (
121
+ sortByTerm (
122
+ consoleMessages . map ( ( message ) => message . text ( ) ) ,
123
+ "Worker said:" ,
124
+ ) ,
125
+ ) . toMatchSnapshot ( "console messages" ) ;
126
+
127
+ expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
128
+ } catch ( error ) {
129
+ throw error ;
130
+ } finally {
131
+ await browser . close ( ) ;
132
+ await server . stop ( ) ;
133
+ }
134
+ } ) ;
135
+
136
+ it ( "should work using multi compiler mode with `web` and `webworker` targets with `devServer: false`" , async ( ) => {
137
+ const compiler = webpack ( workerConfigDevServerFalse ) ;
138
+ const server = new Server (
139
+ {
140
+ port,
141
+ static : {
142
+ directory : path . resolve (
143
+ __dirname ,
144
+ "../fixtures/worker-config-dev-server-false/public/" ,
145
+ ) ,
146
+ } ,
147
+ } ,
148
+ compiler ,
149
+ ) ;
100
150
101
151
await server . start ( ) ;
102
152
@@ -118,9 +168,12 @@ describe("target", () => {
118
168
waitUntil : "networkidle0" ,
119
169
} ) ;
120
170
121
- expect ( consoleMessages . map ( ( message ) => message . text ( ) ) ) . toMatchSnapshot (
122
- "console messages" ,
123
- ) ;
171
+ expect (
172
+ sortByTerm (
173
+ consoleMessages . map ( ( message ) => message . text ( ) ) ,
174
+ "Worker said:" ,
175
+ ) ,
176
+ ) . toMatchSnapshot ( "console messages" ) ;
124
177
125
178
expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
126
179
} catch ( error ) {
0 commit comments