-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for exporting from serverless build (#9744)
* Add support for exporting from serverless build * Add more tests * Update syntax * Dont add dynamic params in worker * Update amphtml rel for serverless tests * Update tests again * Update dynamic params populating * Fix params parsing * Pass params separately
- Loading branch information
Showing
46 changed files
with
1,040 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/integration/export-default-map-serverless/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
target: 'serverless', | ||
} |
5 changes: 5 additions & 0 deletions
5
test/integration/export-default-map-serverless/pages/docs/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { useAmp } from 'next/amp' | ||
|
||
export const config = { amp: 'hybrid' } | ||
|
||
export default () => <p>I'm an {useAmp() ? 'AMP' : 'normal'} page</p> |
2 changes: 2 additions & 0 deletions
2
test/integration/export-default-map-serverless/pages/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export default () => <p>Simple hybrid amp/non-amp page</p> | ||
export const config = { amp: 'hybrid' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { useAmp } from 'next/amp' | ||
|
||
export const config = { amp: 'hybrid' } | ||
|
||
export default () => <p>I'm an {useAmp() ? 'AMP' : 'normal'} page</p> |
2 changes: 2 additions & 0 deletions
2
test/integration/export-default-map-serverless/pages/just-amp/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export default () => <p>I am an AMP only page</p> | ||
export const config = { amp: true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const config = { amp: 'hybrid' } | ||
|
||
export default () => <p>I'm an AMP page</p> |
3 changes: 3 additions & 0 deletions
3
test/integration/export-default-map-serverless/pages/v1.12/docs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Docs(props) { | ||
return <div>Hello again 👋</div> | ||
} |
3 changes: 3 additions & 0 deletions
3
test/integration/export-default-map-serverless/pages/v1.12/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Index(props) { | ||
return <div>Hello 👋</div> | ||
} |
68 changes: 68 additions & 0 deletions
68
test/integration/export-default-map-serverless/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import fs from 'fs' | ||
import { join } from 'path' | ||
import cheerio from 'cheerio' | ||
import { promisify } from 'util' | ||
import { nextBuild, nextExport } from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 | ||
const readFile = promisify(fs.readFile) | ||
const access = promisify(fs.access) | ||
const appDir = join(__dirname, '../') | ||
const outdir = join(appDir, 'out') | ||
|
||
describe('Export with default map', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
await nextExport(appDir, { outdir }) | ||
}) | ||
|
||
it('should export with folder that has dot in name', async () => { | ||
expect.assertions(1) | ||
await expect(access(join(outdir, 'v1.12.html'))).resolves.toBe(undefined) | ||
}) | ||
|
||
it('should export an amp only page to clean path', async () => { | ||
expect.assertions(1) | ||
await expect(access(join(outdir, 'docs.html'))).resolves.toBe(undefined) | ||
}) | ||
|
||
it('should export hybrid amp page correctly', async () => { | ||
expect.assertions(2) | ||
await expect(access(join(outdir, 'some.html'))).resolves.toBe(undefined) | ||
await expect(access(join(outdir, 'some.amp.html'))).resolves.toBe(undefined) | ||
}) | ||
|
||
it('should export nested hybrid amp page correctly', async () => { | ||
expect.assertions(3) | ||
await expect(access(join(outdir, 'docs.html'))).resolves.toBe(undefined) | ||
await expect(access(join(outdir, 'docs.amp.html'))).resolves.toBe(undefined) | ||
|
||
const html = await readFile(join(outdir, 'docs.html')) | ||
const $ = cheerio.load(html) | ||
expect($('link[rel=amphtml]').attr('href')).toBe('/docs.amp') | ||
}) | ||
|
||
it('should export nested hybrid amp page correctly with folder', async () => { | ||
expect.assertions(3) | ||
await expect(access(join(outdir, 'info.html'))).resolves.toBe(undefined) | ||
await expect(access(join(outdir, 'info.amp.html'))).resolves.toBe(undefined) | ||
|
||
const html = await readFile(join(outdir, 'info.html')) | ||
const $ = cheerio.load(html) | ||
expect($('link[rel=amphtml]').attr('href')).toBe('/info.amp') | ||
}) | ||
|
||
it('should export hybrid index amp page correctly', async () => { | ||
expect.assertions(3) | ||
await expect(access(join(outdir, 'index.html'))).resolves.toBe(undefined) | ||
await expect(access(join(outdir, 'index.amp.html'))).resolves.toBe( | ||
undefined | ||
) | ||
|
||
const html = await readFile(join(outdir, 'index.html')) | ||
const $ = cheerio.load(html) | ||
expect($('link[rel=amphtml]').attr('href')).toBe('/index.amp') | ||
}) | ||
}) |
8 changes: 8 additions & 0 deletions
8
test/integration/export-dynamic-pages-serverless/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
target: 'serverless', | ||
exportPathMap() { | ||
return { | ||
'/regression/jeff-is-cool': { page: '/regression/[slug]' }, | ||
} | ||
}, | ||
} |
13 changes: 13 additions & 0 deletions
13
test/integration/export-dynamic-pages-serverless/pages/regression/[slug].js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useRouter } from 'next/router' | ||
|
||
function Regression() { | ||
const { asPath } = useRouter() | ||
if (typeof window !== 'undefined') { | ||
window.__AS_PATHS = [...new Set([...(window.__AS_PATHS || []), asPath])] | ||
} | ||
return <div id="asPath">{asPath}</div> | ||
} | ||
|
||
Regression.getInitialProps = () => ({}) | ||
|
||
export default Regression |
52 changes: 52 additions & 0 deletions
52
test/integration/export-dynamic-pages-serverless/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import { join } from 'path' | ||
import cheerio from 'cheerio' | ||
import webdriver from 'next-webdriver' | ||
import { | ||
nextBuild, | ||
nextExport, | ||
startCleanStaticServer, | ||
stopApp, | ||
renderViaHTTP, | ||
waitFor, | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 | ||
const appDir = join(__dirname, '../') | ||
const outdir = join(appDir, 'out') | ||
|
||
describe('Export Dyanmic Pages', () => { | ||
let server | ||
let port | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
await nextExport(appDir, { outdir }) | ||
|
||
server = await startCleanStaticServer(outdir) | ||
port = server.address().port | ||
}) | ||
|
||
afterAll(async () => { | ||
await stopApp(server) | ||
}) | ||
|
||
it('should of exported with correct asPath', async () => { | ||
const html = await renderViaHTTP(port, '/regression/jeff-is-cool') | ||
const $ = cheerio.load(html) | ||
expect($('#asPath').text()).toBe('/regression/jeff-is-cool') | ||
}) | ||
|
||
it('should hydrate with correct asPath', async () => { | ||
expect.assertions(1) | ||
const browser = await webdriver(port, '/regression/jeff-is-cool') | ||
try { | ||
await waitFor(3000) | ||
expect(await browser.eval(`window.__AS_PATHS`)).toEqual([ | ||
'/regression/jeff-is-cool', | ||
]) | ||
} finally { | ||
await browser.close() | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.next-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => <p>Welcome to dynamic imports.</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants') | ||
|
||
module.exports = phase => { | ||
return { | ||
target: 'serverless', | ||
distDir: phase === PHASE_DEVELOPMENT_SERVER ? '.next-dev' : '.next', | ||
exportTrailingSlash: true, | ||
exportPathMap: function() { | ||
return { | ||
'/': { page: '/' }, | ||
'/about': { page: '/about' }, | ||
'/button-link': { page: '/button-link' }, | ||
'/get-initial-props-with-no-query': { | ||
page: '/get-initial-props-with-no-query', | ||
}, | ||
'/counter': { page: '/counter' }, | ||
'/dynamic-imports': { page: '/dynamic-imports' }, | ||
'/dynamic': { page: '/dynamic', query: { text: 'cool dynamic text' } }, | ||
'/dynamic/one': { | ||
page: '/dynamic', | ||
query: { text: 'next export is nice' }, | ||
}, | ||
'/dynamic/two': { | ||
page: '/dynamic', | ||
query: { text: 'zeit is awesome' }, | ||
}, | ||
'/file-name.md': { | ||
page: '/dynamic', | ||
query: { text: 'this file has an extension' }, | ||
}, | ||
'/query': { page: '/query', query: { a: 'blue' } }, | ||
// API route | ||
'/blog/nextjs/comment/test': { page: '/blog/[post]/comment/[id]' }, | ||
} | ||
}, // end exportPathMap | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Link from 'next/link' | ||
|
||
const About = ({ bar }) => ( | ||
<div id="about-page"> | ||
<div> | ||
<Link href="/"> | ||
<a>Go Back</a> | ||
</Link> | ||
</div> | ||
<p>{`This is the About page foo${bar || ''}`}</p> | ||
</div> | ||
) | ||
|
||
About.getInitialProps = async () => { | ||
return { bar: typeof window === 'undefined' ? 'bar' : '' } | ||
} | ||
|
||
export default About |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default (req, res) => { | ||
res.send('Hello World') | ||
} |
Oops, something went wrong.