Skip to content

Commit

Permalink
chore: catch errors higher in the scope
Browse files Browse the repository at this point in the history
  • Loading branch information
lekterable committed May 2, 2020
1 parent d34a9f1 commit ac5c2a8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features

- make changelog ignored scopes configurable [d34a9f12](https://github.com/lekterable/perfekt/commit/d34a9f12500df6ea21a17b85b783a41b1fca5347)
- make changelog groups configurable [a2ec46eb](https://github.com/lekterable/perfekt/commit/a2ec46eb9e962a79a9153300adc2229af182d4a6)

# 1.1.0
Expand Down
8 changes: 6 additions & 2 deletions bin/perfekt.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ program
...cosmiConfig.config
}

changelog(version, options, config)
changelog(version, options, config).catch(error =>
console.error(error.message)
)
})

program
Expand All @@ -35,7 +37,9 @@ program
...cosmiConfig.config
}

release(version, options, config)
release(version, options, config).catch(error =>
console.error(error.message)
)
})

program.version(version).parse(process.argv)
12 changes: 4 additions & 8 deletions src/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ export const release = async (version, options, config) => {

const newVersion = semver.valid(semver.coerce(version))

if (!newVersion) throw new Error(`Version '${version}' doesnt look right`)
if (!newVersion) throw new Error(`Version '${version}' doesn't look right`)

try {
await updateVersion(newVersion)
await changelog(newVersion, { write: true }, config)
await commitRelease(newVersion)
} catch (error) {
console.error(error)
}
await updateVersion(newVersion)
await changelog(newVersion, { write: true }, config)
await commitRelease(newVersion)
}
16 changes: 1 addition & 15 deletions src/release.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,10 @@ describe('release', () => {
const mockedVersion = 'version'

expect(release(mockedVersion)).rejects.toThrow(
"Version 'version' doesnt look right"
"Version 'version' doesn't look right"
)
})

it('should log error if it occurs', async () => {
const mockedVersion = '2.2.2'
const consoleSpy = jest.spyOn(console, 'error').mockImplementation()

updateVersion.mockImplementation(() => Promise.reject(new Error()))

await release(mockedVersion)

expect(consoleSpy).toBeCalledTimes(1)
expect(consoleSpy).toBeCalledWith(expect.any(Error))

consoleSpy.mockRestore()
})

it('should execute release', async () => {
const mockedVersion = '2.2.2'

Expand Down

0 comments on commit ac5c2a8

Please sign in to comment.