|
2 | 2 | const indentString = require('indent-string');
|
3 | 3 | const tempWrite = require('temp-write');
|
4 | 4 | const flatten = require('arr-flatten');
|
| 5 | +const figures = require('figures'); |
5 | 6 | const chalk = require('chalk');
|
6 | 7 | const sinon = require('sinon');
|
7 | 8 | const test = require('tap').test;
|
@@ -934,3 +935,56 @@ test('result when no-color flag is set', t => {
|
934 | 935 | t.is(output, expectedOutput);
|
935 | 936 | t.end();
|
936 | 937 | });
|
| 938 | + |
| 939 | +test('results with errors and logs', t => { |
| 940 | + const err1 = new Error('failure one'); |
| 941 | + err1.stack = beautifyStack(err1.stack); |
| 942 | + const err1Path = tempWrite.sync('a();'); |
| 943 | + err1.source = source(err1Path); |
| 944 | + err1.avaAssertionError = true; |
| 945 | + err1.statements = []; |
| 946 | + err1.values = [ |
| 947 | + {label: 'actual:', formatted: JSON.stringify('abc') + '\n'}, |
| 948 | + {label: 'expected:', formatted: JSON.stringify('abd') + '\n'} |
| 949 | + ]; |
| 950 | + |
| 951 | + const reporter = miniReporter(); |
| 952 | + reporter.failCount = 1; |
| 953 | + |
| 954 | + const runStatus = { |
| 955 | + errors: [{ |
| 956 | + title: 'failed one', |
| 957 | + logs: ['log from a failed test\nwith a newline', 'another log from failed test'], |
| 958 | + error: err1 |
| 959 | + }] |
| 960 | + }; |
| 961 | + |
| 962 | + const output = reporter.finish(runStatus); |
| 963 | + compareLineOutput(t, output, flatten([ |
| 964 | + '', |
| 965 | + ' ' + chalk.red('1 failed'), |
| 966 | + '', |
| 967 | + ' ' + chalk.bold.white('failed one'), |
| 968 | + ' ' + chalk.magenta(figures.info) + ' ' + chalk.gray('log from a failed test'), |
| 969 | + ' ' + chalk.gray('with a newline'), |
| 970 | + ' ' + chalk.magenta(figures.info) + ' ' + chalk.gray('another log from failed test'), |
| 971 | + '', |
| 972 | + ' ' + chalk.grey(`${err1.source.file}:${err1.source.line}`), |
| 973 | + '', |
| 974 | + indentString(codeExcerpt(err1.source), 2).split('\n'), |
| 975 | + '', |
| 976 | + /failure one/, |
| 977 | + '', |
| 978 | + ' actual:', |
| 979 | + '', |
| 980 | + ' "abc"', |
| 981 | + '', |
| 982 | + ' expected:', |
| 983 | + '', |
| 984 | + ' "abd"', |
| 985 | + '', |
| 986 | + stackLineRegex, compareLineOutput.SKIP_UNTIL_EMPTY_LINE, |
| 987 | + '' |
| 988 | + ])); |
| 989 | + t.end(); |
| 990 | +}); |
0 commit comments