Unverified Commit 20e4a504 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add more export tests for AMP (#6740)

* Add more export tests for AMP

* Remove console.log
Co-Authored-By: 's avatarijjk <22380829+ijjk@users.noreply.github.com>

* remove extra line
Co-Authored-By: 's avatarijjk <22380829+ijjk@users.noreply.github.com>
parent 773a3a21
...@@ -6,6 +6,7 @@ import { resolve, join } from 'path' ...@@ -6,6 +6,7 @@ import { resolve, join } from 'path'
import { existsSync, readFileSync } from 'fs' import { existsSync, readFileSync } from 'fs'
import loadConfig from 'next-server/next-config' import loadConfig from 'next-server/next-config'
import { tryAmp } from 'next-server/dist/server/require' import { tryAmp } from 'next-server/dist/server/require'
import { cleanAmpPath } from 'next-server/dist/server/utils'
import { PHASE_EXPORT, SERVER_DIRECTORY, PAGES_MANIFEST, CONFIG_FILE, BUILD_ID_FILE, CLIENT_STATIC_FILES_PATH } from 'next-server/constants' import { PHASE_EXPORT, SERVER_DIRECTORY, PAGES_MANIFEST, CONFIG_FILE, BUILD_ID_FILE, CLIENT_STATIC_FILES_PATH } from 'next-server/constants'
import createProgress from 'tty-aware-progress' import createProgress from 'tty-aware-progress'
import { promisify } from 'util' import { promisify } from 'util'
...@@ -58,7 +59,8 @@ export default async function (dir, options, configuration) { ...@@ -58,7 +59,8 @@ export default async function (dir, options, configuration) {
if (isAmp) { if (isAmp) {
defaultPathMap[path].query = { amp: 1 } defaultPathMap[path].query = { amp: 1 }
if (!defaultPathMap[path.split('.amp')[0]]) { const nonAmp = cleanAmpPath(path).replace(/\/$/, '')
if (!defaultPathMap[nonAmp]) {
defaultPathMap[path].query.ampOnly = true defaultPathMap[path].query.ampOnly = true
} }
} else { } else {
......
...@@ -47,6 +47,9 @@ process.on( ...@@ -47,6 +47,9 @@ process.on(
path = cleanAmpPath(path) path = cleanAmpPath(path)
} }
// replace /docs/index.amp with /docs.amp
path = path.replace(/(?<!^)\/index\.amp$/, '.amp')
let htmlFilename = `${path}${sep}index.html` let htmlFilename = `${path}${sep}index.html`
const pageExt = extname(page) const pageExt = extname(page)
const pathExt = extname(path) const pathExt = extname(path)
......
export default () => ( export { default } from './index'
<p>I'm an AMP page</p>
)
import { useAmp } from 'next/amp'
export default () => (
<p>I'm an {useAmp() ? 'AMP' : 'normal'} page</p>
)
import { useAmp } from 'next/amp'
export default () => (
<p>I'm an {useAmp() ? 'AMP' : 'normal'} page</p>
)
export default () => (
<p>I am an AMP only page</p>
)
...@@ -34,4 +34,16 @@ describe('Export with default map', () => { ...@@ -34,4 +34,16 @@ describe('Export with default map', () => {
await expect(access(join(outdir, 'some/index.html'))).resolves.toBe(undefined) await expect(access(join(outdir, 'some/index.html'))).resolves.toBe(undefined)
await expect(access(join(outdir, 'some.amp/index.html'))).resolves.toBe(undefined) await expect(access(join(outdir, 'some.amp/index.html'))).resolves.toBe(undefined)
}) })
it('should export nested hybrid amp page correctly', async () => {
expect.assertions(2)
await expect(access(join(outdir, 'docs/index.html'))).resolves.toBe(undefined)
await expect(access(join(outdir, 'docs.amp/index.html'))).resolves.toBe(undefined)
})
it('should export nested hybrid amp page correctly with folder', async () => {
expect.assertions(2)
await expect(access(join(outdir, 'info/index.html'))).resolves.toBe(undefined)
await expect(access(join(outdir, 'info.amp/index.html'))).resolves.toBe(undefined)
})
}) })
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