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 8f4f012 commit 821888a
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 43 deletions.
12 changes: 0 additions & 12 deletions test/cli/samples/custom-frame-log-stack/_config.js

This file was deleted.

1 change: 0 additions & 1 deletion test/cli/samples/custom-frame-log-stack/main.js

This file was deleted.

15 changes: 0 additions & 15 deletions test/cli/samples/custom-frame-log-stack/rollup.config.js

This file was deleted.

13 changes: 9 additions & 4 deletions test/cli/samples/custom-frame-with-pos/_config.js
@@ -1,10 +1,15 @@
const assert = require('assert');
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
description: 'custom (plugin generated) code frame taking priority over pos generated one',
command: 'rollup -c',
error: () => true,
stderr: stderr => {
assert.ok(/custom code frame/.test(stderr));
}
stderr: stderr =>
assertStderrIncludes(
stderr,
'[!] (plugin at position 1) Error: My error.\n' +
'main.js (1:5)\n' +
'custom code frame\n' +
'Error: My error.'
)
};
12 changes: 9 additions & 3 deletions test/cli/samples/custom-frame/_config.js
@@ -1,10 +1,16 @@
const assert = require('assert');
const { assertStderrIncludes } = require('../../../utils.js');

module.exports = {
description: 'errors with custom (plugin generated) code frame',
description: 'errors with plugin generated code frames also contain stack',
command: 'rollup -c',
error: () => true,
stderr: stderr => {
assert.ok(/custom code frame/.test(stderr));
assertStderrIncludes(
stderr,
'[!] (plugin at position 1) Error: My error.\n' +
'main.js\ncustom code frame\nError: My error.\n' +
' at Object.transform'
);
assertStderrIncludes(stderr, 'rollup.config.js:11:17');
}
};
6 changes: 2 additions & 4 deletions test/cli/samples/empty-chunk-multiple/_config.js
@@ -1,10 +1,8 @@
const assert = require('assert');
const { assertStderrIncludes } = require('../../../utils.js');

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

module.exports = {
description: 'shows warning when chunk empty',
command: 'rollup -c',
error: () => true,
stderr: stderr => {
assert.ok(stderr.includes('(!) Generated an empty chunk\nmain'));
}
stderr: stderr => assertStderrIncludes(stderr, '(!) Generated an empty chunk\nmain')

This comment has been minimized.

Copy link
@tjenkinson

tjenkinson Nov 21, 2019

Member

Interesting I wasn’t expecting this to fail as there was no tc in it

};
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 821888a

Please sign in to comment.