From 29ed67b02071cbf7f3ddd1806a206e850eaebc8b Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Tue, 4 Dec 2018 16:42:25 +0100 Subject: [PATCH] Add test for generateBuildId (#5816) * Add docs for returning `null` from generateBuildId * Add test for setting custom buildid * Fix linting --- package.json | 6 +++--- packages/next/README.md | 17 +++++++++++++++-- .../production-config/next.config.js | 3 +++ .../production-config/test/index.test.js | 16 +++++++++++++++- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 0f64bd6e86..af94fb5f66 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ }, "pre-commit": "lint-staged", "lint-staged": { - "*.js": "standard --fix", - "*.ts": "standard --parser typescript-eslint-parser --plugin typescript --fix", - "packages/**/bin/*": "standard" + "*.js": ["standard --fix", "git add"], + "*.ts": ["standard --parser typescript-eslint-parser --plugin typescript --fix", "git add"], + "packages/**/bin/*": ["standard --fix", "git add"] }, "standard": { "parser": "babel-eslint", diff --git a/packages/next/README.md b/packages/next/README.md index dc8bff327e..64c2b9f361 100644 --- a/packages/next/README.md +++ b/packages/next/README.md @@ -1206,8 +1206,6 @@ Or use a function: ```js module.exports = (phase, {defaultConfig}) => { - // - // https://github.com/zeit/ return { /* config options here */ } @@ -1296,6 +1294,21 @@ module.exports = { } ``` +To fall back to the default of generating a unique id return `null` from the function: + +```js +module.exports = { + generateBuildId: async () => { + // When process.env.YOUR_BUILD_ID is undefined we fall back to the default + if(process.env.YOUR_BUILD_ID) { + return process.env.YOUR_BUILD_ID + } + + return null + } +} +``` + ### Customizing webpack config
diff --git a/test/integration/production-config/next.config.js b/test/integration/production-config/next.config.js index 3b08c56e12..4d8a001d1d 100644 --- a/test/integration/production-config/next.config.js +++ b/test/integration/production-config/next.config.js @@ -19,5 +19,8 @@ module.exports = withCSS(withSass({ } return config + }, + async generateBuildId () { + return 'custom-buildid' } })) diff --git a/test/integration/production-config/test/index.test.js b/test/integration/production-config/test/index.test.js index 4b93863a4c..ff787be6b5 100644 --- a/test/integration/production-config/test/index.test.js +++ b/test/integration/production-config/test/index.test.js @@ -11,6 +11,7 @@ import webdriver from 'next-webdriver' jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 +let appPort let server describe('Production Config Usage', () => { @@ -23,6 +24,7 @@ describe('Production Config Usage', () => { quiet: true }) server = await startApp(app) + appPort = server.address().port }) afterAll(() => stopApp(server)) @@ -34,10 +36,22 @@ describe('Production Config Usage', () => { await testBrowser() }) }) + + describe('with generateBuildId', () => { + it('should add the custom buildid', async () => { + const browser = await webdriver(appPort, '/') + const text = await browser.elementByCss('#mounted').text() + expect(text).toMatch(/ComponentDidMount executed on client\./) + + const html = await browser.elementByCss('html').getAttribute('innerHTML') + expect(html).toMatch('custom-buildid') + return browser.close() + }) + }) }) async function testBrowser () { - const browser = await webdriver(server.address().port, '/') + const browser = await webdriver(appPort, '/') const element = await browser.elementByCss('#mounted') const text = await element.text() expect(text).toMatch(/ComponentDidMount executed on client\./) -- GitLab