Unverified Commit 29ed67b0 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add test for generateBuildId (#5816)

* Add docs for returning `null` from generateBuildId

* Add test for setting custom buildid

* Fix linting
parent cdd5129e
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
}, },
"pre-commit": "lint-staged", "pre-commit": "lint-staged",
"lint-staged": { "lint-staged": {
"*.js": "standard --fix", "*.js": ["standard --fix", "git add"],
"*.ts": "standard --parser typescript-eslint-parser --plugin typescript --fix", "*.ts": ["standard --parser typescript-eslint-parser --plugin typescript --fix", "git add"],
"packages/**/bin/*": "standard" "packages/**/bin/*": ["standard --fix", "git add"]
}, },
"standard": { "standard": {
"parser": "babel-eslint", "parser": "babel-eslint",
......
...@@ -1206,8 +1206,6 @@ Or use a function: ...@@ -1206,8 +1206,6 @@ Or use a function:
```js ```js
module.exports = (phase, {defaultConfig}) => { module.exports = (phase, {defaultConfig}) => {
//
// https://github.com/zeit/
return { return {
/* config options here */ /* config options here */
} }
...@@ -1296,6 +1294,21 @@ module.exports = { ...@@ -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 ### Customizing webpack config
<details> <details>
......
...@@ -19,5 +19,8 @@ module.exports = withCSS(withSass({ ...@@ -19,5 +19,8 @@ module.exports = withCSS(withSass({
} }
return config return config
},
async generateBuildId () {
return 'custom-buildid'
} }
})) }))
...@@ -11,6 +11,7 @@ import webdriver from 'next-webdriver' ...@@ -11,6 +11,7 @@ import webdriver from 'next-webdriver'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
let appPort
let server let server
describe('Production Config Usage', () => { describe('Production Config Usage', () => {
...@@ -23,6 +24,7 @@ describe('Production Config Usage', () => { ...@@ -23,6 +24,7 @@ describe('Production Config Usage', () => {
quiet: true quiet: true
}) })
server = await startApp(app) server = await startApp(app)
appPort = server.address().port
}) })
afterAll(() => stopApp(server)) afterAll(() => stopApp(server))
...@@ -34,10 +36,22 @@ describe('Production Config Usage', () => { ...@@ -34,10 +36,22 @@ describe('Production Config Usage', () => {
await testBrowser() 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 () { async function testBrowser () {
const browser = await webdriver(server.address().port, '/') const browser = await webdriver(appPort, '/')
const element = await browser.elementByCss('#mounted') const element = await browser.elementByCss('#mounted')
const text = await element.text() const text = await element.text()
expect(text).toMatch(/ComponentDidMount executed on client\./) expect(text).toMatch(/ComponentDidMount executed on client\./)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment