Skip to content

Commit

Permalink
Add test case for silent flag (#18)
Browse files Browse the repository at this point in the history
Test that console.info is called when false is used for silent flag.
  • Loading branch information
brandondoran authored Sep 26, 2016
1 parent 4f7757c commit d461d6e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/RollbarSourceMapPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class RollbarSourceMapPlugin {
const req = request.post(ROLLBAR_ENDPOINT, (err, res, body) => {
if (!err && res.statusCode === 200) {
if (!this.silent) {
console.info(`\nUploaded ${sourceMap} to Rollbar`); // eslint-disable-line no-console
console.info(`Uploaded ${sourceMap} to Rollbar`); // eslint-disable-line no-console
}
return cb();
}
Expand Down
20 changes: 18 additions & 2 deletions test/RollbarSourceMapPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ describe('RollbarSourceMapPlugin', function() {
if (err) {
return done(err);
}
expect(this.info).toHaveBeenCalledWith('\nUploaded vendor.5190.js.map to Rollbar');
expect(this.info).toHaveBeenCalledWith('Uploaded vendor.5190.js.map to Rollbar');
done();
});
});

it('should not log upload if silent option is true', function(done) {
it('should not log upload to console if silent option is true', function(done) {
const scope = nock('https://api.rollbar.com:443') // eslint-disable-line no-unused-vars
.post('/api/1/sourcemap')
.reply(200, JSON.stringify({ err: 0, result: 'master-latest-sha' }));
Expand All @@ -278,6 +278,22 @@ describe('RollbarSourceMapPlugin', function() {
});
});

it('should log upload to console if silent option is false', function(done) {
const scope = nock('https://api.rollbar.com:443') // eslint-disable-line no-unused-vars
.post('/api/1/sourcemap')
.reply(200, JSON.stringify({ err: 0, result: 'master-latest-sha' }));

const { compilation, chunk } = this;
this.plugin.silent = false;
this.plugin.uploadSourceMap(compilation, chunk, (err) => {
if (err) {
return done(err);
}
expect(this.info).toHaveBeenCalledWith('Uploaded vendor.5190.js.map to Rollbar');
done();
});
});

it('should return detailed error message if failure response includes message', function(done) {
const scope = nock('https://api.rollbar.com:443') // eslint-disable-line no-unused-vars
.post('/api/1/sourcemap')
Expand Down

0 comments on commit d461d6e

Please sign in to comment.