-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for throwing instead of process.exit(1) on errors (#…
…118) * Add support for throwing instead of process.exit(1) on errors When using the package as a library, it's a good idea to throw an error instead of exiting with code 1. This way the user can recover from the mistake somehow (e.g. deleting a throwaway branch on during continuous integration). * Add usage as library e2e test
- Loading branch information
1 parent
bc54995
commit 0b67383
Showing
7 changed files
with
97 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { runMigration } = require('../built/bin/cli'); | ||
|
||
async function main (filePath) { | ||
let statusCode = 0; | ||
|
||
try { | ||
await runMigration({ | ||
spaceId: process.env.CONTENTFUL_SPACE_ID, | ||
accessToken: process.env.CONTENTFUL_MANAGEMENT_ACCESS_TOKEN, | ||
environmentId: 'master', | ||
yes: true, | ||
filePath | ||
}); | ||
} catch (e) { | ||
statusCode = 1; | ||
console.log('Catching Error'); | ||
} finally { | ||
console.log('Cleaning Up'); | ||
} | ||
|
||
process.exit(statusCode); | ||
} | ||
|
||
main(process.argv[2]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
const nixt = require('nixt'); | ||
|
||
const SPACE_ID = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE; | ||
const ACCESS_TOKEN = process.env.CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN; | ||
const cli = () => { | ||
return nixt() | ||
.env('CONTENTFUL_SPACE_ID', SPACE_ID) | ||
.env('CONTENTFUL_MANAGEMENT_ACCESS_TOKEN', ACCESS_TOKEN) | ||
.base('node ./examples/usage-as-lib.js ') | ||
.clone(); | ||
}; | ||
|
||
module.exports = cli; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
const assert = require('./assertions'); | ||
const cliAsLib = require('./cli-as-lib'); | ||
|
||
describe('cli-as-lib', () => { | ||
describe('04-steps-errors.js', function () { | ||
it('should throw and allow for cleanup code to execute', function (done) { | ||
this.timeout(10000); | ||
|
||
cliAsLib() | ||
.run(require.resolve(`../../examples/04-steps-errors.js`)) | ||
.expect(assert.errors.recovery) | ||
.end(done); | ||
}); | ||
}); | ||
}); |