Skip to content

Commit

Permalink
Sanitize stderr before checking output
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Nov 21, 2019
1 parent 98d5540 commit 7926000
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
8 changes: 2 additions & 6 deletions test/cli/samples/empty-chunk-multiple/_config.js
@@ -1,13 +1,9 @@
const assert = require('assert');
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
solo: true,
description: 'shows warning when multiple chunks empty',
command: 'rollup -c',
error: () => true,
stderr: stderr => {
console.log(JSON.stringify(stderr));
assert.ok(stderr.includes('(!) Generated empty chunks'));
assert.ok(stderr.includes('a, b'));
}
stderr: stderr => assertStderrIncludes(stderr, '(!) Generated empty chunks\na, b')
};
8 changes: 2 additions & 6 deletions test/cli/samples/empty-chunk/_config.js
@@ -1,13 +1,9 @@
const assert = require('assert');
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
solo: true,
description: 'shows warning when chunk empty',
command: 'rollup -c',
error: () => true,
stderr: stderr => {
console.log(JSON.stringify(stderr));
assert.ok(stderr.includes('(!) Generated an empty chunk'));
assert.ok(stderr.includes('main'));
}
stderr: stderr => assertStderrIncludes(stderr, '(!) Generated an empty chunk\nmain')
};
10 changes: 10 additions & 0 deletions test/utils.js
Expand Up @@ -12,6 +12,7 @@ exports.loader = loader;
exports.normaliseOutput = normaliseOutput;
exports.runTestSuiteWithSamples = runTestSuiteWithSamples;
exports.assertDirectoriesAreEqual = assertDirectoriesAreEqual;
exports.assertStderrIncludes = assertStderrIncludes;

function normaliseError(error) {
delete error.stack;
Expand Down Expand Up @@ -224,3 +225,12 @@ function assertFilesAreEqual(actualFiles, expectedFiles, dirs = []) {
);
});
}

function assertStderrIncludes(stderr, expected) {
// eslint-disable-next-line no-control-regex
const output = stderr.replace(/\x1b\[[^m]*m/g, '');
assert.ok(
output.includes(expected),
`Could not find ${JSON.stringify(expected)} in ${JSON.stringify(output)}`
);
}

0 comments on commit 7926000

Please sign in to comment.