refactor: Use ES6, Test with AVA

- Use async/await instead of callbacks
- Use execa to run command line
- Use AVA for tests
- Add several assertions in the unit tests
- Add documentation (comments) in the tests
- Run tests with a real git repo instead of mocking child_process and add test helpers to create repos, commits and checkout
- Simplify test directory structure
- Simplify code readability (mostly with async/await)
- Use eslint for for linting, prettier for formatting
This commit is contained in:
Pierre-Denis Vanduynslager
2017-09-30 13:30:41 -04:00
committed by Pierre Vanduynslager
parent 7fe0890350
commit abf92ad03d
51 changed files with 1362 additions and 1132 deletions
+14 -29
View File
@@ -1,40 +1,25 @@
var SemanticReleaseError = require('@semantic-release/error')
const SemanticReleaseError = require('@semantic-release/error');
module.exports = function (config) {
var pkg = config.pkg
var options = config.options
var env = config.env
var errors = []
module.exports = ({pkg, options, env}) => {
const errors = [];
if (!pkg.name) {
errors.push(new SemanticReleaseError(
'No "name" found in package.json.',
'ENOPKGNAME'
))
errors.push(new SemanticReleaseError('No "name" found in package.json.', 'ENOPKGNAME'));
}
if (!pkg.repository || !pkg.repository.url) {
errors.push(new SemanticReleaseError(
'No "repository" found in package.json.',
'ENOPKGREPO'
))
errors.push(new SemanticReleaseError('No "repository" found in package.json.', 'ENOPKGREPO'));
}
if (options.debug) return errors
if (!options.debug) {
if (!options.githubToken) {
errors.push(new SemanticReleaseError('No github token specified.', 'ENOGHTOKEN'));
}
if (!options.githubToken) {
errors.push(new SemanticReleaseError(
'No github token specified.',
'ENOGHTOKEN'
))
if (!(env.NPM_TOKEN || (env.NPM_OLD_TOKEN && env.NPM_EMAIL))) {
errors.push(new SemanticReleaseError('No npm token specified.', 'ENONPMTOKEN'));
}
}
if (!(env.NPM_TOKEN || (env.NPM_OLD_TOKEN && env.NPM_EMAIL))) {
errors.push(new SemanticReleaseError(
'No npm token specified.',
'ENONPMTOKEN'
))
}
return errors
}
return errors;
};