Commit 5a48272a authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Fix amphtml href with nested amp page (#6741)

* Add more export tests for AMP

* Make sure ampPath is correct when nested

* Remove console.log
parent 19f39511
...@@ -66,7 +66,7 @@ export default async function (dir, options, configuration) { ...@@ -66,7 +66,7 @@ export default async function (dir, options, configuration) {
} else { } else {
const ampPath = tryAmp(defaultPathMap, path) const ampPath = tryAmp(defaultPathMap, path)
if (ampPath !== path) { if (ampPath !== path) {
defaultPathMap[path].query = { hasAmp: true, ampPath } defaultPathMap[path].query = { hasAmp: true, ampPath: ampPath.replace(/(?<!^)\/index\.amp$/, '.amp') }
} }
} }
}) })
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
/* global jasmine */ /* global jasmine */
import fs from 'fs' import fs from 'fs'
import { join } from 'path' import { join } from 'path'
import cheerio from 'cheerio'
import { promisify } from 'util' import { promisify } from 'util'
import { import {
nextBuild, nextBuild,
...@@ -9,6 +10,7 @@ import { ...@@ -9,6 +10,7 @@ import {
} from 'next-test-utils' } from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
const readFile = promisify(fs.readFile)
const access = promisify(fs.access) const access = promisify(fs.access)
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
const outdir = join(appDir, 'out') const outdir = join(appDir, 'out')
...@@ -36,14 +38,22 @@ describe('Export with default map', () => { ...@@ -36,14 +38,22 @@ describe('Export with default map', () => {
}) })
it('should export nested hybrid amp page correctly', async () => { it('should export nested hybrid amp page correctly', async () => {
expect.assertions(2) expect.assertions(3)
await expect(access(join(outdir, 'docs/index.html'))).resolves.toBe(undefined) await expect(access(join(outdir, 'docs/index.html'))).resolves.toBe(undefined)
await expect(access(join(outdir, 'docs.amp/index.html'))).resolves.toBe(undefined) await expect(access(join(outdir, 'docs.amp/index.html'))).resolves.toBe(undefined)
const html = await readFile(join(outdir, 'docs/index.html'))
const $ = cheerio.load(html)
expect($('link[rel=amphtml]').attr('href')).toBe('/docs.amp')
}) })
it('should export nested hybrid amp page correctly with folder', async () => { it('should export nested hybrid amp page correctly with folder', async () => {
expect.assertions(2) expect.assertions(3)
await expect(access(join(outdir, 'info/index.html'))).resolves.toBe(undefined) await expect(access(join(outdir, 'info/index.html'))).resolves.toBe(undefined)
await expect(access(join(outdir, 'info.amp/index.html'))).resolves.toBe(undefined) await expect(access(join(outdir, 'info.amp/index.html'))).resolves.toBe(undefined)
const html = await readFile(join(outdir, 'info/index.html'))
const $ = cheerio.load(html)
expect($('link[rel=amphtml]').attr('href')).toBe('/info.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