Skip to content

Commit

Permalink
Added binaryPath test.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jul 21, 2016
1 parent e8e865b commit a5c444f
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion test/PngQuant.js
@@ -1,4 +1,4 @@
/*global describe, it, setTimeout, __dirname*/
/*global describe, it, beforeEach, afterEach, setTimeout, __dirname*/
var expect = require('unexpected').clone()
.use(require('unexpected-stream'))
.use(require('unexpected-sinon'));
Expand Down Expand Up @@ -116,4 +116,42 @@ describe('PngQuant', function () {
});
});
});

expect.addAssertion('<Stream> to error', function (expect, subject) {
return expect.promise(function (run) {
subject.once('error', run(function (err) {
return err;
}));
});
});

expect.addAssertion('<Stream> to error with <any>', function (expect, subject, value) {
expect.errorMode = 'nested';
return expect(subject, 'to error').then(function (err) {
return expect(err, 'to satisfy', value);
});
});

describe('with an overridden #binaryPath', function () {
var childProcess = require('child_process');
beforeEach(function () {
PngQuant.getBinaryPath.purgeAll(); // Make sure we don't get a cached value from one of the other tests
PngQuant.binaryPath = '/foo/bar';
sinon.spy(childProcess, 'spawn');
});
afterEach(function () {
PngQuant.binaryPath = null;
childProcess.spawn.restore();
});

it('should try launching that binary instead of the one found on the system', function () {
return expect(
fs.createReadStream(pathModule.resolve(__dirname, 'purplealpha24bit.png')),
'when piped through',
new PngQuant([128]),
'to error with',
/\/foo\/bar ENOENT/
);
});
});
});

0 comments on commit a5c444f

Please sign in to comment.