diff --git a/e2e-tests/production-runtime/cypress/integration/modified-exports-ts.js b/e2e-tests/production-runtime/cypress/integration/modified-exports-ts.js new file mode 100644 index 0000000000000..bc1753403d1aa --- /dev/null +++ b/e2e-tests/production-runtime/cypress/integration/modified-exports-ts.js @@ -0,0 +1,65 @@ +/** + * Test that page templates have certain exports removed while other files are left alone. + * + * Page templates support only a default exported React component and named exports of + * `config` and `getServerData`, so it's not necessary (or possible) to test other exports + * in page templates. + */ + +const config = `config exported from a non-page template module` +const getServerData = `getServerData exported from a non-page template module` +const helloWorld = `hello world` + +describe(`modifed exports`, () => { + beforeEach(() => { + cy.visit(`/modified-exports-ts`).waitForRouteChange() + }) + + describe(`page templates`, () => { + it(`should have exports named config removed`, () => { + cy.getTestElement(`modified-exports-page-template-config`) + .invoke(`text`) + .should(`contain`, `undefined`) + }) + it(`should have exports named getServerData removed`, () => { + cy.getTestElement(`modified-exports-page-template-get-server-data`) + .invoke(`text`) + .should(`contain`, `undefined`) + }) + it(`should have imported exports named config left alone`, () => { + cy.getTestElement(`unmodified-exports-page-template-config`) + .invoke(`text`) + .should(`contain`, config) + }) + it(`should have imported exports named getServerData left alone`, () => { + cy.getTestElement(`unmodified-exports-page-template-get-server-data`) + .invoke(`text`) + .should(`contain`, getServerData) + }) + it(`should have other imported exports left alone`, () => { + cy.getTestElement(`unmodified-exports-page-template-hello-world`) + .invoke(`text`) + .should(`contain`, helloWorld) + }) + }) + + describe(`other JS files`, () => { + it(`should have exports named config left alone`, () => { + cy.getTestElement(`unmodified-exports-config`) + .invoke(`text`) + .should(`contain`, config) + }) + + it(`should have exports named getServerData left alone`, () => { + cy.getTestElement(`unmodified-exports-get-server-data`) + .invoke(`text`) + .should(`contain`, getServerData) + }) + + it(`should have other named exports left alone`, () => { + cy.getTestElement(`unmodified-exports-hello-world`) + .invoke(`text`) + .should(`contain`, helloWorld) + }) + }) +}) diff --git a/e2e-tests/production-runtime/src/pages/modified-exports-ts.tsx b/e2e-tests/production-runtime/src/pages/modified-exports-ts.tsx new file mode 100644 index 0000000000000..9a4a64506f820 --- /dev/null +++ b/e2e-tests/production-runtime/src/pages/modified-exports-ts.tsx @@ -0,0 +1,39 @@ +import React from "react" +import UnmodifiedExports, { + config as importedConfig, + getServerData as importedGetServerData, + helloWorld, +} from "../components/unmodified-exports" + +function ModifiedExports() { + return ( +
This is the modified exports for page templates test page
+ {/* Use typeof to avoid runtime error */} +{typeof config}
++ {typeof getServerData} +
++ {importedConfig()} +
++ {importedGetServerData()} +
++ {helloWorld()} +
+