Skip to content

Commit 228e056

Browse files
authored
test: remove runInBuild flag from withRetry and untilUpdated helpers (#18699)
1 parent 51d55d3 commit 228e056

File tree

20 files changed

+115
-182
lines changed

20 files changed

+115
-182
lines changed

playground/alias/__tests__/alias.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from 'vitest'
2-
import { editFile, getColor, page, untilUpdated } from '~utils'
2+
import { editFile, getColor, isBuild, page, untilUpdated } from '~utils'
33

44
test('fs', async () => {
55
expect(await page.textContent('.fs')).toMatch('[success] alias to fs path')
@@ -29,6 +29,7 @@ test('js via script src', async () => {
2929

3030
test('css via link', async () => {
3131
expect(await getColor('body')).toBe('grey')
32+
if (isBuild) return
3233
editFile('dir/test.css', (code) => code.replace('grey', 'red'))
3334
await untilUpdated(() => getColor('body'), 'red')
3435
})

playground/assets/__tests__/assets.spec.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ test.runIf(isBuild)('manifest', async () => {
552552

553553
describe.runIf(isBuild)('css and assets in css in build watch', () => {
554554
test('css will not be lost and css does not contain undefined', async () => {
555-
editFile('index.html', (code) => code.replace('Assets', 'assets'), true)
555+
editFile('index.html', (code) => code.replace('Assets', 'assets'))
556556
await notifyRebuildComplete(watcher)
557557
const cssFile = findAssetFile(/index-[-\w]+\.css$/, 'foo')
558558
expect(cssFile).not.toBe('')
@@ -561,15 +561,15 @@ describe.runIf(isBuild)('css and assets in css in build watch', () => {
561561

562562
test('import module.css', async () => {
563563
expect(await getColor('#foo')).toBe('red')
564-
editFile('css/foo.module.css', (code) => code.replace('red', 'blue'), true)
564+
editFile('css/foo.module.css', (code) => code.replace('red', 'blue'))
565565
await notifyRebuildComplete(watcher)
566566
await page.reload()
567567
expect(await getColor('#foo')).toBe('blue')
568568
})
569569

570570
test('import with raw query', async () => {
571571
expect(await page.textContent('.raw-query')).toBe('foo')
572-
editFile('static/foo.txt', (code) => code.replace('foo', 'zoo'), true)
572+
editFile('static/foo.txt', (code) => code.replace('foo', 'zoo'))
573573
await notifyRebuildComplete(watcher)
574574
await page.reload()
575575
expect(await page.textContent('.raw-query')).toBe('zoo')
@@ -585,11 +585,7 @@ if (!isBuild) {
585585
test('@import in html style tag hmr', async () => {
586586
await untilUpdated(() => getColor('.import-css'), 'rgb(0, 136, 255)')
587587
const loadPromise = page.waitForEvent('load')
588-
editFile(
589-
'./css/import.css',
590-
(code) => code.replace('#0088ff', '#00ff88'),
591-
true,
592-
)
588+
editFile('./css/import.css', (code) => code.replace('#0088ff', '#00ff88'))
593589
await loadPromise
594590
await untilUpdated(() => getColor('.import-css'), 'rgb(0, 255, 136)')
595591
})

playground/css-lightningcss/__tests__/css-lightningcss.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ test('linked css', async () => {
1919
expect(await getColor(linked)).toBe('blue')
2020
expect(await getColor(atImport)).toBe('red')
2121

22+
if (isBuild) return
2223
editFile('linked.css', (code) => code.replace('color: blue', 'color: red'))
2324
await untilUpdated(() => getColor(linked), 'red')
2425

@@ -35,6 +36,7 @@ test('css import from js', async () => {
3536
expect(await getColor(imported)).toBe('green')
3637
expect(await getColor(atImport)).toBe('purple')
3738

39+
if (isBuild) return
3840
editFile('imported.css', (code) => code.replace('color: green', 'color: red'))
3941
await untilUpdated(() => getColor(imported), 'red')
4042

@@ -50,6 +52,7 @@ test('css modules', async () => {
5052

5153
expect(await imported.getAttribute('class')).toMatch(/\w{6}_apply-color/)
5254

55+
if (isBuild) return
5356
editFile('mod.module.css', (code) =>
5457
code.replace('color: turquoise', 'color: red'),
5558
)

playground/css/__tests__/css.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ test('linked css', async () => {
3030
expect(await getColor(linked)).toBe('blue')
3131
expect(await getColor(atImport)).toBe('red')
3232

33+
if (isBuild) return
34+
3335
editFile('linked.css', (code) => code.replace('color: blue', 'color: red'))
3436
await untilUpdated(() => getColor(linked), 'red')
3537

@@ -46,6 +48,8 @@ test('css import from js', async () => {
4648
expect(await getColor(imported)).toBe('green')
4749
expect(await getColor(atImport)).toBe('purple')
4850

51+
if (isBuild) return
52+
4953
editFile('imported.css', (code) => code.replace('color: green', 'color: red'))
5054
await untilUpdated(() => getColor(imported), 'red')
5155

@@ -65,6 +69,8 @@ test('postcss config', async () => {
6569
const imported = await page.$('.postcss .nesting')
6670
expect(await getColor(imported)).toBe('pink')
6771

72+
if (isBuild) return
73+
6874
editFile('imported.css', (code) => code.replace('color: pink', 'color: red'))
6975
await untilUpdated(() => getColor(imported), 'red')
7076
})
@@ -96,6 +102,8 @@ test('sass', async () => {
96102
expect(await getColor(await page.$('.sass-file-absolute'))).toBe('orange')
97103
expect(await getColor(await page.$('.sass-dir-index'))).toBe('orange')
98104

105+
if (isBuild) return
106+
99107
editFile('sass.scss', (code) =>
100108
code.replace('color: $injectedColor', 'color: red'),
101109
)
@@ -131,6 +139,8 @@ test('less', async () => {
131139
isBuild ? /ok-[-\w]+\.png/ : `${viteTestUrl}/ok.png`,
132140
)
133141

142+
if (isBuild) return
143+
134144
editFile('less.less', (code) => code.replace('@color: blue', '@color: red'))
135145
await untilUpdated(() => getColor(imported), 'red')
136146

@@ -162,6 +172,8 @@ test('stylus', async () => {
162172
expect(await getColor(optionsDefineVar)).toBe('rgb(51, 197, 255)')
163173
expect(await getColor(optionsDefineFunc)).toBe('rgb(255, 0, 98)')
164174

175+
if (isBuild) return
176+
165177
editFile('stylus.styl', (code) =>
166178
code.replace('$color ?= blue', '$color ?= red'),
167179
)
@@ -183,6 +195,8 @@ test('css modules', async () => {
183195
/.mod-module__apply-color___[\w-]{5}/,
184196
)
185197

198+
if (isBuild) return
199+
186200
editFile('mod.module.css', (code) =>
187201
code.replace('color: turquoise', 'color: red'),
188202
)
@@ -259,6 +273,8 @@ test('css modules w/ sass', async () => {
259273
/.mod-module__apply-color___[\w-]{5}/,
260274
)
261275

276+
if (isBuild) return
277+
262278
editFile('mod.module.scss', (code) =>
263279
code.replace('color: orangered', 'color: blue'),
264280
)
@@ -514,6 +530,8 @@ test('sugarss', async () => {
514530
isBuild ? /base64/ : '/nested/icon.png',
515531
)
516532

533+
if (isBuild) return
534+
517535
editFile('sugarss.sss', (code) => code.replace('color: blue', 'color: coral'))
518536
await untilUpdated(() => getColor(imported), 'coral')
519537

playground/dynamic-import/__tests__/dynamic-import.spec.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import {
1111

1212
test('should load literal dynamic import', async () => {
1313
await page.click('.baz')
14-
await untilUpdated(() => page.textContent('.view'), 'Baz view', true)
14+
await untilUpdated(() => page.textContent('.view'), 'Baz view')
1515
})
1616

1717
test('should load full dynamic import from public', async () => {
1818
await page.click('.qux')
19-
await untilUpdated(() => page.textContent('.view'), 'Qux view', true)
19+
await untilUpdated(() => page.textContent('.view'), 'Qux view')
2020
// No warning should be logged as we are using @vite-ignore
2121
expect(
2222
serverLogs.some((log) => log.includes('cannot be analyzed by vite')),
@@ -25,38 +25,38 @@ test('should load full dynamic import from public', async () => {
2525

2626
test('should load data URL of `blob:`', async () => {
2727
await page.click('.issue-2658-1')
28-
await untilUpdated(() => page.textContent('.view'), 'blob', true)
28+
await untilUpdated(() => page.textContent('.view'), 'blob')
2929
})
3030

3131
test('should load data URL of `data:`', async () => {
3232
await page.click('.issue-2658-2')
33-
await untilUpdated(() => page.textContent('.view'), 'data', true)
33+
await untilUpdated(() => page.textContent('.view'), 'data')
3434
})
3535

3636
test('should have same reference on static and dynamic js import, .mxd', async () => {
3737
await page.click('.mxd')
38-
await untilUpdated(() => page.textContent('.view'), 'true', true)
38+
await untilUpdated(() => page.textContent('.view'), 'true')
3939
})
4040

4141
// in this case, it is not possible to detect the correct module
4242
test('should have same reference on static and dynamic js import, .mxd2', async () => {
4343
await page.click('.mxd2')
44-
await untilUpdated(() => page.textContent('.view'), 'false', true)
44+
await untilUpdated(() => page.textContent('.view'), 'false')
4545
})
4646

4747
test('should have same reference on static and dynamic js import, .mxdjson', async () => {
4848
await page.click('.mxdjson')
49-
await untilUpdated(() => page.textContent('.view'), 'true', true)
49+
await untilUpdated(() => page.textContent('.view'), 'true')
5050
})
5151

5252
// since this test has a timeout, it should be put last so that it
5353
// does not bleed on the last
5454
test('should load dynamic import with vars', async () => {
5555
await page.click('.foo')
56-
await untilUpdated(() => page.textContent('.view'), 'Foo view', true)
56+
await untilUpdated(() => page.textContent('.view'), 'Foo view')
5757

5858
await page.click('.bar')
59-
await untilUpdated(() => page.textContent('.view'), 'Bar view', true)
59+
await untilUpdated(() => page.textContent('.view'), 'Bar view')
6060
})
6161

6262
// dynamic import css
@@ -65,23 +65,20 @@ test('should load dynamic import with css', async () => {
6565
await untilUpdated(
6666
() => page.$eval('.view', (node) => window.getComputedStyle(node).color),
6767
'rgb(255, 0, 0)',
68-
true,
6968
)
7069
})
7170

7271
test('should load dynamic import with vars', async () => {
7372
await untilUpdated(
7473
() => page.textContent('.dynamic-import-with-vars'),
7574
'hello',
76-
true,
7775
)
7876
})
7977

8078
test('should load dynamic import with vars ignored', async () => {
8179
await untilUpdated(
8280
() => page.textContent('.dynamic-import-with-vars-ignored'),
8381
'hello',
84-
true,
8582
)
8683
// No warning should be logged as we are using @vite-ignore
8784
expect(
@@ -95,76 +92,67 @@ test('should load dynamic import with double slash ignored', async () => {
9592
await untilUpdated(
9693
() => page.textContent('.dynamic-import-with-double-slash-ignored'),
9794
'hello',
98-
true,
9995
)
10096
})
10197

10298
test('should load dynamic import with vars multiline', async () => {
10399
await untilUpdated(
104100
() => page.textContent('.dynamic-import-with-vars-multiline'),
105101
'hello',
106-
true,
107102
)
108103
})
109104

110105
test('should load dynamic import with vars alias', async () => {
111106
await untilUpdated(
112107
() => page.textContent('.dynamic-import-with-vars-alias'),
113108
'hi',
114-
true,
115109
)
116110
})
117111

118112
test('should load dynamic import with vars raw', async () => {
119113
await untilUpdated(
120114
() => page.textContent('.dynamic-import-with-vars-raw'),
121115
'export function hello()',
122-
true,
123116
)
124117
})
125118

126119
test('should load dynamic import with vars url', async () => {
127120
await untilUpdated(
128121
() => page.textContent('.dynamic-import-with-vars-url'),
129122
isBuild ? 'data:text/javascript' : '/alias/url.js',
130-
true,
131123
)
132124
})
133125

134126
test('should load dynamic import with vars worker', async () => {
135127
await untilUpdated(
136128
() => page.textContent('.dynamic-import-with-vars-worker'),
137129
'load worker',
138-
true,
139130
)
140131
})
141132

142133
test('should load dynamic import with css in package', async () => {
143134
await page.click('.pkg-css')
144-
await untilUpdated(() => getColor('.pkg-css'), 'blue', true)
135+
await untilUpdated(() => getColor('.pkg-css'), 'blue')
145136
})
146137

147138
test('should work with load ../ and itself directory', async () => {
148139
await untilUpdated(
149140
() => page.textContent('.dynamic-import-self'),
150141
'dynamic-import-self-content',
151-
true,
152142
)
153143
})
154144

155145
test('should work with load ../ and contain itself directory', async () => {
156146
await untilUpdated(
157147
() => page.textContent('.dynamic-import-nested-self'),
158148
'dynamic-import-nested-self-content',
159-
true,
160149
)
161150
})
162151

163152
test('should work a load path that contains parentheses.', async () => {
164153
await untilUpdated(
165154
() => page.textContent('.dynamic-import-with-vars-contains-parenthesis'),
166155
'dynamic-import-with-vars-contains-parenthesis',
167-
true,
168156
)
169157
})
170158

playground/legacy/__tests__/legacy.spec.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,31 @@ import {
1010
} from '~utils'
1111

1212
test('should load the worker', async () => {
13-
await untilUpdated(() => page.textContent('.worker-message'), 'module', true)
13+
await untilUpdated(() => page.textContent('.worker-message'), 'module')
1414
})
1515

1616
test('should work', async () => {
17-
await untilUpdated(() => page.textContent('#app'), 'Hello', true)
17+
await untilUpdated(() => page.textContent('#app'), 'Hello')
1818
})
1919

2020
test('import.meta.env.LEGACY', async () => {
21-
await untilUpdated(
22-
() => page.textContent('#env'),
23-
isBuild ? 'true' : 'false',
24-
true,
25-
)
26-
await untilUpdated(() => page.textContent('#env-equal'), 'true', true)
21+
await untilUpdated(() => page.textContent('#env'), isBuild ? 'true' : 'false')
22+
await untilUpdated(() => page.textContent('#env-equal'), 'true')
2723
})
2824

2925
// https://github.com/vitejs/vite/issues/3400
3026
test('transpiles down iterators correctly', async () => {
31-
await untilUpdated(() => page.textContent('#iterators'), 'hello', true)
27+
await untilUpdated(() => page.textContent('#iterators'), 'hello')
3228
})
3329

3430
test('async generator', async () => {
35-
await untilUpdated(
36-
() => page.textContent('#async-generator'),
37-
'[0,1,2]',
38-
true,
39-
)
31+
await untilUpdated(() => page.textContent('#async-generator'), '[0,1,2]')
4032
})
4133

4234
test('wraps with iife', async () => {
4335
await untilUpdated(
4436
() => page.textContent('#babel-helpers'),
4537
'exposed babel helpers: false',
46-
true,
4738
)
4839
})
4940

@@ -69,7 +60,6 @@ test('generates assets', async () => {
6960
'immutable-chunk-legacy: text/html',
7061
'polyfills-legacy: text/html',
7162
].join('\n'),
72-
true,
7363
)
7464
})
7565

@@ -80,7 +70,7 @@ test('correctly emits styles', async () => {
8070
// dynamic import css
8171
test('should load dynamic import with css', async () => {
8272
await page.click('#dynamic-css-button')
83-
await untilUpdated(() => getColor('#dynamic-css'), 'red', true)
73+
await untilUpdated(() => getColor('#dynamic-css'), 'red')
8474
})
8575

8676
test('asset url', async () => {

playground/legacy/__tests__/no-polyfills-no-systemjs/legacy-no-polyfills-no-systemjs.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ test.runIf(isBuild)('includes only a single script tag', async () => {
77
await untilUpdated(
88
() => page.getAttribute('#vite-legacy-entry', 'data-src'),
99
/.\/assets\/index-legacy-(.+)\.js/,
10-
true,
1110
)
1211

1312
expect(await page.locator('script').count()).toBe(1)

0 commit comments

Comments
 (0)