Skip to content

Commit

Permalink
Output phantom.js errors to stderr.
Browse files Browse the repository at this point in the history
Use .contain
  • Loading branch information
giakki committed Mar 9, 2015
1 parent cd46c50 commit 62145b3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/phantom.js
Expand Up @@ -26,6 +26,9 @@ function init(instance) {
sslProtocol: 'any'
}));
}).then(function (ph) {
/* Phridge outputs everything to stdout by default */
ph.childProcess.cleanStdout.unpipe();
ph.childProcess.cleanStdout.pipe(process.stderr);
phantom = ph;
}).disposer(phridge.disposeAll);
}
Expand Down
18 changes: 18 additions & 0 deletions tests/errors.js
Expand Up @@ -66,6 +66,24 @@ describe('Error reporting', function () {
});
});

it('PhantomJS errors to stderr', function (done) {
var stderrBuffer = '';
var oldWrite = process.stderr.write;
process.stderr.write = function (data) {
stderrBuffer += data;
};

uncss(
['tests/phantomjs/throw.html'],
{ raw: '' },
function (error) {
expect(error).to.equal(null);
expect(stderrBuffer).to.contain('Exception');
process.stderr.write = oldWrite;
done();
});
});

it('css-parse errors', function (done) {
uncss(
['tests/selectors/index.html'],
Expand Down
14 changes: 14 additions & 0 deletions tests/phantomjs/throw.html
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PhantomJS basic test</title>
<link rel="stylesheet" href="phantomjs.css">
</head>
<body>
<script>
/* Append an element */
throw 'Exception';
</script>
</body>
</html>

0 comments on commit 62145b3

Please sign in to comment.