Skip to content

Commit

Permalink
Refactor development-logs removing duplicated code.
Browse files Browse the repository at this point in the history
  • Loading branch information
leitea-google committed Aug 12, 2021
1 parent 1552b83 commit 8cca27a
Showing 1 changed file with 15 additions and 44 deletions.
59 changes: 15 additions & 44 deletions test/integration/basic/test/development-logs.js
Expand Up @@ -2,66 +2,37 @@
import webdriver from 'next-webdriver'

export default (context) => {
describe('Development Logs', () => {
it('should warn when prefetch is true', async () => {
let browser
async function getLogs$(path) {
let foundLog = false
let browser
try {
browser = await webdriver(context.appPort, '/development-logs')
browser = await webdriver(context.appPort, path)
const browserLogs = await browser.log('browser')
let foundLog = false

browserLogs.forEach((log) => {
if (log.message.includes('Next.js auto-prefetches automatically')) {
foundLog = true
}
})
expect(foundLog).toBe(true)
} finally {
if (browser) {
await browser.close()
}
}
return foundLog
}
describe('Development Logs', () => {
it('should warn when prefetch is true', async () => {
const foundLog = await getLogs$('/development-logs')
expect(foundLog).toBe(true)
})
it('should not warn when prefetch is false', async () => {
let browser
try {
browser = await webdriver(
context.appPort,
'/development-logs/link-with-prefetch-false'
)
const browserLogs = await browser.log('browser')
let found = false
browserLogs.forEach((log) => {
if (log.message.includes('Next.js auto-prefetches automatically')) {
found = true
}
})
expect(found).toBe(false)
} finally {
if (browser) {
await browser.close()
}
}
const foundLog = await getLogs$('/development-logs/link-with-prefetch-false')
expect(foundLog).toBe(false)
})
it('should not warn when prefetch is not specified', async () => {
let browser
try {
browser = await webdriver(
context.appPort,
'/development-logs/link-with-no-prefetch'
)
const browserLogs = await browser.log('browser')
let found = false
browserLogs.forEach((log) => {
if (log.message.includes('Next.js auto-prefetches automatically')) {
found = true
}
})
expect(found).toBe(false)
} finally {
if (browser) {
await browser.close()
}
}
const foundLog = await getLogs$('/development-logs/link-with-no-prefetch')
expect(foundLog).toBe(false)
})
})
}

0 comments on commit 8cca27a

Please sign in to comment.