提交 5a48272a 编写于 作者: J JJ Kasper 提交者: 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
上级 19f39511
......@@ -66,7 +66,7 @@ export default async function (dir, options, configuration) {
} else {
const ampPath = tryAmp(defaultPathMap, 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 @@
/* global jasmine */
import fs from 'fs'
import { join } from 'path'
import cheerio from 'cheerio'
import { promisify } from 'util'
import {
nextBuild,
......@@ -9,6 +10,7 @@ import {
} from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
const readFile = promisify(fs.readFile)
const access = promisify(fs.access)
const appDir = join(__dirname, '../')
const outdir = join(appDir, 'out')
......@@ -36,14 +38,22 @@ describe('Export with default map', () => {
})
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.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 () => {
expect.assertions(2)
expect.assertions(3)
await expect(access(join(outdir, 'info/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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册