Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor development-logs removing duplicated code. #28049

Merged
merged 6 commits into from Aug 13, 2021
81 changes: 27 additions & 54 deletions test/integration/basic/test/development-logs.js
Expand Up @@ -2,66 +2,39 @@
import webdriver from 'next-webdriver'

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

browserLogs.forEach((log) => {
if (log.message.includes('Next.js auto-prefetches automatically')) {
foundLog = 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)
})
})
}