Unverified Commit 3ffef602 authored by Jan Potoms's avatar Jan Potoms Committed by GitHub

Fix webdriver error handling (#15491)

errors in script execution will result in timeout instead of failure. This PR makes sure to pass all arguments to `.then` so error handling is correctly set up. (`.then` needs to be able to take a second argument). I also removed `.finally`.

I don't know why, but it looks like the following test does something that prevents the tests after it from opening a new browser window on azure. I'm giving up, I shuffled the tests to put this one last.
```js
    it('shows warning when dynamic route mismatch is used on Link', async () => {
      await showsError(
        '/dynamic-route-mismatch',
        /Mismatching `as` and `href` failed to manually provide the params: post in the `href`'s `query`/,
        true,
        true
      )
    })
```
parent 571e2a7c
......@@ -64,11 +64,6 @@ 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) {
......@@ -92,56 +87,6 @@ const noError = async (pathname, click = false) => {
}
describe('Invalid hrefs', () => {
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
it('shows error when mailto: is used as href on Link', async () => {
await showsError('/first', firstErrorRegex)
})
it('shows error when mailto: is used as href on router.push', async () => {
await showsError('/first?method=push', firstErrorRegex, true)
})
it('shows error when mailto: is used as href on router.replace', async () => {
await showsError('/first?method=replace', firstErrorRegex, true)
})
it('shows error when https://google.com is used as href on Link', async () => {
await showsError('/second', secondErrorRegex)
})
it('shows error when http://google.com is used as href on router.push', async () => {
await showsError('/second?method=push', secondErrorRegex, true)
})
it('shows error when https://google.com is used as href on router.replace', async () => {
await showsError('/second?method=replace', secondErrorRegex, true)
})
it('shows error when dynamic route mismatch is used on Link', async () => {
await showsError(
'/dynamic-route-mismatch',
/The provided `as` value \(\/blog\/post-1\) is incompatible with the `href` value \(\/\[post\]\)/,
true
)
await showsError(
'/dynamic-route-mismatch',
/Mismatching `as` and `href` failed to manually provide the params: post in the `href`'s `query`/,
true,
true
)
})
it('does not throw error when dynamic route mismatch is used on Link and params are manually provided', async () => {
await noError('/dynamic-route-mismatch-manual', true)
})
})
describe('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
......@@ -210,4 +155,57 @@ describe('Invalid hrefs', () => {
await browser.waitForElementByCss('#is-done')
})
})
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
it('shows error when mailto: is used as href on Link', async () => {
await showsError('/first', firstErrorRegex)
})
it('shows error when mailto: is used as href on router.push', async () => {
await showsError('/first?method=push', firstErrorRegex, true)
})
it('shows error when mailto: is used as href on router.replace', async () => {
await showsError('/first?method=replace', firstErrorRegex, true)
})
it('shows error when https://google.com is used as href on Link', async () => {
await showsError('/second', secondErrorRegex)
})
it('shows error when http://google.com is used as href on router.push', async () => {
await showsError('/second?method=push', secondErrorRegex, true)
})
it('shows error when https://google.com is used as href on router.replace', async () => {
await showsError('/second?method=replace', secondErrorRegex, true)
})
it('shows error when dynamic route mismatch is used on Link', async () => {
await showsError(
'/dynamic-route-mismatch',
/The provided `as` value \(\/blog\/post-1\) is incompatible with the `href` value \(\/\[post\]\)/,
true
)
})
it('does not throw error when dynamic route mismatch is used on Link and params are manually provided', async () => {
await noError('/dynamic-route-mismatch-manual', true)
})
it('shows warning when dynamic route mismatch is used on Link', async () => {
await showsError(
'/dynamic-route-mismatch',
/Mismatching `as` and `href` failed to manually provide the params: post in the `href`'s `query`/,
true,
true
)
})
})
})
......@@ -10,9 +10,8 @@ export default class Chain {
this.promise = Promise.resolve()
}
this.promise = this.promise.then(nextCall)
this.then = (cb) => this.promise.then(cb)
this.catch = (cb) => this.promise.catch(cb)
this.finally = (cb) => this.promise.finally(cb)
this.then = (...args) => this.promise.then(...args)
this.catch = (...args) => this.promise.catch(...args)
return this
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment