Skip to content

Commit

Permalink
Re-enable fetch logging test - HMR (vercel#72640)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaojude authored Nov 13, 2024
1 parent c1377b4 commit 171970d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
1 change: 1 addition & 0 deletions test/development/acceptance-app/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
const { next, isTurbopack } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true,
patchFileDelay: 1000,
})

test('should strip whitespace correctly with newline', async () => {
Expand Down
62 changes: 41 additions & 21 deletions test/e2e/app-dir/logging/fetch-logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'fs'
import stripAnsi from 'strip-ansi'
import { retry } from 'next-test-utils'
import { nextTestSetup } from 'e2e-utils'
import { sandbox } from 'development-sandbox'

const cacheReasonRegex = /Cache (missed|skipped) reason: /

Expand Down Expand Up @@ -43,6 +44,46 @@ function parseLogsFromCli(cliOutput: string) {
}, [])
}

describe('app-dir - fetch logging', () => {
const { next, isNextDev } = nextTestSetup({
skipDeployment: true,
files: __dirname,
})

isNextDev &&
it('should not log requests for HMR refreshes', async () => {
const { browser, cleanup, session } = await sandbox(
next,
undefined,
'/fetch-no-store'
)

let headline = await browser.waitForElementByCss('h1').text()
expect(headline).toBe('Hello World!')
const outputIndex = next.cliOutput.length

await session.patch('app/fetch-no-store/page.js', (content) =>
content.replace('Hello World!', 'Hello Test!')
)

await retry(async () => {
headline = await browser.waitForElementByCss('h1').text()
expect(headline).toBe('Hello Test!')
const logs = stripAnsi(next.cliOutput.slice(outputIndex))
expect(logs).toInclude(' GET /fetch-no-store')
expect(logs).not.toInclude(` │ GET `)
// TODO: remove custom duration in case we increase the default.
}, 5000)

await cleanup()
})

// TODO: remove when there is a test for isNextDev === false
it('placeholder to satisfy at least one test when isNextDev is false', async () => {
expect(true).toBe(true)
})
})

// TODO: this test has been quite flaky, so we are skipping it for now
// will rewrite it later
describe.skip('app-dir - logging', () => {
Expand Down Expand Up @@ -228,27 +269,6 @@ describe.skip('app-dir - logging', () => {
})
})

it('should not log requests for HMR refreshes', async () => {
const browser = await next.browser('/fetch-no-store')
let headline = await browser.waitForElementByCss('h1').text()
expect(headline).toBe('Hello World!')
const outputIndex = next.cliOutput.length

await next.patchFile(
'app/fetch-no-store/page.js',
(content) => content.replace('Hello World!', 'Hello Test!'),
async () =>
retry(async () => {
headline = await browser.waitForElementByCss('h1').text()
expect(headline).toBe('Hello Test!')
const logs = stripAnsi(next.cliOutput.slice(outputIndex))
expect(logs).toInclude(' GET /fetch-no-store')
expect(logs).not.toInclude(` │ GET `)
// TODO: remove custom duration in case we increase the default.
}, 5000)
)
})

describe('when logging.fetches.hmrRefreshes is true', () => {
beforeAll(async () => {
await next.patchFile('next.config.js', (content) =>
Expand Down

0 comments on commit 171970d

Please sign in to comment.