-
Notifications
You must be signed in to change notification settings - Fork 457
chore: 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 all commits
33a36d2
1a263ab
a8f885f
5476051
42642f6
b3f369f
60d6c8a
91b1d39
c48bc05
678f748
a95c20e
236e745
2077c6f
7c3f178
ed55775
1e7c583
08f0ec1
56af0b7
fb18cdc
05ea557
7b862e0
d774b94
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,50 @@ 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 } }, | ||||||||||||||||||||||
|
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. Env value should be a string for consistency and to match Line 122 of this same file uses - devServer: { env: { NETLIFY_DEV_SERVER_CHECK_SSG_ENDPOINTS: 1 } },
+ devServer: { env: { NETLIFY_DEV_SERVER_CHECK_SSG_ENDPOINTS: '1' } },📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| 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.
IIRC
isCIalready checksCIenv var as part of its checks, so I am not sure if this actually does anything? Ref https://github.com/watson/ci-info/blob/c4e1d0565552fb20ea3c133db2e056a574e78e6b/test.js#L59-L65