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:
parent
cdd5129ef3
commit
29ed67b020
|
@ -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",
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -19,5 +19,8 @@ module.exports = withCSS(withSass({
|
|||
}
|
||||
|
||||
return config
|
||||
},
|
||||
async generateBuildId () {
|
||||
return 'custom-buildid'
|
||||
}
|
||||
}))
|
||||
|
|
|
@ -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\./)
|
||||
|
|
Loading…
Reference in a new issue