From 7700617e62c6e579db59675877c5178cfe820856 Mon Sep 17 00:00:00 2001 From: Matt Snider Date: Sun, 2 Feb 2020 10:02:56 -0800 Subject: [PATCH] Custom AMP Validator Variable Name Collision Fix (#10371) * Changing variable name internally * Add tests for custom AMP validator Co-authored-by: JJ Kasper --- packages/next/export/index.ts | 2 +- packages/next/export/worker.js | 2 +- .../amphtml-custom-validator/next.config.js | 7 +++ .../amphtml-custom-validator/pages/index.js | 5 ++ .../test/index.test.js | 49 +++++++++++++++++++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 test/integration/amphtml-custom-validator/next.config.js create mode 100644 test/integration/amphtml-custom-validator/pages/index.js create mode 100644 test/integration/amphtml-custom-validator/test/index.test.js diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index b23b0890f398373..40f0c33ca68852a 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -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 diff --git a/packages/next/export/worker.js b/packages/next/export/worker.js index 68a1307b519dd7b..61a2a88e2517d6e 100644 --- a/packages/next/export/worker.js +++ b/packages/next/export/worker.js @@ -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` diff --git a/test/integration/amphtml-custom-validator/next.config.js b/test/integration/amphtml-custom-validator/next.config.js new file mode 100644 index 000000000000000..60668d95da8fa5b --- /dev/null +++ b/test/integration/amphtml-custom-validator/next.config.js @@ -0,0 +1,7 @@ +module.exports = { + experimental: { + amp: { + validator: 'https://cdn.ampproject.org/v0/validator.js', + }, + }, +} diff --git a/test/integration/amphtml-custom-validator/pages/index.js b/test/integration/amphtml-custom-validator/pages/index.js new file mode 100644 index 000000000000000..b4d8c8f0e616e3d --- /dev/null +++ b/test/integration/amphtml-custom-validator/pages/index.js @@ -0,0 +1,5 @@ +export const config = { + amp: true, +} + +export default () =>

Hello from AMP

diff --git a/test/integration/amphtml-custom-validator/test/index.test.js b/test/integration/amphtml-custom-validator/test/index.test.js new file mode 100644 index 000000000000000..24d67151fad6d67 --- /dev/null +++ b/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') + }) +})