Skip to content

Commit

Permalink
stabilize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot committed Jul 25, 2020
1 parent a297bb1 commit 6f53352
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
38 changes: 20 additions & 18 deletions test/integration/dynamic-optional-routing/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import {
nextBuild,
nextStart,
renderViaHTTP,
waitFor,
check,
} from 'next-test-utils'
import { join } from 'path'

jest.setTimeout(1000 * 60 * 2)

let app
let appPort
let stderr
const appDir = join(__dirname, '../')

const DUMMY_PAGE = 'export default () => null'
Expand Down Expand Up @@ -187,9 +188,10 @@ function runInvalidPagesTests(buildFn) {
const invalidRoute = appDir + 'pages/index.js'
try {
await fs.outputFile(invalidRoute, DUMMY_PAGE, 'utf-8')
const { stderr } = await buildFn(appDir)
await expect(stderr).toMatch(
'You cannot define a route with the same specificity as a optional catch-all route'
await buildFn(appDir)
await check(
() => stderr,
/You cannot define a route with the same specificity as a optional catch-all route/
)
} finally {
await fs.unlink(invalidRoute)
Expand All @@ -200,9 +202,10 @@ function runInvalidPagesTests(buildFn) {
const invalidRoute = appDir + 'pages/nested.js'
try {
await fs.outputFile(invalidRoute, DUMMY_PAGE, 'utf-8')
const { stderr } = await buildFn(appDir)
await expect(stderr).toMatch(
'You cannot define a route with the same specificity as a optional catch-all route'
await buildFn(appDir)
await check(
() => stderr,
/You cannot define a route with the same specificity as a optional catch-all route/
)
} finally {
await fs.unlink(invalidRoute)
Expand All @@ -213,8 +216,8 @@ function runInvalidPagesTests(buildFn) {
const invalidRoute = appDir + 'pages/nested/[...param].js'
try {
await fs.outputFile(invalidRoute, DUMMY_PAGE, 'utf-8')
const { stderr } = await buildFn(appDir)
await expect(stderr).toMatch(/You cannot use both .+ at the same level/)
await buildFn(appDir)
await check(() => stderr, /You cannot use both .+ at the same level/)
} finally {
await fs.unlink(invalidRoute)
}
Expand All @@ -224,9 +227,10 @@ function runInvalidPagesTests(buildFn) {
const invalidRoute = appDir + 'pages/invalid/[[param]].js'
try {
await fs.outputFile(invalidRoute, DUMMY_PAGE, 'utf-8')
const { stderr } = await buildFn(appDir)
await expect(stderr).toMatch(
'Optional route parameters are not yet supported'
await buildFn(appDir)
await check(
() => stderr,
/Optional route parameters are not yet supported/
)
} finally {
await fs.unlink(invalidRoute)
Expand All @@ -245,14 +249,12 @@ describe('Dynamic Optional Routing', () => {
runTests()

runInvalidPagesTests(async (appDir) => {
let stderr = ''
stderr = ''
await launchApp(appDir, await findPort(), {
onStderr: (msg) => {
stderr += msg
},
})
await waitFor(1000)
return { stderr }
})
})

Expand All @@ -272,9 +274,9 @@ describe('Dynamic Optional Routing', () => {

runTests()

runInvalidPagesTests(async (appDir) =>
nextBuild(appDir, [], { stderr: true })
)
runInvalidPagesTests(async (appDir) => {
;({ stderr } = await nextBuild(appDir, [], { stderr: true }))
})

it('should fail to build when param is not explicitly defined', async () => {
const invalidRoute = appDir + 'pages/invalid/[[...slug]].js'
Expand Down
2 changes: 1 addition & 1 deletion test/integration/error-in-error/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Handles an Error in _error', () => {

it('Handles error during client transition', async () => {
const browser = await webdriver(port, '/')
await browser.elementByCss('a').click()
await browser.waitForElementByCss('a').click()
await waitFor(1000)
const html = await browser.eval('document.body.innerHTML')
expect(html).toMatch(/internal server error/i)
Expand Down

0 comments on commit 6f53352

Please sign in to comment.