Skip to content

Commit

Permalink
update @brillout/test-e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Jul 4, 2023
1 parent b3f00f3 commit f3e66c0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 35 deletions.
10 changes: 4 additions & 6 deletions boilerplates/.testRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
autoRetry,
fetchHtml,
getServerUrl,
expectError,
expectLog,
editFile,
editFileRevert,
sleep,
Expand Down Expand Up @@ -119,11 +119,9 @@ function testRun(
await page.goto(getServerUrl() + '/does-not-exist')
expect(await page.textContent('h1')).toBe('404 Page Not Found')
expect(await page.textContent('p')).toBe('This page could not be found.')
expectError(
(log) =>
log.logSource === 'Browser Error' &&
partRegex`http://${/[^\/]+/}:3000/does-not-exist`.test(log.logText) &&
log.logText.includes('Failed to load resource: the server responded with a status of 404 (Not Found)')
expectLog(
'Failed to load resource: the server responded with a status of 404 (Not Found)',
(log) => log.logSource === 'Browser Error' && partRegex`http://${/[^\/]+/}:3000/does-not-exist`.test(log.logText)
)
})
}
18 changes: 7 additions & 11 deletions examples/react-full/.testRun.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { run, page, test, expect, getServerUrl, fetchHtml, autoRetry, expectError, sleep } from '@brillout/test-e2e'
import { run, page, test, expect, getServerUrl, fetchHtml, autoRetry, expectLog, sleep } from '@brillout/test-e2e'

export { testRun }

Expand Down Expand Up @@ -119,11 +119,9 @@ function testRun(viewFramework: 'vue' | 'react', cmd: 'npm run dev' | 'npm run p
test('throw RenderErrorPage', async () => {
await page.goto(getServerUrl() + '/hello/bob')
expect(await page.textContent('h1')).toBe('404 Page Not Found')
expectError(
(log) =>
log.logSource === 'Browser Error' &&
log.logText.includes('http://localhost:3000/hello/bob') &&
log.logText.includes('Failed to load resource: the server responded with a status of 404 (Not Found)')
expectLog(
'Failed to load resource: the server responded with a status of 404 (Not Found)',
(log) => log.logSource === 'Browser Error' && log.logText.includes('http://localhost:3000/hello/bob')
)
const txt = 'Unknown name: bob.'
expect(await page.textContent('body')).toContain(txt)
Expand All @@ -134,11 +132,9 @@ function testRun(viewFramework: 'vue' | 'react', cmd: 'npm run dev' | 'npm run p
test('guard()', async () => {
await page.goto(getServerUrl() + '/hello/forbidden')
expect(await page.textContent('h1')).toBe('Forbidden')
expectError(
(log) =>
log.logSource === 'Browser Error' &&
log.logText.includes('http://localhost:3000/hello/forbidden') &&
log.logText.includes('Failed to load resource: the server responded with a status of 404 (Not Found)')
expectLog(
'Failed to load resource: the server responded with a status of 404 (Not Found)',
(log) => log.logSource === 'Browser Error' && log.logText.includes('http://localhost:3000/hello/forbidden')
)
const txt = 'This page is forbidden.'
expect(await page.textContent('body')).toContain(txt)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"devDependencies": {
"@brillout/bump-dependencies": "^0.1.1",
"@brillout/dev-my-dep": "^0.1.5",
"@brillout/test-e2e": "^0.5.9",
"@brillout/test-e2e": "^0.5.10",
"@brillout/test-types": "^0.1.6",
"vitest": "^0.32.0"
},
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions test/env/.test-dev.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { page, test, expect, run, autoRetry, fetchHtml, getServerUrl, expectError } from '@brillout/test-e2e'
import { page, test, expect, run, autoRetry, fetchHtml, getServerUrl, expectLog } from '@brillout/test-e2e'

testRun()

Expand All @@ -11,7 +11,7 @@ function testRun() {
expect(html).toContain('<li>PUBLIC_ENV: <!-- -->123</li><li>SOME_ENV: <!-- -->456</li>')
})

test("Warning is shown while client-side works", async () => {
test('Warning is shown while client-side works', async () => {
await page.goto(getServerUrl() + '/')
await page.click('a[href="/"]')
expect(await page.textContent('h1')).toBe('Welcome')
Expand All @@ -21,12 +21,9 @@ function testRun() {
await page.click('button')
expect(await page.textContent('button')).toBe('Counter 1')
})
expectError(
(log) =>
log.logSource === 'stderr' &&
log.logText.includes(
'import.meta.env.SOME_ENV used in /pages/index/+Page.jsx and therefore included in client-side bundle which can be be a security leak (vite-plugin-ssr will prevent your app from building for production), remove import.meta.env.SOME_ENV or rename SOME_ENV to PUBLIC_SOME_ENV, see https://vite-plugin-ssr.com/env'
)
expectLog(
'import.meta.env.SOME_ENV used in /pages/index/+Page.jsx and therefore included in client-side bundle which can be be a security leak (vite-plugin-ssr will prevent your app from building for production), remove import.meta.env.SOME_ENV or rename SOME_ENV to PUBLIC_SOME_ENV, see https://vite-plugin-ssr.com/env',
(log) => log.logSource === 'stderr'
)
})
}
10 changes: 5 additions & 5 deletions vite-plugin-ssr/shared/route/resolveRouteString.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ describe('resolveRouteString', () => {
expect(resolveRouteString('/a', '/a')).toEqual({ routeParams: {} })
expect(resolveRouteString('/', '/')).toEqual({ routeParams: {} })

expectError(
expectErr(
() => resolveRouteString('', '/a/b/c'),
`[vite-plugin-ssr][Wrong Usage] Invalid Route String '' (empty string): Route Strings should start with a leading slash '/' (or be '*')`
)
expectError(
expectErr(
() => resolveRouteString('a', '/a/b/c'),
`[vite-plugin-ssr][Wrong Usage] Invalid Route String 'a': Route Strings should start with a leading slash '/' (or be '*')`
)
Expand Down Expand Up @@ -60,11 +60,11 @@ describe('resolveRouteString', () => {
expect(resolveRouteString('/a/*', '/a/b/c/d')).toEqual({ routeParams: { '*': 'b/c/d' } })
expect(resolveRouteString('/a/*', '/b/c')).toEqual(null)

expectError(
expectErr(
() => resolveRouteString('/a/*/c/*', '/a/b/c'),
`[vite-plugin-ssr][Wrong Usage] Invalid Route String '/a/*/c/*': Route Strings are not allowed to contain more than one glob character '*'`
)
expectError(
expectErr(
() => resolveRouteString('/a/*/c', '/a/b/c'),
`[vite-plugin-ssr][Wrong Usage] Invalid Route String '/a/*/c': make sure your Route String ends with the glob character '*'`
)
Expand All @@ -83,7 +83,7 @@ describe('resolveRouteString', () => {
})
})

function expectError(fn: Function, errMsg: string) {
function expectErr(fn: Function, errMsg: string) {
{
let err: Error | undefined
try {
Expand Down

0 comments on commit f3e66c0

Please sign in to comment.