From 6f53352a0e69ed00f0be5ff8770897552e14a87e Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Sat, 25 Jul 2020 21:19:54 +0200 Subject: [PATCH] stabilize tests --- .../test/index.test.js | 38 ++++++++++--------- .../error-in-error/test/index.test.js | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/test/integration/dynamic-optional-routing/test/index.test.js b/test/integration/dynamic-optional-routing/test/index.test.js index 90dcb70c9e138..c17bd9168bf55 100644 --- a/test/integration/dynamic-optional-routing/test/index.test.js +++ b/test/integration/dynamic-optional-routing/test/index.test.js @@ -10,7 +10,7 @@ import { nextBuild, nextStart, renderViaHTTP, - waitFor, + check, } from 'next-test-utils' import { join } from 'path' @@ -18,6 +18,7 @@ jest.setTimeout(1000 * 60 * 2) let app let appPort +let stderr const appDir = join(__dirname, '../') const DUMMY_PAGE = 'export default () => null' @@ -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) @@ -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) @@ -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) } @@ -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) @@ -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 } }) }) @@ -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' diff --git a/test/integration/error-in-error/test/index.test.js b/test/integration/error-in-error/test/index.test.js index 2b4bee2991071..4443aec17bc33 100644 --- a/test/integration/error-in-error/test/index.test.js +++ b/test/integration/error-in-error/test/index.test.js @@ -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)