forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AMP validation on export (vercel#6794)
* Add err.sh link and pool validation results to wait to show error until export is finished * Fix wording in amp-export-validation err.sh * Update validation error message Co-Authored-By: ijjk <[email protected]> * Update ways to fix text Co-Authored-By: ijjk <[email protected]> * Update why the error occurred wording Co-Authored-By: ijjk <[email protected]> * Update wording some more Co-Authored-By: ijjk <[email protected]>
- Loading branch information
Showing
9 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# AMP Export Validation | ||
|
||
#### Why This Error Occurred | ||
|
||
During export we validate AMP pages using [amphtml-validator](https://www.npmjs.com/package/amphtml-validator). Errors received from the validator will fail the export. | ||
|
||
Validation errors will cause pages to not be [indexed by AMP Caches](https://www.ampproject.org/docs/fundamentals/how_cached). | ||
|
||
#### Possible Ways to Fix It | ||
|
||
Look at the error messages and follow their appropriate links to learn more about the error and how to correct the problem. | ||
|
||
### Useful Links | ||
|
||
- [AMP HTML Specification](https://www.ampproject.org/docs/fundamentals/spec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
// exportPathMap | ||
experimental: { | ||
amp: true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default () => ( | ||
<div> | ||
{/* I show a warning since the amp-video script isn't added */} | ||
<amp-video src='/cats.mp4' height={400} width={800} /> | ||
</div> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default () => ( | ||
<div> | ||
{/* I throw an error since <amp-img/> should be used instead */} | ||
<img src='/dog.gif' height={400} width={800} /> | ||
{/* I show a warning since the amp-video script isn't added */} | ||
<amp-video src='/cats.mp4' height={400} width={800} /> | ||
</div> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default () => ( | ||
<div> | ||
{/* I throw an error since <amp-img/> should be used instead */} | ||
<img src='/dog.gif' height={400} width={800} /> | ||
</div> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import fs from 'fs' | ||
import { join } from 'path' | ||
import { promisify } from 'util' | ||
import { | ||
File, | ||
nextBuild, | ||
runNextCommand | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 | ||
const access = promisify(fs.access) | ||
const appDir = join(__dirname, '../') | ||
const outDir = join(appDir, 'out') | ||
const nextConfig = new File(join(appDir, 'next.config.js')) | ||
|
||
describe('AMP Validation on Export', () => { | ||
beforeAll(() => nextBuild(appDir)) | ||
|
||
it('shows AMP warning without throwing error', async () => { | ||
nextConfig.replace('// exportPathMap', | ||
`exportPathMap: function(defaultMap) { | ||
return { | ||
'/cat': defaultMap['/cat.amp'], | ||
} | ||
},`) | ||
|
||
let stdout = '' | ||
try { | ||
await runNextCommand(['export', appDir], { | ||
instance: child => { | ||
child.stdout.on('data', chunk => { | ||
stdout += chunk.toString() | ||
}) | ||
} | ||
}) | ||
expect(stdout).toMatch(/warn.*The tag 'amp-video extension \.js script' is missing/) | ||
await expect(access(join(outDir, 'cat/index.html'))).resolves.toBe(undefined) | ||
} finally { | ||
nextConfig.restore() | ||
} | ||
}) | ||
|
||
it('throws error on AMP error', async () => { | ||
nextConfig.replace('// exportPathMap', | ||
`exportPathMap: function(defaultMap) { | ||
return { | ||
'/dog': defaultMap['/dog.amp'], | ||
} | ||
},`) | ||
|
||
let stdout = '' | ||
try { | ||
await runNextCommand(['export', appDir], { | ||
instance: child => { | ||
child.stdout.on('data', chunk => { | ||
stdout += chunk.toString() | ||
}) | ||
} | ||
}) | ||
expect(stdout).toMatch(/error.*The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'\?/) | ||
await expect(access(join(outDir, 'dog/index.html'))).resolves.toBe(undefined) | ||
} finally { | ||
nextConfig.restore() | ||
} | ||
}) | ||
|
||
it('shows warning and error when throwing error', async () => { | ||
nextConfig.replace('// exportPathMap', | ||
`exportPathMap: function(defaultMap) { | ||
return { | ||
'/dog-cat': defaultMap['/dog-cat.amp'], | ||
} | ||
},`) | ||
|
||
let stdout = '' | ||
try { | ||
await runNextCommand(['export', appDir], { | ||
instance: child => { | ||
child.stdout.on('data', chunk => { | ||
stdout += chunk.toString() | ||
}) | ||
} | ||
}) | ||
expect(stdout).toMatch(/warn.*The tag 'amp-video extension \.js script' is missing/) | ||
expect(stdout).toMatch(/error.*The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'\?/) | ||
await expect(access(join(outDir, 'dog-cat/index.html'))).resolves.toBe(undefined) | ||
} finally { | ||
nextConfig.restore() | ||
} | ||
}) | ||
}) |