Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Sep 3, 2015
1 parent feceb8b commit 2d47966
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions index.js
Expand Up @@ -7,6 +7,7 @@ var getPkgRepo = require('get-pkg-repo');
var gitRawCommits = require('git-raw-commits');
var gitSemverTags = require('git-semver-tags');
var Q = require('q');
// var readClosestPackage = require('read-closest-package');
var stream = require('stream');
var through = require('through2');
var url = require('url');
Expand Down Expand Up @@ -71,7 +72,9 @@ function conventinalChangelog(options, context, gitRawCommitsOpts, parserOpts, w
}
}

// if (options.pkg.path) {
pkgPromise = Q.nfcall(fs.readFile, options.pkg.path, 'utf8');
// }

semverTagsPromise = Q.nfcall(gitSemverTags);

Expand All @@ -98,7 +101,9 @@ function conventinalChangelog(options, context, gitRawCommitsOpts, parserOpts, w
if (pkgObj.state === 'fulfilled') {
pkg = pkgObj.value;
try {
// if (options.pkg.path) {
pkg = JSON.parse(pkg);
// }
pkg = options.pkg.transform(pkg);
context.version = context.version || pkg.version;
context.packageData = pkg;
Expand Down Expand Up @@ -246,6 +251,9 @@ function conventinalChangelog(options, context, gitRawCommitsOpts, parserOpts, w

cb();
}));
})
.catch(function(err) {
setImmediate(readable.emit.bind(readable), 'error', err);
});

return readable;
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -36,6 +36,7 @@
"lodash": "^3.9.3",
"meow": "^3.3.0",
"q": "^1.4.1",
"read-closest-package": "^1.0.1",
"semver": "^5.0.1",
"tempfile": "^1.1.1",
"through2": "^2.0.0"
Expand Down
43 changes: 43 additions & 0 deletions test/test.js
Expand Up @@ -543,11 +543,18 @@ describe('conventionalChangelog', function() {
});

it('should warn if preset is not found', function(done) {
var i = 0;

conventionalChangelog({
preset: 'no',
warn: function(warning) {
if (i > 0) {
return;
}

expect(warning).to.equal('Preset: "no" does not exist');

i++;
done();
}
});
Expand Down Expand Up @@ -611,6 +618,42 @@ describe('conventionalChangelog', function() {
});
});

it('should error if anything throws', function(done) {
conventionalChangelog({
pkg: {
path: __dirname + '/fixtures/_malformation.json'
},
warn: function() {
undefined.a = 10;
}
}).on('error', function(err) {
expect(err).to.be.ok; // jshint ignore:line
done();
});
});

// it('should error if there is an error in `options.transform`', function(done) {
// conventionalChangelog({
// pkg: {
// path: __dirname + '/fixtures/_short.json',
// transform: function() {
// undefined.a = 10;
// }
// },
// warn: function(warning) {
// console.log(warning);
// expect(warning).to.equal('');
//
// done();
// }
// })
// .on('error', function(err) {
// expect(err.message).to.include('Error in conventional-changelog-writer:');
//
// done();
// });
// });

it('should error if it errors in git-raw-commits', function(done) {
conventionalChangelog({}, {}, {
unknowOptions: false
Expand Down

0 comments on commit 2d47966

Please sign in to comment.