From d4da5f531f0f777f97cc50fad5bca876e33659dd Mon Sep 17 00:00:00 2001 From: bluwy Date: Wed, 25 May 2022 00:38:51 +0800 Subject: [PATCH] chore: fix ssr tests --- .../ssr-react/__tests__/ssr-react.spec.ts | 2 ++ playground/ssr-vue/__tests__/ssr-vue.spec.ts | 17 ++++++++++------- playground/ssr-vue/vite.config.js | 3 +++ playground/ssr-vue/vite.config.noexternal.js | 3 +++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/playground/ssr-react/__tests__/ssr-react.spec.ts b/playground/ssr-react/__tests__/ssr-react.spec.ts index 62bb7d2014f770..49b031f9e70fd8 100644 --- a/playground/ssr-react/__tests__/ssr-react.spec.ts +++ b/playground/ssr-react/__tests__/ssr-react.spec.ts @@ -40,6 +40,7 @@ test('/', async () => { }) test('hmr', async () => { + await page.goto(url) editFile('src/pages/Home.jsx', (code) => code.replace('

Home', '

changed') ) @@ -47,6 +48,7 @@ test('hmr', async () => { }) test('client navigation', async () => { + await page.goto(url) await untilUpdated(() => page.textContent('a[href="/about"]'), 'About') await page.click('a[href="/about"]') await untilUpdated(() => page.textContent('h1'), 'About') diff --git a/playground/ssr-vue/__tests__/ssr-vue.spec.ts b/playground/ssr-vue/__tests__/ssr-vue.spec.ts index c58cea4cd13e59..e4b8170364f009 100644 --- a/playground/ssr-vue/__tests__/ssr-vue.spec.ts +++ b/playground/ssr-vue/__tests__/ssr-vue.spec.ts @@ -13,7 +13,8 @@ import { const url = `http://localhost:${port}` test('vuex can be import succeed by named import', async () => { - await page.goto(url + '/store') + // wait networkidle for dynamic optimize vuex + await page.goto(url + '/store', { waitUntil: 'networkidle' }) expect(await page.textContent('h1')).toMatch('bar') // raw http request @@ -111,19 +112,18 @@ test('/', async () => { }) test('css', async () => { + await page.goto(url) if (isBuild) { expect(await getColor('h1')).toBe('green') expect(await getColor('.jsx')).toBe('blue') } else { - // During dev, the CSS is loaded from async chunk and we may have to wait - // when the test runs concurrently. - await page.waitForLoadState('networkidle') await untilUpdated(() => getColor('h1'), 'green') await untilUpdated(() => getColor('.jsx'), 'blue') } }) test('asset', async () => { + await page.goto(url) // should have no 404s browserLogs.forEach((msg) => { expect(msg).not.toMatch('404') @@ -135,36 +135,39 @@ test('asset', async () => { }) test('jsx', async () => { + await page.goto(url) expect(await page.textContent('.jsx')).toMatch('from JSX') }) test('virtual module', async () => { + await page.goto(url) expect(await page.textContent('.virtual')).toMatch('hi') }) test('nested virtual module', async () => { + await page.goto(url) expect(await page.textContent('.nested-virtual')).toMatch('[success]') }) test('hydration', async () => { + await page.goto(url) expect(await page.textContent('button')).toMatch('0') await page.click('button') - await page.waitForLoadState('networkidle') expect(await page.textContent('button')).toMatch('1') }) test('hmr', async () => { + await page.goto(url) editFile('src/pages/Home.vue', (code) => code.replace('Home', 'changed')) - await page.waitForLoadState('networkidle') await untilUpdated(() => page.textContent('h1'), 'changed') }) test('client navigation', async () => { + await page.goto(url) await untilUpdated(() => page.textContent('a[href="/about"]'), 'About') await page.click('a[href="/about"]') await untilUpdated(() => page.textContent('h1'), 'About') editFile('src/pages/About.vue', (code) => code.replace('About', 'changed')) - await page.waitForLoadState('networkidle') await untilUpdated(() => page.textContent('h1'), 'changed') await page.click('a[href="/"]') await untilUpdated(() => page.textContent('a[href="/"]'), 'Home') diff --git a/playground/ssr-vue/vite.config.js b/playground/ssr-vue/vite.config.js index 03277fd6560551..83128683536388 100644 --- a/playground/ssr-vue/vite.config.js +++ b/playground/ssr-vue/vite.config.js @@ -51,5 +51,8 @@ module.exports = { // this package has uncompiled .vue files 'example-external-component' ] + }, + optimizeDeps: { + exclude: ['example-external-component'] } } diff --git a/playground/ssr-vue/vite.config.noexternal.js b/playground/ssr-vue/vite.config.noexternal.js index ac74bf1430e94e..ce9a389defc68b 100644 --- a/playground/ssr-vue/vite.config.noexternal.js +++ b/playground/ssr-vue/vite.config.noexternal.js @@ -18,5 +18,8 @@ module.exports = Object.assign(config, { replacement: '@vue/runtime-core/dist/runtime-core.cjs.js' } ] + }, + optimizeDeps: { + exclude: ['example-external-component'] } })