Skip to content

Commit

Permalink
Add test for generateBuildId (vercel#5816)
Browse files Browse the repository at this point in the history
* Add docs for returning `null` from generateBuildId

* Add test for setting custom buildid

* Fix linting
  • Loading branch information
timneutkens authored Dec 4, 2018
1 parent cdd5129 commit 29ed67b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 15 additions & 2 deletions packages/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1206,8 +1206,6 @@ Or use a function:
```js
module.exports = (phase, {defaultConfig}) => {
//
// https://github.com/zeit/
return {
/* config options here */
}
Expand Down Expand Up @@ -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>
Expand Down
3 changes: 3 additions & 0 deletions test/integration/production-config/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ module.exports = withCSS(withSass({
}

return config
},
async generateBuildId () {
return 'custom-buildid'
}
}))
16 changes: 15 additions & 1 deletion test/integration/production-config/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import webdriver from 'next-webdriver'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5

let appPort
let server

describe('Production Config Usage', () => {
Expand All @@ -23,6 +24,7 @@ describe('Production Config Usage', () => {
quiet: true
})
server = await startApp(app)
appPort = server.address().port
})
afterAll(() => stopApp(server))

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

0 comments on commit 29ed67b

Please sign in to comment.