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', () => {
}
})
it('should add prefetch tags when Link prefetch prop is used', async () => {
const browser = await webdriver(appPort, '/prefetch')
await waitFor(2000)
const elements = await browser.elementsByCss('link[rel=prefetch]')
expect(elements.length).toBe(4)
await Promise.all(
elements.map(async element => {
const rel = await element.getAttribute('rel')
const as = await element.getAttribute('as')
expect(rel).toBe('prefetch')
expect(as).toBe('script')
})
)
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')
if (browserName === 'chrome') {
it('should add prefetch tags when Link prefetch prop is used', async () => {
const browser = await webdriver(appPort, '/prefetch')
await waitFor(2000)
const elements = await browser.elementsByCss('link[rel=prefetch]')
expect(elements.length).toBe(4)
await Promise.all(
elements.map(async element => {
const rel = await element.getAttribute('rel')
const as = await element.getAttribute('as')
expect(rel).toBe('prefetch')
expect(as).toBe('script')
})
)
await browser.close()
})
// Let the browser to prefetch the page and error it on the console.
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
}
// 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()
})
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')
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.
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 () => {
......
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