Skip to content

Commit

Permalink
test: remove runInBuild flag from withRetry and untilUpdated he…
Browse files Browse the repository at this point in the history
…lpers (#18699)
  • Loading branch information
hi-ogawa authored Nov 19, 2024
1 parent 51d55d3 commit 228e056
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 182 deletions.
3 changes: 2 additions & 1 deletion playground/alias/__tests__/alias.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from 'vitest'
import { editFile, getColor, page, untilUpdated } from '~utils'
import { editFile, getColor, isBuild, page, untilUpdated } from '~utils'

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

test('css via link', async () => {
expect(await getColor('body')).toBe('grey')
if (isBuild) return
editFile('dir/test.css', (code) => code.replace('grey', 'red'))
await untilUpdated(() => getColor('body'), 'red')
})
Expand Down
12 changes: 4 additions & 8 deletions playground/assets/__tests__/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ test.runIf(isBuild)('manifest', async () => {

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

test('import module.css', async () => {
expect(await getColor('#foo')).toBe('red')
editFile('css/foo.module.css', (code) => code.replace('red', 'blue'), true)
editFile('css/foo.module.css', (code) => code.replace('red', 'blue'))
await notifyRebuildComplete(watcher)
await page.reload()
expect(await getColor('#foo')).toBe('blue')
})

test('import with raw query', async () => {
expect(await page.textContent('.raw-query')).toBe('foo')
editFile('static/foo.txt', (code) => code.replace('foo', 'zoo'), true)
editFile('static/foo.txt', (code) => code.replace('foo', 'zoo'))
await notifyRebuildComplete(watcher)
await page.reload()
expect(await page.textContent('.raw-query')).toBe('zoo')
Expand All @@ -585,11 +585,7 @@ if (!isBuild) {
test('@import in html style tag hmr', async () => {
await untilUpdated(() => getColor('.import-css'), 'rgb(0, 136, 255)')
const loadPromise = page.waitForEvent('load')
editFile(
'./css/import.css',
(code) => code.replace('#0088ff', '#00ff88'),
true,
)
editFile('./css/import.css', (code) => code.replace('#0088ff', '#00ff88'))
await loadPromise
await untilUpdated(() => getColor('.import-css'), 'rgb(0, 255, 136)')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test('linked css', async () => {
expect(await getColor(linked)).toBe('blue')
expect(await getColor(atImport)).toBe('red')

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

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

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

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

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

if (isBuild) return
editFile('mod.module.css', (code) =>
code.replace('color: turquoise', 'color: red'),
)
Expand Down
18 changes: 18 additions & 0 deletions playground/css/__tests__/css.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ test('linked css', async () => {
expect(await getColor(linked)).toBe('blue')
expect(await getColor(atImport)).toBe('red')

if (isBuild) return

editFile('linked.css', (code) => code.replace('color: blue', 'color: red'))
await untilUpdated(() => getColor(linked), 'red')

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

if (isBuild) return

editFile('imported.css', (code) => code.replace('color: green', 'color: red'))
await untilUpdated(() => getColor(imported), 'red')

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

if (isBuild) return

editFile('imported.css', (code) => code.replace('color: pink', 'color: red'))
await untilUpdated(() => getColor(imported), 'red')
})
Expand Down Expand Up @@ -96,6 +102,8 @@ test('sass', async () => {
expect(await getColor(await page.$('.sass-file-absolute'))).toBe('orange')
expect(await getColor(await page.$('.sass-dir-index'))).toBe('orange')

if (isBuild) return

editFile('sass.scss', (code) =>
code.replace('color: $injectedColor', 'color: red'),
)
Expand Down Expand Up @@ -131,6 +139,8 @@ test('less', async () => {
isBuild ? /ok-[-\w]+\.png/ : `${viteTestUrl}/ok.png`,
)

if (isBuild) return

editFile('less.less', (code) => code.replace('@color: blue', '@color: red'))
await untilUpdated(() => getColor(imported), 'red')

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

if (isBuild) return

editFile('stylus.styl', (code) =>
code.replace('$color ?= blue', '$color ?= red'),
)
Expand All @@ -183,6 +195,8 @@ test('css modules', async () => {
/.mod-module__apply-color___[\w-]{5}/,
)

if (isBuild) return

editFile('mod.module.css', (code) =>
code.replace('color: turquoise', 'color: red'),
)
Expand Down Expand Up @@ -259,6 +273,8 @@ test('css modules w/ sass', async () => {
/.mod-module__apply-color___[\w-]{5}/,
)

if (isBuild) return

editFile('mod.module.scss', (code) =>
code.replace('color: orangered', 'color: blue'),
)
Expand Down Expand Up @@ -514,6 +530,8 @@ test('sugarss', async () => {
isBuild ? /base64/ : '/nested/icon.png',
)

if (isBuild) return

editFile('sugarss.sss', (code) => code.replace('color: blue', 'color: coral'))
await untilUpdated(() => getColor(imported), 'coral')

Expand Down
32 changes: 10 additions & 22 deletions playground/dynamic-import/__tests__/dynamic-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {

test('should load literal dynamic import', async () => {
await page.click('.baz')
await untilUpdated(() => page.textContent('.view'), 'Baz view', true)
await untilUpdated(() => page.textContent('.view'), 'Baz view')
})

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

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

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

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

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

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

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

await page.click('.bar')
await untilUpdated(() => page.textContent('.view'), 'Bar view', true)
await untilUpdated(() => page.textContent('.view'), 'Bar view')
})

// dynamic import css
Expand All @@ -65,23 +65,20 @@ test('should load dynamic import with css', async () => {
await untilUpdated(
() => page.$eval('.view', (node) => window.getComputedStyle(node).color),
'rgb(255, 0, 0)',
true,
)
})

test('should load dynamic import with vars', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-with-vars'),
'hello',
true,
)
})

test('should load dynamic import with vars ignored', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-with-vars-ignored'),
'hello',
true,
)
// No warning should be logged as we are using @vite-ignore
expect(
Expand All @@ -95,76 +92,67 @@ test('should load dynamic import with double slash ignored', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-with-double-slash-ignored'),
'hello',
true,
)
})

test('should load dynamic import with vars multiline', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-with-vars-multiline'),
'hello',
true,
)
})

test('should load dynamic import with vars alias', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-with-vars-alias'),
'hi',
true,
)
})

test('should load dynamic import with vars raw', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-with-vars-raw'),
'export function hello()',
true,
)
})

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

test('should load dynamic import with vars worker', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-with-vars-worker'),
'load worker',
true,
)
})

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

test('should work with load ../ and itself directory', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-self'),
'dynamic-import-self-content',
true,
)
})

test('should work with load ../ and contain itself directory', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-nested-self'),
'dynamic-import-nested-self-content',
true,
)
})

test('should work a load path that contains parentheses.', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-with-vars-contains-parenthesis'),
'dynamic-import-with-vars-contains-parenthesis',
true,
)
})

Expand Down
24 changes: 7 additions & 17 deletions playground/legacy/__tests__/legacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,31 @@ import {
} from '~utils'

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

test('should work', async () => {
await untilUpdated(() => page.textContent('#app'), 'Hello', true)
await untilUpdated(() => page.textContent('#app'), 'Hello')
})

test('import.meta.env.LEGACY', async () => {
await untilUpdated(
() => page.textContent('#env'),
isBuild ? 'true' : 'false',
true,
)
await untilUpdated(() => page.textContent('#env-equal'), 'true', true)
await untilUpdated(() => page.textContent('#env'), isBuild ? 'true' : 'false')
await untilUpdated(() => page.textContent('#env-equal'), 'true')
})

// https://github.com/vitejs/vite/issues/3400
test('transpiles down iterators correctly', async () => {
await untilUpdated(() => page.textContent('#iterators'), 'hello', true)
await untilUpdated(() => page.textContent('#iterators'), 'hello')
})

test('async generator', async () => {
await untilUpdated(
() => page.textContent('#async-generator'),
'[0,1,2]',
true,
)
await untilUpdated(() => page.textContent('#async-generator'), '[0,1,2]')
})

test('wraps with iife', async () => {
await untilUpdated(
() => page.textContent('#babel-helpers'),
'exposed babel helpers: false',
true,
)
})

Expand All @@ -69,7 +60,6 @@ test('generates assets', async () => {
'immutable-chunk-legacy: text/html',
'polyfills-legacy: text/html',
].join('\n'),
true,
)
})

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

test('asset url', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ test.runIf(isBuild)('includes only a single script tag', async () => {
await untilUpdated(
() => page.getAttribute('#vite-legacy-entry', 'data-src'),
/.\/assets\/index-legacy-(.+)\.js/,
true,
)

expect(await page.locator('script').count()).toBe(1)
Expand Down
Loading

0 comments on commit 228e056

Please sign in to comment.