Commit f4bc5c26 authored by Tobias Koppers's avatar Tobias Koppers

Skip get_compilation_issues tests in webpack mode

The tool is Turbopack-only; wrapping the suite in the
`IS_TURBOPACK_TEST ? describe : describe.skip` pattern ensures CI
doesn't run it in the webpack dev job where the endpoint state is
unavailable.
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent 3ebfe319
......@@ -2,94 +2,100 @@ import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { retry } from 'next-test-utils'
describe('mcp-server get_compilation_issues tool', () => {
const { next, skipped } = nextTestSetup({
files: new FileRef(
path.join(__dirname, 'fixtures', 'compilation-issues-app')
),
skipDeployment: true,
})
if (skipped) {
return
}
async function callGetCompilationIssues(): Promise<string> {
const response = await fetch(`${next.url}/_next/mcp`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json, text/event-stream',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: `test-${Date.now()}`,
method: 'tools/call',
params: { name: 'get_compilation_issues', arguments: {} },
}),
// get_compilation_issues is Turbopack-only (requires live endpoint state)
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)(
'mcp-server get_compilation_issues tool',
() => {
const { next, skipped } = nextTestSetup({
files: new FileRef(
path.join(__dirname, 'fixtures', 'compilation-issues-app')
),
skipDeployment: true,
})
const text = await response.text()
const match = text.match(/data: ({.*})/s)
const result = JSON.parse(match![1])
return result.result?.content?.[0]?.text
}
if (skipped) {
return
}
it('should return empty issues for a page with no errors', async () => {
await next.browser('/')
async function callGetCompilationIssues(): Promise<string> {
const response = await fetch(`${next.url}/_next/mcp`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json, text/event-stream',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: `test-${Date.now()}`,
method: 'tools/call',
params: { name: 'get_compilation_issues', arguments: {} },
}),
})
let response: any = null
await retry(async () => {
const responseText = await callGetCompilationIssues()
response = JSON.parse(responseText)
// The '/page' route should be present once the page has been compiled
expect(response.routes).toHaveProperty('/page')
})
const text = await response.text()
const match = text.match(/data: ({.*})/s)
const result = JSON.parse(match![1])
return result.result?.content?.[0]?.text
}
expect(response.routes['/page'].issues).toEqual([])
})
it('should return empty issues for a page with no errors', async () => {
await next.browser('/')
it('should return compilation issues for a page with a syntax error', async () => {
await next.browser('/broken')
let response: any = null
await retry(async () => {
const responseText = await callGetCompilationIssues()
response = JSON.parse(responseText)
// The '/page' route should be present once the page has been compiled
expect(response.routes).toHaveProperty('/page')
})
let response: any = null
await retry(async () => {
const responseText = await callGetCompilationIssues()
response = JSON.parse(responseText)
expect(response.routes['/broken/page']?.issues?.length).toBeGreaterThan(0)
expect(response.routes['/page'].issues).toEqual([])
})
const issue = response.routes['/broken/page'].issues[0]
expect(issue).toMatchObject({
severity: 'error',
filePath: expect.stringContaining('broken/page.tsx'),
})
})
it('should return compilation issues for a page with a syntax error', async () => {
await next.browser('/broken')
it('should reflect fixed issues after the file is patched', async () => {
await next.browser('/broken')
let response: any = null
await retry(async () => {
const responseText = await callGetCompilationIssues()
response = JSON.parse(responseText)
expect(response.routes['/broken/page']?.issues?.length).toBeGreaterThan(
0
)
})
// Confirm there are issues before patching
await retry(async () => {
const resp = JSON.parse(await callGetCompilationIssues())
expect(resp.routes['/broken/page']?.issues?.length).toBeGreaterThan(0)
const issue = response.routes['/broken/page'].issues[0]
expect(issue).toMatchObject({
severity: 'error',
filePath: expect.stringContaining('broken/page.tsx'),
})
})
// Patch the broken page to a valid implementation
await next.patchFile(
'app/broken/page.tsx',
`export default function BrokenPage() {
it('should reflect fixed issues after the file is patched', async () => {
await next.browser('/broken')
// Confirm there are issues before patching
await retry(async () => {
const resp = JSON.parse(await callGetCompilationIssues())
expect(resp.routes['/broken/page']?.issues?.length).toBeGreaterThan(0)
})
// Patch the broken page to a valid implementation
await next.patchFile(
'app/broken/page.tsx',
`export default function BrokenPage() {
return <div>Fixed</div>
}`
)
)
// After the fix, the issues for '/broken/page' should be empty
await retry(async () => {
const resp = JSON.parse(await callGetCompilationIssues())
expect(
resp.routes['/broken/page'] == null ||
resp.routes['/broken/page'].issues.length === 0
).toBe(true)
// After the fix, the issues for '/broken/page' should be empty
await retry(async () => {
const resp = JSON.parse(await callGetCompilationIssues())
expect(
resp.routes['/broken/page'] == null ||
resp.routes['/broken/page'].issues.length === 0
).toBe(true)
})
})
})
})
}
)
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