Skip to content

Commit c99bf67

Browse files
authored
Fix env-config tests for Turbopack (vercel#61503)
## What? This test was checking internals, specifically the written files. I've refactored it to only depend on page in the application itself, the functionality worked fine already in Turbopack. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # --> Closes NEXT-2325
1 parent ffd5732 commit c99bf67

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import { useEffect, useState } from 'react'
12
export default function Page() {
2-
return <p>{process.env.NEXT_PUBLIC_TEST_DEST}</p>
3+
const [path, setPath] = useState(null)
4+
useEffect(() => {
5+
setPath(process.env.NEXT_PUBLIC_TEST_DEST)
6+
}, [])
7+
return path ? <p id="global-value">{path}</p> : <p>Waiting </p>
38
}

test/integration/env-config/test/index.test.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,11 @@ const runTests = (mode = 'dev', didReload = false) => {
8686
})
8787

8888
it('should inline global values during build', async () => {
89-
// make sure to build page
90-
await renderViaHTTP(appPort, '/global')
89+
const browser = await webdriver(appPort, '/global')
9190

92-
const buildManifest = require(join(
93-
__dirname,
94-
'../app/.next/build-manifest.json'
95-
))
96-
97-
const pageFile = buildManifest.pages['/global'].find((filename) =>
98-
filename.includes('pages/global')
99-
)
100-
101-
// read client bundle contents since a server side render can
102-
// have the value available during render but it not be injected
103-
const bundleContent = await fs.readFile(
104-
join(appDir, '.next', pageFile),
105-
'utf8'
91+
expect(await browser.waitForElementByCss('#global-value').text()).toBe(
92+
'another'
10693
)
107-
expect(bundleContent).toContain('another')
10894
})
10995

11096
it('should provide env for SSG', async () => {
@@ -295,7 +281,9 @@ describe('Env Config', () => {
295281

296282
try {
297283
const browser = await webdriver(appPort, '/global')
298-
expect(await browser.elementByCss('p').text()).toBe('another')
284+
expect(
285+
await browser.waitForElementByCss('#global-value').text()
286+
).toBe('another')
299287

300288
let outputIdx = output.length
301289

@@ -313,7 +301,10 @@ describe('Env Config', () => {
313301
).toBe(1)
314302
expect(output.substring(outputIdx)).not.toContain('.env.local')
315303

316-
await check(() => browser.elementByCss('p').text(), 'replaced')
304+
await check(
305+
() => browser.waitForElementByCss('#global-value').text(),
306+
'replaced'
307+
)
317308

318309
outputIdx = output.length
319310

@@ -328,7 +319,10 @@ describe('Env Config', () => {
328319
).toBe(1)
329320
expect(output.substring(outputIdx)).toContain('.env.local')
330321

331-
await check(() => browser.elementByCss('p').text(), 'overridden')
322+
await check(
323+
() => browser.waitForElementByCss('#global-value').text(),
324+
'overridden'
325+
)
332326

333327
outputIdx = output.length
334328

test/turbopack-tests-manifest.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9059,13 +9059,12 @@
90599059
"Env Config test environment should provide env correctly for API routes",
90609060
"Env Config test environment should provide env correctly for SSR",
90619061
"Env Config test environment should provide env for SSG",
9062-
"Env Config test environment should provide global env to next.config.js"
9063-
],
9064-
"failed": [
9062+
"Env Config test environment should provide global env to next.config.js",
90659063
"Env Config dev mode should inline global values during build",
90669064
"Env Config dev mode with hot reload should inline global values during build",
90679065
"Env Config test environment should inline global values during build"
90689066
],
9067+
"failed": [],
90699068
"pending": [
90709069
"Env Config production mode should have process environment override .env",
90719070
"Env Config production mode should inline global values during build",

0 commit comments

Comments
 (0)