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

@ -11,7 +11,7 @@ test('matchers are never applied if non-error exit', async t => {
const testArgs = buildDummyArgs("foo bar\\nblort qux", "foo bar\\nblort qux", '', 0);
const matchers: ErrorMatcher[] = [[123, new RegExp("foo bar"), 'error!!!']];
const matchers: ErrorMatcher[] = [{exitCode: 123, outputRegex: new RegExp("foo bar"), message: 'error!!!' }];
t.deepEqual(await exec.exec('node', testArgs), 0);
@ -23,7 +23,7 @@ test('regex matchers are applied to stdout for non-zero exit code', async t => {
const testArgs = buildDummyArgs("foo bar\\nblort qux", '', '', 1);
const matchers: ErrorMatcher[] = [[123, new RegExp("foo bar"), '🦄']];
const matchers: ErrorMatcher[] = [{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'});
@ -38,7 +38,7 @@ test('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: ErrorMatcher[] = [[123, new RegExp("foo bar"), '🦄']];
const matchers: ErrorMatcher[] = [{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'});
@ -53,9 +53,9 @@ test('matcher returns correct error message when multiple matchers defined', asy
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
const matchers: ErrorMatcher[] = [[456, new RegExp("lorem ipsum"), '😩'],
[123, new RegExp("foo bar"), '🦄'],
[789, new RegExp("blah blah"), '🤦‍♂️']];
const matchers: ErrorMatcher[] = [{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'});
@ -70,9 +70,9 @@ test('matcher returns first match to regex when multiple matches', async t => {
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
const matchers: ErrorMatcher[] = [[123, new RegExp("foo bar"), '🦄'],
[789, new RegExp("blah blah"), '🤦‍♂️'],
[987, new RegExp("foo bar"), '🚫']];
const matchers: ErrorMatcher[] = [{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'});
@ -87,7 +87,7 @@ test('exit code matchers are applied', async t => {
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 123);
const matchers: ErrorMatcher[] = [[123, new RegExp("this will not match"), '🦄']];
const matchers: ErrorMatcher[] = [{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'});