Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize more tests #15470

Merged
merged 13 commits into from
Jul 26, 2020
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
"release": "6.0.1",
"request-promise-core": "1.1.2",
"rimraf": "2.6.3",
"selenium-standalone": "6.17.0",
"selenium-webdriver": "4.0.0-alpha.5",
"selenium-standalone": "6.18.0",
"selenium-webdriver": "4.0.0-alpha.7",
"shell-quote": "1.7.2",
"styled-components": "5.1.0",
"styled-jsx-plugin-postcss": "2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const TIMINGS_API = `https://next-timings.jjsweb.site/api/timings`
{
stdio: 'inherit',
env: {
JEST_RETRY_TIMES: 2,
JEST_RETRY_TIMES: 0,
...process.env,
...(isAzure
? {
Expand Down
12 changes: 7 additions & 5 deletions test/integration/amphtml/pages/only-amp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export const config = { amp: true }

export default () => (
<div>
<p id="only-amp">Only AMP for me...</p>
</div>
)
export default function Page() {
return (
<div>
<p id="only-amp">Only AMP for me...</p>
</div>
)
}
6 changes: 3 additions & 3 deletions test/integration/auto-export/pages/[post]/[cmnt].js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ if (typeof window !== 'undefined') {
const origWarn = window.console.warn
const origError = window.console.error
window.console.warn = function (...args) {
window.caughtWarns.push(1)
window.caughtWarns.push(args)
origWarn(...args)
}
window.console.error = function (...args) {
window.caughtWarns.push(1)
window.caughtWarns.push(args)
origError(...args)
}
window.pathnames = []
}

export default () => {
export default function Page() {
if (typeof window !== 'undefined') {
window.pathnames.push(window.location.pathname)
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/auto-export/pages/[post]/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRouter } from 'next/router'

export default () => {
export default function Page() {
const { query } = useRouter()

return <p>post: {query.post}</p>
Expand Down
5 changes: 2 additions & 3 deletions test/integration/auto-export/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ describe('Auto Export', () => {

it('should not show hydration warning from mismatching asPath', async () => {
const browser = await webdriver(appPort, '/zeit/cmnt-1')

const numCaught = await browser.eval(`window.caughtWarns.length`)
expect(numCaught).toBe(0)
const caughtWarns = await browser.eval(`window.caughtWarns`)
expect(caughtWarns).toEqual([])
})
})
})
4 changes: 3 additions & 1 deletion test/integration/build-indicator/pages/a.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export default () => <p>Hello from a</p>
export default function Page() {
return <p>Hello from a</p>
}
4 changes: 3 additions & 1 deletion test/integration/build-indicator/pages/b.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export default () => <p>Hello from b</p>
export default function Page() {
return <p>Hello from b</p>
}
22 changes: 12 additions & 10 deletions test/integration/build-indicator/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Link from 'next/link'

export default () => (
<>
<Link href="/a">
<a id="to-a">Go to a</a>
</Link>
<Link href="/b">
<a id="to-b">Go to b</a>
</Link>
</>
)
export default function Page() {
return (
<>
<Link href="/a">
<a id="to-a">Go to a</a>
</Link>
<Link href="/b">
<a id="to-b">Go to b</a>
</Link>
</>
)
}
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
2 changes: 1 addition & 1 deletion test/integration/invalid-href/pages/third.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState } from 'react'

const invalidLink = 'https://vercel.com/'

export default () => {
export default function Page() {
const { query, ...router } = useRouter()
const [isDone, setIsDone] = useState(false)
const { method = 'push' } = query
Expand Down
23 changes: 10 additions & 13 deletions test/integration/invalid-href/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,18 @@ jest.retryTimes(0)
const showsError = async (pathname, regex, click = false, isWarn = false) => {
const browser = await webdriver(appPort, pathname)
try {
// wait for page to be built and navigated to
await browser.waitForElementByCss('#click-me')
if (isWarn) {
await browser.eval(`(function() {
window.warnLogs = []
var origWarn = window.console.warn
window.console.warn = function() {
var warnStr = ''
for (var i = 0; i < arguments.length; i++) {
if (i > 0) warnStr += ' ';
warnStr += arguments[i]
}
window.warnLogs.push(warnStr)
origWarn.apply(undefined, arguments)
window.console.warn = (...args) => {
window.warnLogs.push(args.join(' '))
origWarn.apply(window.console, args)
}
})()`)
}
// wait for page to be built and navigated to
await waitFor(3000)
await browser.waitForElementByCss('#click-me')
if (click) {
await browser.elementByCss('#click-me').click()
await waitFor(500)
Expand All @@ -70,6 +64,11 @@ const showsError = async (pathname, regex, click = false, isWarn = false) => {
const noError = async (pathname, click = false) => {
const browser = await webdriver(appPort, '/')
try {
await check(async () => {
const appReady = await browser.eval('!!window.next.router')
console.log('app ready: ', appReady)
return appReady ? 'ready' : 'nope'
}, 'ready')
await browser.eval(`(function() {
window.caughtErrors = []
window.addEventListener('error', function (error) {
Expand All @@ -80,8 +79,6 @@ const noError = async (pathname, click = false) => {
})
window.next.router.replace('${pathname}')
})()`)
// wait for page to be built and navigated to
await waitFor(3000)
await browser.waitForElementByCss('#click-me')
if (click) {
await browser.elementByCss('#click-me').click()
Expand Down
Loading