Skip to content

Commit

Permalink
chore: update e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
hannoeru committed Jun 30, 2022
1 parent ad8c5e9 commit 7d0e443
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 174 deletions.
76 changes: 26 additions & 50 deletions test/e2e/react.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable jest/no-conditional-expect */
/* eslint-disable no-console */
import { resolve } from 'path'
import { copyFile, rm } from 'fs/promises'
import { existsSync } from 'fs'
import { createServer } from 'vite'
import { chromium } from 'playwright'
import { getViteConfig, stopServer } from './utils'
Expand All @@ -10,6 +9,9 @@ import type { ViteDevServer } from 'vite'

const vueRoot = resolve('./examples/react')

const srcPath = resolve('./test/data/test.tsx')
const distPath = resolve('./examples/react/src/pages/test.tsx')

describe('react e2e test', () => {
let server: ViteDevServer
let browser: Browser
Expand All @@ -23,76 +25,50 @@ describe('react e2e test', () => {
})

afterAll(async() => {
// HMR test file
if (existsSync(distPath))
await rm(distPath)
await browser.close()
await stopServer(server)
})

const getUrl = (path: string) => `http://localhost:${server.config.server.port}${path}`

test('/blog/today have content', async() => {
try {
await page.goto(getUrl('/blog/today'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today/index')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/blog/today'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today/index')
})

test('/blog/today/xxx - nested cache all', async() => {
try {
await page.goto(getUrl('/blog/today/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today ...all route')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/blog/today/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today ...all route')
})

test('/xxx/xxx - cache all route', async() => {
try {
await page.goto(getUrl('/xxx/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('...all route')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/xxx/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('...all route')
})

test('/blog/1b234bk12b3 - dynamic route', async() => {
try {
await page.goto(getUrl('/blog/1b234bk12b3'))
const text = await page.locator('body > div > p').textContent()
expect(text?.trim()).toBe('blog/[id].tsx: 1b234bk12b3')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/blog/1b234bk12b3'))
const text = await page.locator('body > div > p').textContent()
expect(text?.trim()).toBe('blog/[id].tsx: 1b234bk12b3')
})

test('hmr - dynamic add /test route', async() => {
const srcPath = resolve('./test/data/test.tsx')
const distPath = resolve('./examples/react/src/pages/test.tsx')

try {
await page.goto(getUrl('/'))
await page.goto(getUrl('/'))

await copyFile(srcPath, distPath)
await copyFile(srcPath, distPath)

await page.goto(getUrl('/'), { waitUntil: 'networkidle' })
await page.goto(getUrl('/test'))
await page.goto(getUrl('/'), { waitUntil: 'networkidle' })
await page.goto(getUrl('/test'))

const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('this is test file')
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('this is test file')

await rm(distPath)
} catch (e) {
await rm(distPath)
console.error(e)
expect(e).toBeUndefined()
}
await rm(distPath)
})
})
86 changes: 29 additions & 57 deletions test/e2e/solid.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable jest/no-standalone-expect */
/* eslint-disable no-console */
import { resolve } from 'path'
import { copyFile, rm } from 'fs/promises'
import { existsSync } from 'fs'
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
import { createServer } from 'vite'
import { chromium } from 'playwright'
Expand All @@ -11,6 +11,9 @@ import type { ViteDevServer } from 'vite'

const solidRoot = resolve('./examples/solid')

const srcPath = resolve('./test/data/test.tsx')
const distPath = resolve(`${solidRoot}/src/pages/test.tsx`)

describe('solid e2e test', () => {
let server: ViteDevServer
let browser: Browser
Expand All @@ -24,87 +27,56 @@ describe('solid e2e test', () => {
})

afterAll(async() => {
// HMR test file
if (existsSync(distPath))
await rm(distPath)
await browser.close()
await stopServer(server)
})

const getUrl = (path: string) => `http://localhost:${server.config.server.port}${path}`

test('/blog/today have content', async() => {
try {
await page.goto(getUrl('/blog/today'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today/index.tsx')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/blog/today'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today/index.tsx')
})

test('/blog/today/xxx - nested cache all', async() => {
try {
await page.goto(getUrl('/blog/today/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today ...all route')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/blog/today/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today ...all route')
})

test('/xxx/xxx - cache all route', async() => {
try {
await page.goto(getUrl('/xxx/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('...all route')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/xxx/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('...all route')
})

test('/about/1b234bk12b3/more deep nested dynamic route', async() => {
try {
await page.goto(getUrl('/about/1b234bk12b3/more'))
const text = await page.locator('div.deep-more').textContent()
expect(text?.trim()).toBe('deep nested: about/[id]/more.tsx')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/about/1b234bk12b3/more'))
const text = await page.locator('div.deep-more').textContent()
expect(text?.trim()).toBe('deep nested: about/[id]/more.tsx')
})

test('/features/dashboard custom routes folder', async() => {
try {
await page.goto(getUrl('/features/dashboard'))
const text = await page.locator('body > div > p >> nth=0').textContent()
expect(text?.trim()).toBe('features/dashboard/pages/dashboard.tsx')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/features/dashboard'))
const text = await page.locator('body > div > p >> nth=0').textContent()
expect(text?.trim()).toBe('features/dashboard/pages/dashboard.tsx')
})

test('hmr - dynamic add /test route', async() => {
const srcPath = resolve('./test/data/test.tsx')
const distPath = resolve(`${solidRoot}/src/pages/test.tsx`)

try {
await page.goto(getUrl('/'))
await page.goto(getUrl('/'))

await copyFile(srcPath, distPath)
await copyFile(srcPath, distPath)

await page.goto(getUrl('/'), { waitUntil: 'networkidle' })
await page.goto(getUrl('/test'))
await page.goto(getUrl('/'), { waitUntil: 'networkidle' })
await page.goto(getUrl('/test'))

const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('this is test file')
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('this is test file')

await rm(distPath)
} catch (e) {
await rm(distPath)
console.error(e)
expect(e).toBeUndefined()
}
await rm(distPath)
})
})
97 changes: 32 additions & 65 deletions test/e2e/vue.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable jest/no-standalone-expect */
/* eslint-disable no-console */
import { resolve } from 'path'
import { copyFile, rm } from 'fs/promises'
import { existsSync } from 'fs'
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
import { createServer } from 'vite'
import { chromium } from 'playwright'
Expand All @@ -11,6 +11,9 @@ import type { ViteDevServer } from 'vite'

const vueRoot = resolve('./examples/vue')

const srcPath = resolve('./test/data/test.vue')
const distPath = resolve('./examples/vue/src/pages/test.vue')

describe('vue e2e test', () => {
let server: ViteDevServer
let browser: Browser
Expand All @@ -24,98 +27,62 @@ describe('vue e2e test', () => {
})

afterAll(async() => {
// HMR test file
if (existsSync(distPath))
await rm(distPath)
await browser.close()
await stopServer(server)
})

const getUrl = (path: string) => `http://localhost:${server.config.server.port}${path}`

test('/blog/today have content', async() => {
try {
await page.goto(getUrl('/blog/today'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today/index.vue')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/blog/today'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today/index.vue')
})

test('/blog/today/xxx - nested cache all', async() => {
try {
await page.goto(getUrl('/blog/today/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today ...all route')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/blog/today/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('blog/today ...all route')
})

test('/markdown have markdown content', async() => {
try {
await page.goto(getUrl('/markdown'))
const text = await page.locator('body > div > div > h1').textContent()
expect(text?.trim()).toBe('hello from markdown file')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/markdown'))
const text = await page.locator('body > div > div > h1').textContent()
expect(text?.trim()).toBe('hello from markdown file')
})

test('/xxx/xxx - cache all route', async() => {
try {
await page.goto(getUrl('/xxx/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('...all route')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/xxx/xxx'))
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('...all route')
})

test('/about/1b234bk12b3/more deep nested dynamic route', async() => {
try {
await page.goto(getUrl('/about/1b234bk12b3/more'))
const text = await page.locator('div.deep-more').textContent()
expect(text?.trim()).toBe('deep nested: about/[id]/more.vue')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/about/1b234bk12b3/more'))
const text = await page.locator('div.deep-more').textContent()
expect(text?.trim()).toBe('deep nested: about/[id]/more.vue')
})

test('/features/dashboard custom routes folder', async() => {
try {
await page.goto(getUrl('/features/dashboard'))
const text = await page.locator('body > div > p >> nth=0').textContent()
expect(text?.trim()).toBe('features/dashboard/pages/dashboard.vue')
} catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await page.goto(getUrl('/features/dashboard'))
const text = await page.locator('body > div > p >> nth=0').textContent()
expect(text?.trim()).toBe('features/dashboard/pages/dashboard.vue')
})

test('hmr - dynamic add /test route works', async() => {
const srcPath = resolve('./test/data/test.vue')
const distPath = resolve('./examples/vue/src/pages/test.vue')

try {
await page.goto(getUrl('/'))
await page.goto(getUrl('/'))

await copyFile(srcPath, distPath)
await copyFile(srcPath, distPath)

await page.goto(getUrl('/'), { waitUntil: 'networkidle' })
await page.goto(getUrl('/test'))
await page.goto(getUrl('/'), { waitUntil: 'networkidle' })
await page.goto(getUrl('/test'))

const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('this is test file')
const text = await page.locator('body > div').textContent()
expect(text?.trim()).toBe('this is test file')

await rm(distPath)
} catch (e) {
await rm(distPath)
console.error(e)
expect(e).toBeUndefined()
}
await rm(distPath)
})
})
Loading

0 comments on commit 7d0e443

Please sign in to comment.