@@ -7,51 +7,48 @@ import {
7
7
untilMatches ,
8
8
sleep ,
9
9
getColor ,
10
- editFile ,
11
- addFile ,
12
- removeFile ,
13
- editViteConfig ,
14
10
browserLogs ,
15
- waitForBuildWatchAndPageReload
11
+ e2eServer
16
12
} from '~utils' ;
13
+ import { describe , test , expect } from 'vitest' ;
17
14
18
- test ( 'should render App' , async ( ) => {
19
- expect ( await getText ( '#app-header' ) ) . toBe ( 'Test-App' ) ;
20
- } ) ;
15
+ describe . runIf ( isBuildWatch ) ( 'build-watch' , ( ) => {
16
+ test ( 'should render App' , async ( ) => {
17
+ expect ( await getText ( '#app-header' ) ) . toBe ( 'Test-App' ) ;
18
+ } ) ;
21
19
22
- test ( 'should render static import' , async ( ) => {
23
- expect ( await getText ( '#static-import .label' ) ) . toBe ( 'static-import' ) ;
24
- } ) ;
20
+ test ( 'should render static import' , async ( ) => {
21
+ expect ( await getText ( '#static-import .label' ) ) . toBe ( 'static-import' ) ;
22
+ } ) ;
25
23
26
- test ( 'should render dependency import' , async ( ) => {
27
- expect ( await getText ( '#dependency-import .label' ) ) . toBe ( 'dependency-import' ) ;
28
- } ) ;
24
+ test ( 'should render dependency import' , async ( ) => {
25
+ expect ( await getText ( '#dependency-import .label' ) ) . toBe ( 'dependency-import' ) ;
26
+ } ) ;
29
27
30
- test ( 'should render dynamic import' , async ( ) => {
31
- expect ( await getEl ( '#dynamic-import' ) ) . toBe ( null ) ;
32
- const dynamicImportButton = await getEl ( '#button-import-dynamic' ) ;
33
- expect ( dynamicImportButton ) . toBeDefined ( ) ;
34
- await dynamicImportButton . click ( ) ;
35
- await untilMatches (
36
- ( ) => getText ( '#dynamic-import .label' ) ,
37
- 'dynamic-import' ,
38
- 'dynamic import loaded after click'
39
- ) ;
40
- } ) ;
28
+ test ( 'should render dynamic import' , async ( ) => {
29
+ expect ( await getEl ( '#dynamic-import' ) ) . toBe ( null ) ;
30
+ const dynamicImportButton = await getEl ( '#button-import-dynamic' ) ;
31
+ expect ( dynamicImportButton ) . toBeDefined ( ) ;
32
+ await dynamicImportButton . click ( ) ;
33
+ await untilMatches (
34
+ ( ) => getText ( '#dynamic-import .label' ) ,
35
+ 'dynamic-import' ,
36
+ 'dynamic import loaded after click'
37
+ ) ;
38
+ } ) ;
41
39
42
- test ( 'should not have failed requests' , async ( ) => {
43
- browserLogs . forEach ( ( msg ) => {
44
- expect ( msg ) . not . toMatch ( '404' ) ;
40
+ test ( 'should not have failed requests' , async ( ) => {
41
+ browserLogs . forEach ( ( msg ) => {
42
+ expect ( msg ) . not . toMatch ( '404' ) ;
43
+ } ) ;
45
44
} ) ;
46
- } ) ;
47
45
48
- test ( 'should respect transforms' , async ( ) => {
49
- expect ( await getText ( '#js-transform' ) ) . toBe ( 'Hello world' ) ;
50
- expect ( await getColor ( '#css-transform' ) ) . toBe ( 'red' ) ;
51
- } ) ;
46
+ test ( 'should respect transforms' , async ( ) => {
47
+ expect ( await getText ( '#js-transform' ) ) . toBe ( 'Hello world' ) ;
48
+ expect ( await getColor ( '#css-transform' ) ) . toBe ( 'red' ) ;
49
+ } ) ;
52
50
53
- if ( isBuildWatch ) {
54
- describe ( 'build --watch' , ( ) => {
51
+ describe ( 'edit files' , ( ) => {
55
52
const updateHmrTest = editFileAndWaitForBuildWatchComplete . bind (
56
53
null ,
57
54
'src/components/HmrTest.svelte'
@@ -90,6 +87,7 @@ if (isBuildWatch) {
90
87
// color should have changed
91
88
expect ( await getColor ( '#hmr-test-1 .label' ) ) . toBe ( 'green' ) ;
92
89
expect ( await getColor ( '#hmr-test-2 .label' ) ) . toBe ( 'green' ) ;
90
+ expect ( e2eServer . logs . watch . err , 'error log of `build --watch` is not empty' ) . toEqual ( [ ] ) ;
93
91
} ) ;
94
92
95
93
test ( 'should apply js change in HmrTest.svelte ' , async ( ) => {
@@ -99,6 +97,7 @@ if (isBuildWatch) {
99
97
) ;
100
98
expect ( await getText ( '#hmr-test-1 .label' ) ) . toBe ( 'hmr-test-updated' ) ;
101
99
expect ( await getText ( '#hmr-test-2 .label' ) ) . toBe ( 'hmr-test-updated' ) ;
100
+ expect ( e2eServer . logs . watch . err , 'error log of `build --watch` is not empty' ) . toEqual ( [ ] ) ;
102
101
} ) ;
103
102
104
103
test ( 'should reset state of external store used by HmrTest.svelte when editing App.svelte' , async ( ) => {
@@ -114,6 +113,7 @@ if (isBuildWatch) {
114
113
expect ( await getText ( '#hmr-test-2 .counter' ) ) . toBe ( '0' ) ;
115
114
// a third instance has been added
116
115
expect ( await getText ( '#hmr-test-3 .counter' ) ) . toBe ( '0' ) ;
116
+ expect ( e2eServer . logs . watch . err , 'error log of `build --watch` is not empty' ) . toEqual ( [ ] ) ;
117
117
} ) ;
118
118
119
119
test ( 'should reset state of store when editing hmr-stores.js' , async ( ) => {
@@ -124,6 +124,7 @@ if (isBuildWatch) {
124
124
await updateStore ( ( content ) => `${ content } \n/*trigger change*/\n` ) ;
125
125
// counter state is reset
126
126
expect ( await getText ( '#hmr-test-2 .counter' ) ) . toBe ( '0' ) ;
127
+ expect ( e2eServer . logs . watch . err , 'error log of `build --watch` is not empty' ) . toEqual ( [ ] ) ;
127
128
} ) ;
128
129
129
130
test ( 'should work when editing script context="module"' , async ( ) => {
@@ -134,79 +135,9 @@ if (isBuildWatch) {
134
135
await updateModuleContext ( ( content ) => content . replace ( 'y = 1' , 'y = 2' ) ) ;
135
136
expect ( await getText ( '#hmr-with-context' ) ) . toContain ( 'x=0 y=2 slot=2' ) ;
136
137
expect ( await getText ( '#hmr-without-context' ) ) . toContain ( 'x=0 y=2 slot=' ) ;
137
- expect ( hmrCount ( 'UsingNamed.svelte' ) , 'updates for UsingNamed.svelte' ) . toBe ( 1 ) ;
138
+ expect ( hmrCount ( 'UsingNamed.svelte' ) , 'updates for UsingNamed.svelte' ) . toBe ( 0 ) ;
138
139
expect ( hmrCount ( 'UsingDefault.svelte' ) , 'updates for UsingDefault.svelte' ) . toBe ( 0 ) ;
139
- } ) ;
140
-
141
- test ( 'should work with emitCss: false in vite config' , async ( ) => {
142
- await editViteConfig ( ( c ) => c . replace ( 'svelte()' , 'svelte({emitCss:false})' ) ) ;
143
- expect ( await getText ( '#hmr-test-1 .counter' ) ) . toBe ( '0' ) ;
144
- expect ( await getColor ( '#hmr-test-1 .label' ) ) . toBe ( 'green' ) ;
145
- await ( await getEl ( '#hmr-test-1 .increment' ) ) . click ( ) ;
146
- await sleep ( 50 ) ;
147
- expect ( await getText ( '#hmr-test-1 .counter' ) ) . toBe ( '1' ) ;
148
- await updateHmrTest ( ( content ) => content . replace ( 'color: green' , 'color: red' ) ) ;
149
- expect ( await getColor ( '#hmr-test-1 .label' ) ) . toBe ( 'red' ) ;
150
- // counter value is reset
151
- expect ( await getText ( '#hmr-test-1 .counter' ) ) . toBe ( '0' ) ;
152
- } ) ;
153
-
154
- test ( 'should work with emitCss: false in svelte config' , async ( ) => {
155
- addFile ( 'svelte.config.js' , 'export default {vitePlugin:{emitCss:false}}' ) ;
156
- await waitForBuildWatchAndPageReload ( ) ;
157
- expect ( await getColor ( '#hmr-test-1 .label' ) ) . toBe ( 'red' ) ;
158
- removeFile ( 'svelte.config.js' ) ;
159
- await waitForBuildWatchAndPageReload ( ) ;
160
- } ) ;
161
-
162
- test ( 'should detect changes in svelte config and rebuild' , async ( ) => {
163
- const injectPreprocessor = ( { content, filename } ) => {
164
- if ( filename && filename . includes ( 'App.svelte' ) ) {
165
- return {
166
- code : content . replace (
167
- '<!-- HMR-TEMPLATE-INJECT -->' ,
168
- '<div id="preprocess-inject">Injected</div>\n<!-- HMR-TEMPLATE-INJECT -->'
169
- )
170
- } ;
171
- }
172
- } ;
173
- await addFile (
174
- 'svelte.config.js' ,
175
- `export default {
176
- preprocess:[{markup:${ injectPreprocessor . toString ( ) } }]};`
177
- ) ;
178
- await waitForBuildWatchAndPageReload ( ) ;
179
- expect ( await getText ( '#preprocess-inject' ) ) . toBe ( 'Injected' ) ;
180
- expect ( await getText ( '#hmr-test-1 .counter' ) ) . toBe ( '0' ) ;
181
- expect ( await getColor ( '#hmr-test-1 .label' ) ) . toBe ( 'red' ) ;
182
- await ( await getEl ( '#hmr-test-1 .increment' ) ) . click ( ) ;
183
- await sleep ( 50 ) ;
184
- expect ( await getText ( '#hmr-test-1 .counter' ) ) . toBe ( '1' ) ;
185
- await updateHmrTest ( ( content ) => content . replace ( 'color: red' , 'color: green' ) ) ;
186
- expect ( await getColor ( '#hmr-test-1 .label' ) ) . toBe ( 'green' ) ;
187
- expect ( await getText ( '#hmr-test-1 .counter' ) ) . toBe ( '0' ) ;
188
- await editFile ( 'svelte.config.js' , ( content ) =>
189
- content
190
- . replace ( 'preprocess-inject' , 'preprocess-inject-2' )
191
- . replace ( 'Injected' , 'Injected 2' )
192
- ) ;
193
- await waitForBuildWatchAndPageReload ( ) ;
194
- expect ( await getText ( '#preprocess-inject-2' ) ) . toBe ( 'Injected 2' ) ;
195
- expect ( await getEl ( '#preprocess-inject' ) ) . toBe ( null ) ;
196
- expect ( await getColor ( '#hmr-test-1 .label' ) ) . toBe ( 'green' ) ;
197
- expect ( await getText ( '#hmr-test-1 .counter' ) ) . toBe ( '0' ) ;
198
- await ( await getEl ( '#hmr-test-1 .increment' ) ) . click ( ) ;
199
- await sleep ( 50 ) ;
200
- expect ( await getText ( '#hmr-test-1 .counter' ) ) . toBe ( '1' ) ;
201
- await updateHmrTest ( ( content ) => content . replace ( 'color: green' , 'color: red' ) ) ;
202
- expect ( await getColor ( '#hmr-test-1 .label' ) ) . toBe ( 'red' ) ;
203
- expect ( await getText ( '#hmr-test-1 .counter' ) ) . toBe ( '0' ) ;
204
- await removeFile ( 'svelte.config.js' ) ;
205
- await waitForBuildWatchAndPageReload ( ) ;
206
- expect ( await getEl ( '#preprocess-inject-2' ) ) . toBe ( null ) ;
207
- expect ( await getEl ( '#preprocess-inject' ) ) . toBe ( null ) ;
208
- expect ( await getColor ( '#hmr-test-1 .label' ) ) . toBe ( 'red' ) ;
209
- expect ( await getText ( '#hmr-test-1 .counter' ) ) . toBe ( '0' ) ;
140
+ expect ( e2eServer . logs . watch . err , 'error log of `build --watch` is not empty' ) . toEqual ( [ ] ) ;
210
141
} ) ;
211
142
} ) ;
212
- }
143
+ } ) ;
0 commit comments