Commit 12241384 authored by Joe Haddad's avatar Joe Haddad Committed by JJ Kasper

Fix Chrome-Only Tests (#9825)

parent 69a34dd7
...@@ -441,82 +441,86 @@ describe('Production Usage', () => { ...@@ -441,82 +441,86 @@ describe('Production Usage', () => {
} }
}) })
it('should add prefetch tags when Link prefetch prop is used', async () => { if (browserName === 'chrome') {
const browser = await webdriver(appPort, '/prefetch') it('should add prefetch tags when Link prefetch prop is used', async () => {
await waitFor(2000) const browser = await webdriver(appPort, '/prefetch')
const elements = await browser.elementsByCss('link[rel=prefetch]') await waitFor(2000)
const elements = await browser.elementsByCss('link[rel=prefetch]')
expect(elements.length).toBe(4)
await Promise.all( expect(elements.length).toBe(4)
elements.map(async element => { await Promise.all(
const rel = await element.getAttribute('rel') elements.map(async element => {
const as = await element.getAttribute('as') const rel = await element.getAttribute('rel')
expect(rel).toBe('prefetch') const as = await element.getAttribute('as')
expect(as).toBe('script') expect(rel).toBe('prefetch')
}) expect(as).toBe('script')
) })
await browser.close() )
}) await browser.close()
})
// This is a workaround to fix https://github.com/zeit/next.js/issues/5860
// TODO: remove this workaround when https://bugs.webkit.org/show_bug.cgi?id=187726 is fixed.
it('It does not add a timestamp to link tags with prefetch attribute', async () => {
const browser = await webdriver(appPort, '/prefetch')
const links = await browser.elementsByCss('link[rel=prefetch]')
await Promise.all(
links.map(async element => {
const href = await element.getAttribute('href')
expect(href).not.toMatch(/\?ts=/)
})
)
const scripts = await browser.elementsByCss('script[src]')
await Promise.all(
scripts.map(async element => {
const src = await element.getAttribute('src')
expect(src).not.toMatch(/\?ts=/)
})
)
await browser.close()
})
it('should reload the page on page script error with prefetch', async () => {
const browser = await webdriver(appPort, '/counter')
if (global.browserName !== 'chrome') return
const counter = await browser
.elementByCss('#increase')
.click()
.click()
.elementByCss('#counter')
.text()
expect(counter).toBe('Counter: 2')
// Let the browser to prefetch the page and error it on the console. // This is a workaround to fix https://github.com/zeit/next.js/issues/5860
await waitFor(3000) // TODO: remove this workaround when https://bugs.webkit.org/show_bug.cgi?id=187726 is fixed.
const browserLogs = await browser.log('browser') it('It does not add a timestamp to link tags with prefetch attribute', async () => {
let foundLog = false const browser = await webdriver(appPort, '/prefetch')
browserLogs.forEach(log => { const links = await browser.elementsByCss('link[rel=prefetch]')
if (log.message.match(/\/no-such-page\.js - Failed to load resource/)) { await Promise.all(
foundLog = true links.map(async element => {
} const href = await element.getAttribute('href')
expect(href).not.toMatch(/\?ts=/)
})
)
const scripts = await browser.elementsByCss('script[src]')
await Promise.all(
scripts.map(async element => {
const src = await element.getAttribute('src')
expect(src).not.toMatch(/\?ts=/)
})
)
await browser.close()
}) })
expect(foundLog).toBe(true)
// When we go to the 404 page, it'll do a hard reload. it('should reload the page on page script error with prefetch', async () => {
// So, it's possible for the front proxy to load a page from another zone. const browser = await webdriver(appPort, '/counter')
// Since the page is reloaded, when we go back to the counter page again, if (global.browserName !== 'chrome') return
// previous counter value should be gone. const counter = await browser
const counterAfter404Page = await browser .elementByCss('#increase')
.elementByCss('#no-such-page-prefetch') .click()
.click() .click()
.waitForElementByCss('h1') .elementByCss('#counter')
.back() .text()
.waitForElementByCss('#counter-page') expect(counter).toBe('Counter: 2')
.elementByCss('#counter')
.text() // Let the browser to prefetch the page and error it on the console.
expect(counterAfter404Page).toBe('Counter: 0') await waitFor(3000)
const browserLogs = await browser.log('browser')
let foundLog = false
browserLogs.forEach(log => {
if (
log.message.match(/\/no-such-page\.js - Failed to load resource/)
) {
foundLog = true
}
})
expect(foundLog).toBe(true)
// When we go to the 404 page, it'll do a hard reload.
// So, it's possible for the front proxy to load a page from another zone.
// Since the page is reloaded, when we go back to the counter page again,
// previous counter value should be gone.
const counterAfter404Page = await browser
.elementByCss('#no-such-page-prefetch')
.click()
.waitForElementByCss('h1')
.back()
.waitForElementByCss('#counter-page')
.elementByCss('#counter')
.text()
expect(counterAfter404Page).toBe('Counter: 0')
await browser.close() await browser.close()
}) })
}
}) })
it('should not expose the compiled page file in development', async () => { it('should not expose the compiled page file in development', async () => {
......
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