Unverified Commit 4c05de3c authored by Juny's avatar Juny Committed by GitHub

fix amp validator message format (#31018)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

fixes https://github.com/vercel/next.js/issues/31012

I referred to the previous code.

```
    if (errors == null) {
      if (Object.keys(amp).length > 0) {
        warnings = (warnings || []).concat(formatAmpMessages(amp) || [])
        if (!warnings.length) warnings = null
      }
    }
```

https://github.com/vercel/next.js/pull/29753/files
parent e9e8e8b4
......@@ -181,8 +181,7 @@ buildStore.subscribe((state) => {
...(client.warnings || []),
...(server.warnings || []),
...((serverWeb && serverWeb.warnings) || []),
...((Object.keys(amp).length > 0 && formatAmpMessages(amp)) || []),
]
].concat(formatAmpMessages(amp) || [])
consoleStore.setState(
{
......
export const config = { amp: true }
export default function Page() {
return (
<div>
<p id="invalid-amp">Invalid AMP Page</p>
<img src="/images/test.png"></img>
</div>
)
}
......@@ -257,6 +257,9 @@ describe('AMP Usage', () => {
onStdout(msg) {
inspectPayload += msg
},
onStderr(msg) {
inspectPayload += msg
},
})
await renderViaHTTP(dynamicAppPort, '/only-amp')
......@@ -518,6 +521,26 @@ describe('AMP Usage', () => {
}
})
it('should detect amp validator warning on invalid amp', async () => {
let inspectPayload = ''
dynamicAppPort = await findPort()
ampDynamic = await launchApp(join(__dirname, '../'), dynamicAppPort, {
onStdout(msg) {
inspectPayload += msg
},
onStderr(msg) {
inspectPayload += msg
},
})
await renderViaHTTP(dynamicAppPort, '/invalid-amp')
await killApp(ampDynamic)
expect(inspectPayload).toContain('warn')
expect(inspectPayload).toContain('error')
})
it('should not contain missing files warning', async () => {
expect(output).toContain('compiled client and server successfully')
expect(output).toContain('compiling /only-amp')
......
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