make ErrorMatcher an object rather than a tuple

This commit is contained in:
Nick Fyson 2020-09-11 18:30:07 +01:00
parent 1fb7c81099
commit b3b99014eb
12 changed files with 58 additions and 48 deletions

View file

@ -17,41 +17,41 @@ const toolrunner_error_catcher_1 = require("./toolrunner-error-catcher");
testing_utils_1.setupTests(ava_1.default);
ava_1.default('matchers are never applied if non-error exit', async (t) => {
const testArgs = buildDummyArgs("foo bar\\nblort qux", "foo bar\\nblort qux", '', 0);
const matchers = [[123, new RegExp("foo bar"), 'error!!!']];
const matchers = [{ exitCode: 123, outputRegex: new RegExp("foo bar"), message: 'error!!!' }];
t.deepEqual(await exec.exec('node', testArgs), 0);
t.deepEqual(await toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), 0);
});
ava_1.default('regex matchers are applied to stdout for non-zero exit code', async (t) => {
const testArgs = buildDummyArgs("foo bar\\nblort qux", '', '', 1);
const matchers = [[123, new RegExp("foo bar"), '🦄']];
const matchers = [{ exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄' }];
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
await t.throwsAsync(toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
});
ava_1.default('regex matchers are applied to stderr for non-zero exit code', async (t) => {
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
const matchers = [[123, new RegExp("foo bar"), '🦄']];
const matchers = [{ exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄' }];
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
await t.throwsAsync(toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
});
ava_1.default('matcher returns correct error message when multiple matchers defined', async (t) => {
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
const matchers = [[456, new RegExp("lorem ipsum"), '😩'],
[123, new RegExp("foo bar"), '🦄'],
[789, new RegExp("blah blah"), '🤦‍♂️']];
const matchers = [{ exitCode: 456, outputRegex: new RegExp("lorem ipsum"), message: '😩' },
{ exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄' },
{ exitCode: 789, outputRegex: new RegExp("blah blah"), message: '🤦‍♂️' }];
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
await t.throwsAsync(toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
});
ava_1.default('matcher returns first match to regex when multiple matches', async (t) => {
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
const matchers = [[123, new RegExp("foo bar"), '🦄'],
[789, new RegExp("blah blah"), '🤦‍♂️'],
[987, new RegExp("foo bar"), '🚫']];
const matchers = [{ exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄' },
{ exitCode: 789, outputRegex: new RegExp("blah blah"), message: '🤦‍♂️' },
{ exitCode: 987, outputRegex: new RegExp("foo bar"), message: '🚫' }];
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
await t.throwsAsync(toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
});
ava_1.default('exit code matchers are applied', async (t) => {
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 123);
const matchers = [[123, new RegExp("this will not match"), '🦄']];
const matchers = [{ exitCode: 123, outputRegex: new RegExp("this will not match"), message: '🦄' }];
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 123' });
await t.throwsAsync(toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
});