1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Add test for generateBuildId (#5816)

* Add docs for returning `null` from generateBuildId

* Add test for setting custom buildid

* Fix linting
This commit is contained in:
Tim Neutkens 2018-12-04 16:42:25 +01:00 committed by GitHub
parent cdd5129ef3
commit 29ed67b020
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 6 deletions

View file

@ -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",

View file

@ -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
<details>

View file

@ -19,5 +19,8 @@ module.exports = withCSS(withSass({
}
return config
},
async generateBuildId () {
return 'custom-buildid'
}
}))

View file

@ -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\./)