Skip to content

Commit

Permalink
Fix webdriver error handling (vercel#15491)
Browse files Browse the repository at this point in the history
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
      )
    })
```
  • Loading branch information
Janpot authored Jul 29, 2020
1 parent 571e2a7 commit 3ffef60
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 58 deletions.
108 changes: 53 additions & 55 deletions test/integration/invalid-href/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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
)
})
})
})
5 changes: 2 additions & 3 deletions test/lib/wd-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 3ffef60

Please sign in to comment.