-
Notifications
You must be signed in to change notification settings - Fork 451
fix: stabilize integration test suite #8209
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ site/src/**/*.md | |
| .verdaccio-storage | ||
| .eslintcache | ||
| _test_out/** | ||
| tests/unit/utils/tmp | ||
| *.crt | ||
| *.key | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,6 @@ | ||||||||||||||||||||||
| import { readFile, writeFile } from 'fs/promises' | ||||||||||||||||||||||
| import { join } from 'path' | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import getPort from 'get-port' | ||||||||||||||||||||||
| import fetch from 'node-fetch' | ||||||||||||||||||||||
| import { describe, expect, test } from 'vitest' | ||||||||||||||||||||||
|
|
@@ -32,27 +35,46 @@ describe('redirects', async () => { | |||||||||||||||||||||
| }) | ||||||||||||||||||||||
| }) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| await setupFixtureTests('next-app', { devServer: { env: { NETLIFY_DEV_SERVER_CHECK_SSG_ENDPOINTS: 1 } } }, () => { | ||||||||||||||||||||||
| test<FixtureTestContext>('should prefer local files instead of redirect when not forced', async ({ devServer }) => { | ||||||||||||||||||||||
| const response = await fetch(`http://localhost:${devServer!.port}/test.txt`, {}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| expect(response.status).toBe(200) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const result = await response.text() | ||||||||||||||||||||||
| expect(result.trim()).toEqual('hello world') | ||||||||||||||||||||||
| }) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| test<FixtureTestContext>('should check for the dynamic page existence before doing redirect', async ({ | ||||||||||||||||||||||
| devServer, | ||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||
| const response = await fetch(`http://localhost:${devServer!.port}/`, {}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| expect(response.status).toBe(200) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const result = await response.text() | ||||||||||||||||||||||
| expect(result.toLowerCase()).not.toContain('netlify') | ||||||||||||||||||||||
| }) | ||||||||||||||||||||||
| }) | ||||||||||||||||||||||
| await setupFixtureTests( | ||||||||||||||||||||||
| 'next-app', | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| devServer: { env: { NETLIFY_DEV_SERVER_CHECK_SSG_ENDPOINTS: 1 } }, | ||||||||||||||||||||||
| setup: async ({ fixture }) => { | ||||||||||||||||||||||
| const targetPort = await getPort() | ||||||||||||||||||||||
| const packageJsonPath = join(fixture.directory, 'package.json') | ||||||||||||||||||||||
| const netlifyTomlPath = join(fixture.directory, 'netlify.toml') | ||||||||||||||||||||||
| const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8')) as { scripts: { dev: string } } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| packageJson.scripts.dev = `next dev -p ${targetPort.toString()}` | ||||||||||||||||||||||
| await writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`) | ||||||||||||||||||||||
| await writeFile( | ||||||||||||||||||||||
| netlifyTomlPath, | ||||||||||||||||||||||
| (await readFile(netlifyTomlPath, 'utf8')).replace('targetPort = 6123', `targetPort = ${targetPort.toString()}`), | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
Comment on lines
+50
to
+55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fragile string replace — silently no-ops if
🛠️ Suggested fix: assert the replacement happened (or use a regex with a post-check)- await writeFile(
- netlifyTomlPath,
- (await readFile(netlifyTomlPath, 'utf8')).replace('targetPort = 6123', `targetPort = ${targetPort.toString()}`),
- )
+ const originalToml = await readFile(netlifyTomlPath, 'utf8')
+ const updatedToml = originalToml.replace(/targetPort\s*=\s*\d+/, `targetPort = ${targetPort.toString()}`)
+ if (updatedToml === originalToml) {
+ throw new Error(`Failed to substitute targetPort in ${netlifyTomlPath}`)
+ }
+ await writeFile(netlifyTomlPath, updatedToml)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| () => { | ||||||||||||||||||||||
| test<FixtureTestContext>('should prefer local files instead of redirect when not forced', async ({ devServer }) => { | ||||||||||||||||||||||
| const response = await fetch(`http://localhost:${devServer!.port}/test.txt`, {}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| expect(response.status).toBe(200) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const result = await response.text() | ||||||||||||||||||||||
| expect(result.trim()).toEqual('hello world') | ||||||||||||||||||||||
| }) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| test<FixtureTestContext>('should check for the dynamic page existence before doing redirect', async ({ | ||||||||||||||||||||||
| devServer, | ||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||
| const response = await fetch(`http://localhost:${devServer!.port}/`, {}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| expect(response.status).toBe(200) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const result = await response.text() | ||||||||||||||||||||||
| expect(result.toLowerCase()).not.toContain('netlify') | ||||||||||||||||||||||
| }) | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| test('should not check the endpoint existence for hidden proxies', async (t) => { | ||||||||||||||||||||||
| await withSiteBuilder(t, async (builder) => { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Env value should be a string for consistency and to match
NodeJS.ProcessEnvtyping.Line 122 of this same file uses
NETLIFY_DEV_SERVER_CHECK_SSG_ENDPOINTS: '1'. Node coerces numeric values at spawn time, but TS'sProcessEnvtype expects strings and downstream code typically does strict equality against'1'.📝 Committable suggestion
🤖 Prompt for AI Agents