Skip to content

Commit

Permalink
fix(create-initial-branch): greenkeeper.json must end with newline
Browse files Browse the repository at this point in the history
  • Loading branch information
espy authored and janl committed Apr 6, 2018
1 parent fc75f35 commit e597e6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions jobs/create-initial-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ module.exports = async function ({ repositoryId }) {
const greenkeeperJSON = {
groups: defaultGroups
}
return JSON.stringify(greenkeeperJSON, null, 2)
// greenkeeper.json must end with a newline
return JSON.stringify(greenkeeperJSON, null, 2) + '\n'
},
create: true
}
Expand All @@ -203,7 +204,8 @@ module.exports = async function ({ repositoryId }) {

// Replace the transform that generates the default group with one that updates existing groups
greenkeeperJSONTransform.transform = () => {
return JSON.stringify(greenkeeperConfigFile, null, 2)
// greenkeeper.json must end with a newline
return JSON.stringify(greenkeeperConfigFile, null, 2) + '\n'
}
// Don’t create this file because it already exists
delete greenkeeperJSONTransform.create
Expand Down
18 changes: 12 additions & 6 deletions test/jobs/create-initial-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ describe('create initial branch', () => {
'@finnpauls/dep': '1.0.0',
'@finnpauls/dep2': '1.0.0'
}
expect.assertions(20)
expect.assertions(21)

nock('https://api.github.com')
.post('/installations/137/access_tokens')
Expand Down Expand Up @@ -515,13 +515,16 @@ describe('create initial branch', () => {
expect(newReadme).toMatch(/https:\/\/badges.greenkeeper.io\/finnp\/test.svg/)
expect(transforms.length).toEqual(5)
expect(transforms[0].path).toEqual('greenkeeper.json')
expect(JSON.parse(transforms[0].transform())).toEqual({
const greenkeeperConfigTransformResult = transforms[0].transform()
expect(JSON.parse(greenkeeperConfigTransformResult)).toEqual({
groups: {
default: {
packages: ['package.json', 'frontend/package.json']
}
}
})
// greenkeeper.json must end with a newline
expect(greenkeeperConfigTransformResult.substr(greenkeeperConfigTransformResult.length - 1, 1)).toEqual('\n')
expect(transforms[1].path).toEqual('frontend/package.json')
expect(JSON.parse(transforms[1].transform(JSON.stringify({ devDependencies })))).toEqual({
'devDependencies': {
Expand Down Expand Up @@ -604,7 +607,7 @@ describe('create initial branch', () => {
'@finnpauls/dep2': '1.0.0'
}

expect.assertions(18)
expect.assertions(19)

nock('https://api.github.com')
.post('/installations/137/access_tokens')
Expand Down Expand Up @@ -733,8 +736,9 @@ describe('create initial branch', () => {
// The `empty` group should disappear completely, since it no longer contains any files
// The `frontend` group should not contain `this-file-no-longer-exists/package.json`, since that file
// is no longer in the repo
const transformedConfigFile = JSON.parse(transforms[0].transform())
expect(transformedConfigFile.groups).toMatchObject({
const transformedConfigFile = transforms[0].transform()
const parsedConfigFile = JSON.parse(transformedConfigFile)
expect(parsedConfigFile.groups).toMatchObject({
build: {
packages: [
'package.json'
Expand All @@ -751,7 +755,9 @@ describe('create initial branch', () => {
]
}
})
expect(transformedConfigFile.ignore).toEqual(['eslint'])
// greenkeeper.json must end with a newline
expect(transformedConfigFile.substr(transformedConfigFile.length - 1, 1)).toEqual('\n')
expect(parsedConfigFile.ignore).toEqual(['eslint'])
expect(transforms.length).toEqual(6)

return '1234abcd'
Expand Down

0 comments on commit e597e6b

Please sign in to comment.