Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom AMP Validator Variable Name Collision Fix #10371

Merged
merged 3 commits into from Feb 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/export/index.ts
Expand Up @@ -232,7 +232,7 @@ export default async function(
hotReloader: null,
canonicalBase: nextConfig.amp?.canonicalBase || '',
isModern: nextConfig.experimental.modern,
ampValidator: nextConfig.experimental.amp?.validator || undefined,
ampValidatorPath: nextConfig.experimental.amp?.validator || undefined,
}

const { serverRuntimeConfig, publicRuntimeConfig } = nextConfig
Expand Down
2 changes: 1 addition & 1 deletion packages/next/export/worker.js
Expand Up @@ -214,7 +214,7 @@ export default async function({
}

if (curRenderOpts.inAmpMode) {
await validateAmp(html, path, curRenderOpts.ampValidator)
await validateAmp(html, path, curRenderOpts.ampValidatorPath)
} else if (curRenderOpts.hybridAmp) {
// we need to render the AMP version
let ampHtmlFilename = `${ampPath}${sep}index.html`
Expand Down
7 changes: 7 additions & 0 deletions test/integration/amphtml-custom-validator/next.config.js
@@ -0,0 +1,7 @@
module.exports = {
experimental: {
amp: {
validator: 'https://cdn.ampproject.org/v0/validator.js',
},
},
}
5 changes: 5 additions & 0 deletions test/integration/amphtml-custom-validator/pages/index.js
@@ -0,0 +1,5 @@
export const config = {
amp: true,
}

export default () => <p>Hello from AMP</p>
49 changes: 49 additions & 0 deletions test/integration/amphtml-custom-validator/test/index.test.js
@@ -0,0 +1,49 @@
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import {
nextBuild,
findPort,
nextStart,
killApp,
launchApp,
renderViaHTTP,
} from 'next-test-utils'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1

let app
let appPort
const appDir = join(__dirname, '../')

describe('AMP Custom Validator', () => {
it('should build and start successfully', async () => {
const { code } = await nextBuild(appDir)
expect(code).toBe(0)

appPort = await findPort()
app = await nextStart(appDir, appPort)

const html = await renderViaHTTP(appPort, '/')
await killApp(app)

expect(html).toContain('Hello from AMP')
})

it('should run in dev mode successfully', async () => {
let stderr = ''

appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})

const html = await renderViaHTTP(appPort, '/')
await killApp(app)

expect(stderr).not.toContain('error')
expect(html).toContain('Hello from AMP')
})
})