Unverified Commit 338307cd authored by Gal Schlezinger's avatar Gal Schlezinger Committed by GitHub

Fix global process testing for the process polyfill (#33220)

When there is a DOM element with id of `process`, the DOM marks it as a global, so `window.process` would exist. We should check for `process.env` to make sure it is available too.
parent 1f685ae5
module.exports = global.process || require('../../compiled/process') module.exports =
global.process?.env && typeof global.process?.env === 'object'
? global.process
: require('../../compiled/process')
export default function Page() {
return (
<div id="process">
Hello, {process.env.NEXT_PUBLIC_VISITOR ?? 'stranger'}
</div>
)
}
...@@ -36,9 +36,18 @@ describe('Polyfills', () => { ...@@ -36,9 +36,18 @@ describe('Polyfills', () => {
await browser.close() await browser.close()
}) })
it('should allow using process.env when there is an element with `id` of `process`', async () => {
const browser = await webdriver(appPort, '/process')
const text = await browser.elementByCss('#process').text()
expect(text).toBe('Hello, stranger')
await browser.close()
})
it('should contain generated page count in output', async () => { it('should contain generated page count in output', async () => {
expect(output).toContain('Generating static pages (0/4)') expect(output).toContain('Generating static pages (0/5)')
expect(output).toContain('Generating static pages (4/4)') expect(output).toContain('Generating static pages (5/5)')
// we should only have 1 segment and the initial message logged out // we should only have 1 segment and the initial message logged out
expect(output.match(/Generating static pages/g).length).toBe(5) expect(output.match(/Generating static pages/g).length).toBe(5)
}) })
......
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