Skip to content

Commit

Permalink
Test that params are properly passed to hybrid amp pages
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekkolodziej committed Sep 30, 2020
1 parent 02d7504 commit d941405
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/next/export/worker.ts
Expand Up @@ -332,7 +332,7 @@ export default async function exportPage({
if (serverless) {
req.url += (req.url!.includes('?') ? '&' : '?') + 'amp=1'
// @ts-ignore
ampHtml = (await renderMethod(req, res, 'export')).html
ampHtml = (await renderMethod(req, res, 'export', undefined, params)).html
} else {
ampHtml = await renderMethod(
req,
Expand Down
6 changes: 4 additions & 2 deletions test/integration/amphtml-ssg/pages/blog/[slug].js
Expand Up @@ -4,9 +4,10 @@ export const config = {
amp: 'hybrid',
}

export const getStaticProps = () => {
export const getStaticProps = (ctx) => {
return {
props: {
slug: (ctx && ctx.params && ctx.params.slug) || null,
hello: 'hello',
random: Math.random(),
},
Expand All @@ -18,10 +19,11 @@ export const getStaticPaths = () => ({
fallback: false,
})

export default ({ hello, random }) => (
export default ({ hello, random, slug }) => (
<>
<p id="use-amp">useAmp: {useAmp() ? 'yes' : 'no'}</p>
<p id="hello">{hello}</p>
<p id="random">{random}</p>
<p id="slug">{slug}</p>
</>
)
3 changes: 3 additions & 0 deletions test/integration/amphtml-ssg/test/index.test.js
Expand Up @@ -51,20 +51,23 @@ const runTests = (isDev = false) => {
const $ = cheerio.load(html)
expect($('#use-amp').text()).toContain('no')
expect($('#hello').text()).toContain('hello')
expect($('#slug').text()).toContain('post-1')
})

it('should load dynamic hybrid SSG/AMP page with trailing slash', async () => {
const html = await renderViaHTTP(appPort, '/blog/post-1/')
const $ = cheerio.load(html)
expect($('#use-amp').text()).toContain('no')
expect($('#hello').text()).toContain('hello')
expect($('#slug').text()).toContain('post-1')
})

it('should load dynamic hybrid SSG/AMP page with query', async () => {
const html = await renderViaHTTP(appPort, '/blog/post-1?amp=1')
const $ = cheerio.load(html)
expect($('#use-amp').text()).toContain('yes')
expect($('#hello').text()).toContain('hello')
expect($('#slug').text()).toContain('post-1')
})

it('should load a hybrid amp page with query correctly', async () => {
Expand Down

0 comments on commit d941405

Please sign in to comment.