Skip to content

Commit

Permalink
Custom AMP Validator Variable Name Collision Fix (vercel#10371)
Browse files Browse the repository at this point in the history
* Changing variable name internally

* Add tests for custom AMP validator

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
2 people authored and chibicode committed Feb 11, 2020
1 parent 4462ef5 commit 7700617
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
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')
})
})

0 comments on commit 7700617

Please sign in to comment.