Unverified Commit e2e19c48 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

test(dev): add dedicated compiler polling coverage (#97673)

### What?

Adds a dedicated development integration test for compiler file watching
in polling mode under both webpack and Turbopack.

It also removes obsolete `CHOKIDAR_USEPOLLING` / `CHOKIDAR_INTERVAL`
variables from the unrelated `read-only-source-hmr` suite, which remains
focused on read-only source semantics and normal watcher behavior.

Stack: **5/5** · Previous: #98737

### Why?

Next.js did not have an e2e/development test dedicated to
`watchOptions.pollIntervalMs`. Existing Rust coverage checks watcher
modes, while the filesystem-watcher fuzzer is manual rather than part of
the normal development-test matrix.

The test also regresses notify-rs/notify#981. Older PollWatcher versions
stored ordinary-file mtimes at whole-second precision, so a second edit
in the same second compared equal and was permanently dropped. The
preceding stack layer upgrades to `notify 9.0.0-rc.5`, which preserves
nanosecond precision for regular files without content hashing.

### How?

The dedicated pages-directory fixture configures only
`watchOptions.pollIntervalMs`:

- webpack maps it to compiler `watchOptions.poll`;
- Turbopack passes it to notify and selects PollWatcher.

It intentionally does not set `WATCHPACK_POLLING`, create/delete routes,
or test the dev-server route watcher, keeping the test focused on
compiler-level polling.

The test writes two versions of an already-loaded page with controlled
mtimes at +100 ms and +200 ms inside the same future whole second. It
waits for the first HMR update before making the second write, requiring
two distinct watcher events rather than allowing changes to coalesce.

A negative control with the older npm-provided native binary observes
the first update but permanently misses the second. A fresh local native
build from the full stack passes both updates. The dedicated test and
`read-only-source-hmr` pass under both Turbopack and webpack; Prettier
and ESLint also pass.

<!-- NEXT_JS_LLM -->


<!-- fleet 6488265d-2685-49d3-b632-6511b4b47690 -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
Co-authored-by: 's avatarBenjamin Woodruff ‮ <180404+bgw@users.noreply.github.com>
parent 57ea96fa
......@@ -14,10 +14,6 @@ describe('Read-only source HMR', () => {
skipStart: true,
env: {
__NEXT_TEST_WITH_DEVTOOL: '1',
// Events can be finicky in CI. This switches to a more reliable
// polling method.
CHOKIDAR_USEPOLLING: 'true',
CHOKIDAR_INTERVAL: '500',
},
})
......
/** @type {import('next').NextConfig} */
module.exports = {
watchOptions: {
pollIntervalMs: 500,
},
}
export default function Page() {
return <p>initial</p>
}
import { nextTestSetup } from 'e2e-utils'
import fs from 'fs-extra'
import { retry } from 'next-test-utils'
import path from 'path'
const POLL_INTERVAL_MS = 500
describe('watch polling', () => {
const { next } = nextTestSetup({
files: __dirname,
})
async function writePage(content: string, mtimeMs: number) {
const pagePath = path.join(next.testDir, 'pages/index.tsx')
await fs.writeFile(
pagePath,
`export default function Page() { return <p>${content}</p> }`
)
const mtime = new Date(mtimeMs)
await fs.utimes(pagePath, mtime, mtime)
}
it('detects subsecond changes while polling', async () => {
const browser = await next.browser('/')
expect(await browser.elementByCss('p').text()).toBe('initial')
// PollWatcher used to truncate mtimes to whole seconds. Pin two updates to
// the same future second so this test fails unless their subsecond parts
// are preserved. The first update is observed before the second is made,
// ensuring both watcher events are required.
const sameSecond = Math.ceil(Date.now() / 1000) * 1000 + 10_000
await writePage('first update', sameSecond + 100)
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('first update')
}, POLL_INTERVAL_MS * 20)
await writePage('second update', sameSecond + 200)
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('second update')
}, POLL_INTERVAL_MS * 20)
})
})
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