@@ -8,12 +8,12 @@ import { webpackDevServerFacts } from '../src/webpackDevServerFacts'
8
8
9
9
import { defineDevServerConfig , devServer , startDevServer } from '../'
10
10
11
- const requestSpecFile = ( port : number ) => {
11
+ const requestSpecFile = ( file : string , port : number ) => {
12
12
return new Promise ( ( res ) => {
13
13
const opts = {
14
14
host : 'localhost' ,
15
15
port,
16
- path : '/test/fixtures/foo.spec.js' ,
16
+ path : encodeURI ( file ) ,
17
17
}
18
18
19
19
const callback = ( response : EventEmitter ) => {
@@ -41,13 +41,15 @@ const webpackConfig = {
41
41
42
42
}
43
43
44
- const specs : Cypress . Cypress [ 'spec' ] [ ] = [
45
- {
46
- name : `${ root } /test/fixtures/foo.spec.js` ,
47
- relative : `${ root } /test/fixtures/foo.spec.js` ,
48
- absolute : `${ root } /test/fixtures/foo.spec.js` ,
49
- } ,
50
- ]
44
+ const createSpecs = ( name : string ) : Cypress . Cypress [ 'spec' ] [ ] => {
45
+ return [
46
+ {
47
+ name : `${ root } /test/fixtures/${ name } ` ,
48
+ relative : `${ root } /test/fixtures/${ name } ` ,
49
+ absolute : `${ root } /test/fixtures/${ name } ` ,
50
+ } ,
51
+ ]
52
+ }
51
53
52
54
const config = {
53
55
projectRoot : root ,
@@ -62,12 +64,12 @@ describe('#startDevServer', () => {
62
64
webpackConfig,
63
65
options : {
64
66
config,
65
- specs,
67
+ specs : createSpecs ( 'foo.spec.js' ) ,
66
68
devServerEvents : new EventEmitter ( ) ,
67
69
} ,
68
70
} )
69
71
70
- const response = await requestSpecFile ( port as number )
72
+ const response = await requestSpecFile ( '/test/fixtures/foo.spec.js' , port as number )
71
73
72
74
expect ( response ) . to . eq ( 'const foo = () => {}\n' )
73
75
@@ -76,13 +78,89 @@ describe('#startDevServer', () => {
76
78
} )
77
79
} )
78
80
81
+ it ( 'serves specs in directory with [] chars via a webpack dev server' , async ( ) => {
82
+ const { port, close } = await startDevServer ( {
83
+ webpackConfig,
84
+ options : {
85
+ config,
86
+ specs : createSpecs ( '[foo]/bar.spec.js' ) ,
87
+ devServerEvents : new EventEmitter ( ) ,
88
+ } ,
89
+ } )
90
+
91
+ const response = await requestSpecFile ( '/test/fixtures/[foo]/bar.spec.js' , port as number )
92
+
93
+ expect ( response ) . to . eq ( `it('this is a spec with a path containing []', () => {})\n` )
94
+
95
+ return new Promise ( ( res ) => {
96
+ close ( ( ) => res ( ) )
97
+ } )
98
+ } )
99
+
100
+ it ( 'serves specs in directory with non English chars via a webpack dev server' , async ( ) => {
101
+ const { port, close } = await startDevServer ( {
102
+ webpackConfig,
103
+ options : {
104
+ config,
105
+ specs : createSpecs ( 'サイプレス.spec.js' ) ,
106
+ devServerEvents : new EventEmitter ( ) ,
107
+ } ,
108
+ } )
109
+
110
+ const response = await requestSpecFile ( '/test/fixtures/サイプレス.spec.js' , port as number )
111
+
112
+ expect ( response ) . to . eq ( `it('サイプレス', () => {})\n` )
113
+
114
+ return new Promise ( ( res ) => {
115
+ close ( ( ) => res ( ) )
116
+ } )
117
+ } )
118
+
119
+ it ( 'serves specs in directory with ... in the file name via a webpack dev server' , async ( ) => {
120
+ const { port, close } = await startDevServer ( {
121
+ webpackConfig,
122
+ options : {
123
+ config,
124
+ specs : createSpecs ( '[...bar].spec.js' ) ,
125
+ devServerEvents : new EventEmitter ( ) ,
126
+ } ,
127
+ } )
128
+
129
+ const response = await requestSpecFile ( '/test/fixtures/[...bar].spec.js' , port as number )
130
+
131
+ expect ( response ) . to . eq ( `it('...bar', () => {})\n` )
132
+
133
+ return new Promise ( ( res ) => {
134
+ close ( ( ) => res ( ) )
135
+ } )
136
+ } )
137
+
138
+ it ( 'serves a file with spaces via a webpack dev server' , async ( ) => {
139
+ const { port, close } = await startDevServer ( {
140
+ webpackConfig,
141
+ options : {
142
+ config,
143
+ specs : createSpecs ( 'foo bar.spec.js' ) ,
144
+ devServerEvents : new EventEmitter ( ) ,
145
+ } ,
146
+ } )
147
+
148
+ const response = await requestSpecFile ( '/test/fixtures/foo bar.spec.js' , port as number )
149
+
150
+ expect ( response ) . to . eq ( `it('this is a spec with a path containing a space', () => {})\n` )
151
+
152
+ return new Promise ( ( res ) => {
153
+ close ( ( ) => res ( ) )
154
+ } )
155
+ } )
156
+
79
157
it ( 'emits dev-server:compile:success event on successful compilation' , async ( ) => {
80
158
const devServerEvents = new EventEmitter ( )
81
159
const { close } = await startDevServer ( {
82
160
webpackConfig,
83
161
options : {
84
162
config,
85
- specs,
163
+ specs : createSpecs ( 'foo.spec.js' ) ,
86
164
devServerEvents,
87
165
} ,
88
166
} )
@@ -137,7 +215,7 @@ describe('#startDevServer', () => {
137
215
webpackConfig,
138
216
options : {
139
217
config,
140
- specs,
218
+ specs : createSpecs ( 'foo.spec.js' ) ,
141
219
devServerEvents,
142
220
} ,
143
221
} )
@@ -172,13 +250,13 @@ describe('#startDevServer', () => {
172
250
const { port, close } = await devServer (
173
251
{
174
252
config,
175
- specs,
253
+ specs : createSpecs ( 'foo.spec.js' ) ,
176
254
devServerEvents,
177
255
} ,
178
256
defineDevServerConfig ( { webpackConfig } ) ,
179
257
)
180
258
181
- const response = await requestSpecFile ( port as number )
259
+ const response = await requestSpecFile ( '/test/fixtures/foo.spec.js' , port as number )
182
260
183
261
expect ( response ) . to . eq ( 'const foo = () => {}\n' )
184
262
0 commit comments