-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
verbose.js
934 lines (800 loc) 路 22.6 KB
/
verbose.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
'use strict';
// These tests are run as a sub-process of the `tap` module, so the standard
// output stream will not be recognized as a text terminal. AVA internals are
// sensitive to this detail and respond by automatically disable output
// coloring. Because the tests are written verify AVA's behavior in text
// terminals, that environment should be simulated prior to loading any
// modules.
process.stdout.isTTY = true;
const indentString = require('indent-string');
const flatten = require('arr-flatten');
const tempWrite = require('temp-write');
const figures = require('figures');
const sinon = require('sinon');
const test = require('tap').test;
const lolex = require('lolex');
const AssertionError = require('../../lib/assert').AssertionError;
const colors = require('../helper/colors');
const VerboseReporter = require('../../lib/reporters/verbose');
const compareLineOutput = require('../helper/compare-line-output');
const errorFromWorker = require('../helper/error-from-worker');
const codeExcerpt = require('../../lib/code-excerpt');
const stackLineRegex = /.+ \(.+:[0-9]+:[0-9]+\)/;
lolex.install({
now: new Date(2014, 11, 19, 17, 19, 12, 200).getTime(),
toFake: [
'Date'
]
});
const time = ' ' + colors.dimGray('[17:19:12]');
function createReporter(options) {
if (options === undefined) {
options = {color: true};
}
const reporter = new VerboseReporter(options);
return reporter;
}
function createRunStatus() {
return {
fileCount: 1,
testCount: 1
};
}
function source(file, line) {
return {
file,
line: line || 1,
isWithinProject: true,
isDependency: false
};
}
test('start', t => {
const reporter = createReporter();
t.is(reporter.start(createRunStatus()), '');
t.end();
});
test('passing test and duration less than threshold', t => {
const reporter = createReporter();
const actualOutput = reporter.test({
title: 'passed',
duration: 90
}, createRunStatus());
const expectedOutput = ' ' + colors.green(figures.tick) + ' passed';
t.is(actualOutput, expectedOutput);
t.end();
});
test('passing test and duration greater than threshold', t => {
const reporter = createReporter();
const actualOutput = reporter.test({
title: 'passed',
duration: 150
}, createRunStatus());
const expectedOutput = ' ' + colors.green(figures.tick) + ' passed' + colors.dimGray(' (150ms)');
t.is(actualOutput, expectedOutput);
t.end();
});
test('don\'t display test title if there is only one anonymous test', t => {
const reporter = createReporter();
const output = reporter.test({
title: '[anonymous]'
}, createRunStatus());
t.is(output, undefined);
t.end();
});
test('known failure test', t => {
const reporter = createReporter();
const actualOutput = reporter.test({
title: 'known failure',
failing: true
}, createRunStatus());
const expectedOutput = ' ' + colors.red(figures.tick) + ' ' + colors.red('known failure');
t.is(actualOutput, expectedOutput);
t.end();
});
test('failing test', t => {
const reporter = createReporter();
const actualOutput = reporter.test({
title: 'failed',
error: {
message: 'assertion failed'
}
}, createRunStatus());
const expectedOutput = ' ' + colors.red(figures.cross) + ' failed ' + colors.red('assertion failed');
t.is(actualOutput, expectedOutput);
t.end();
});
test('skipped test', t => {
const reporter = createReporter();
const actualOutput = reporter.test({
title: 'skipped',
skip: true
}, createRunStatus());
const expectedOutput = ' ' + colors.yellow('- skipped');
t.is(actualOutput, expectedOutput);
t.end();
});
test('todo test', t => {
const reporter = createReporter();
const actualOutput = reporter.test({
title: 'todo',
skip: true,
todo: true
}, createRunStatus());
const expectedOutput = ' ' + colors.blue('- todo');
t.is(actualOutput, expectedOutput);
t.end();
});
test('uncaught exception', t => {
const reporter = createReporter();
const error = errorFromWorker(new Error('Unexpected token'), {
type: 'exception',
file: 'test.js'
});
const output = reporter.unhandledError(error, createRunStatus()).split('\n');
t.is(output[0], colors.red('Uncaught Exception: test.js'));
t.match(output[1], /Error: Unexpected token/);
t.match(output[2], /test\/reporters\/verbose\.js/);
t.end();
});
test('ava error', t => {
const reporter = createReporter();
const output = reporter.unhandledError({
type: 'exception',
file: 'test.js',
name: 'AvaError',
message: 'A futuristic test runner'
}, createRunStatus()).split('\n');
t.is(output[0], colors.red(' ' + figures.cross + ' A futuristic test runner'));
t.end();
});
test('unhandled rejection', t => {
const reporter = createReporter();
const error = errorFromWorker(new Error('Unexpected token'), {
file: 'test.js',
type: 'rejection'
});
const output = reporter.unhandledError(error, createRunStatus()).split('\n');
t.is(output[0], colors.red('Unhandled Rejection: test.js'));
t.match(output[1], /Error: Unexpected token/);
t.match(output[2], /test\/reporters\/verbose\.js/);
t.end();
});
test('unhandled error without stack', t => {
const reporter = createReporter();
const err = errorFromWorker({message: 'test'}, {
file: 'test.js',
type: 'exception'
});
const output = reporter.unhandledError(err, createRunStatus()).split('\n');
t.is(output[0], colors.red('Uncaught Exception: test.js'));
t.is(output[1], ' ' + colors.red(JSON.stringify(err)));
t.end();
});
test('results with passing tests', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.passCount = 1;
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed'),
''
].join('\n');
t.is(actualOutput, expectedOutput);
t.end();
});
test('results with passing known failure tests', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.passCount = 1;
runStatus.knownFailureCount = 1;
runStatus.knownFailures = [{
title: 'known failure',
failing: true
}];
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed'),
' ' + colors.red('1 known failure'),
'',
'',
' ' + colors.red('known failure'),
''
].join('\n');
t.is(actualOutput, expectedOutput);
t.end();
});
test('results with skipped tests', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.passCount = 1;
runStatus.skipCount = 1;
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed'),
' ' + colors.yellow('1 test skipped'),
''
].join('\n');
t.is(actualOutput, expectedOutput);
t.end();
});
test('results with todo tests', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.passCount = 1;
runStatus.todoCount = 1;
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed'),
' ' + colors.blue('1 test todo'),
''
].join('\n');
t.is(actualOutput, expectedOutput);
t.end();
});
test('results with passing tests and rejections', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.passCount = 1;
runStatus.rejectionCount = 1;
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed'),
' ' + colors.red('1 unhandled rejection'),
''
].join('\n');
t.is(actualOutput, expectedOutput);
t.end();
});
test('results with passing tests and exceptions', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.passCount = 1;
runStatus.exceptionCount = 1;
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed'),
' ' + colors.red('1 uncaught exception'),
''
].join('\n');
t.is(actualOutput, expectedOutput);
t.end();
});
test('results with passing tests, rejections and exceptions', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.passCount = 1;
runStatus.exceptionCount = 1;
runStatus.rejectionCount = 1;
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed'),
' ' + colors.red('1 unhandled rejection'),
' ' + colors.red('1 uncaught exception'),
''
].join('\n');
t.is(actualOutput, expectedOutput);
t.end();
});
test('results with errors', t => {
const error1 = errorFromWorker(new AssertionError({message: 'error one message'}));
const err1Path = tempWrite.sync('a()');
error1.source = source(err1Path);
error1.statements = [];
error1.values = [
{label: 'actual:', formatted: JSON.stringify('abc')},
{label: 'expected:', formatted: JSON.stringify('abd')}
];
const error2 = errorFromWorker(new AssertionError({message: 'error two message'}), {
stack: 'error message\nTest.fn (test.js:1:1)'
});
const err2Path = tempWrite.sync('b()');
error2.source = source(err2Path);
error2.statements = [];
error2.values = [
{label: 'actual:', formatted: JSON.stringify([1])},
{label: 'expected:', formatted: JSON.stringify([2])}
];
const error3 = errorFromWorker(new AssertionError({message: 'error three message'}), {
stack: 'error message\nTest.fn (test.js:1:1)'
});
const err3Path = tempWrite.sync('b()');
error3.source = source(err3Path);
error3.statements = [];
error3.values = [
{label: 'error three message:', formatted: JSON.stringify([1])}
];
const reporter = createReporter({color: true});
const runStatus = createRunStatus();
runStatus.failCount = 1;
runStatus.tests = [{
title: 'fail one',
error: error1
}, {
title: 'fail two',
error: error2
}, {
title: 'fail three',
error: error3
}];
const output = reporter.finish(runStatus);
compareLineOutput(t, output, flatten([
'',
' ' + colors.red('1 test failed'),
'',
' ' + colors.boldWhite('fail one'),
' ' + colors.gray(`${error1.source.file}:${error1.source.line}`),
'',
indentString(codeExcerpt(error1.source), 2).split('\n'),
'',
/error one message/,
'',
' actual:',
'',
' "abc"',
'',
' expected:',
'',
' "abd"',
'',
stackLineRegex, compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
'',
'',
'',
' ' + colors.boldWhite('fail two'),
' ' + colors.gray(`${error2.source.file}:${error2.source.line}`),
'',
indentString(codeExcerpt(error2.source), 2).split('\n'),
'',
/error two message/,
'',
' actual:',
'',
' [1]',
'',
' expected:',
'',
' [2]',
'',
'',
'',
' ' + colors.boldWhite('fail three'),
' ' + colors.gray(`${error3.source.file}:${error3.source.line}`),
'',
indentString(codeExcerpt(error3.source), 2).split('\n'),
'',
' error three message:',
'',
' [1]',
''
]));
t.end();
});
test('results with errors and disabled code excerpts', t => {
const error1 = errorFromWorker(new AssertionError({message: 'error one message'}));
delete error1.source;
error1.statements = [];
error1.values = [
{label: 'actual:', formatted: JSON.stringify('abc')},
{label: 'expected:', formatted: JSON.stringify('abd')}
];
const error2 = errorFromWorker(new AssertionError({message: 'error two message'}), {
stack: 'error message\nTest.fn (test.js:1:1)\n'
});
const err2Path = tempWrite.sync('b()');
error2.source = source(err2Path);
error2.statements = [];
error2.values = [
{label: 'actual:', formatted: JSON.stringify([1])},
{label: 'expected:', formatted: JSON.stringify([2])}
];
const reporter = createReporter({color: true});
const runStatus = createRunStatus();
runStatus.failCount = 1;
runStatus.tests = [{
title: 'fail one',
error: error1
}, {
title: 'fail two',
error: error2
}];
const output = reporter.finish(runStatus);
compareLineOutput(t, output, flatten([
'',
' ' + colors.red('1 test failed'),
'',
' ' + colors.boldWhite('fail one'),
'',
/error one message/,
'',
' actual:',
'',
' "abc"',
'',
' expected:',
'',
' "abd"',
'',
stackLineRegex, compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
'',
'',
'',
' ' + colors.boldWhite('fail two'),
' ' + colors.gray(`${error2.source.file}:${error2.source.line}`),
'',
indentString(codeExcerpt(error2.source), 2).split('\n'),
'',
/error two message/,
'',
' actual:',
'',
' [1]',
'',
' expected:',
'',
' [2]',
''
]));
t.end();
});
test('results with errors and disabled code excerpts', t => {
const error1 = errorFromWorker(new AssertionError({message: 'error one message'}));
const err1Path = tempWrite.sync('a();');
error1.source = source(err1Path, 10);
error1.statements = [];
error1.values = [
{label: 'actual:', formatted: JSON.stringify('abc')},
{label: 'expected:', formatted: JSON.stringify('abd')}
];
const error2 = errorFromWorker(new AssertionError({message: 'error two message'}), {
stack: 'error message\nTest.fn (test.js:1:1)\n'
});
const err2Path = tempWrite.sync('b()');
error2.source = source(err2Path);
error2.statements = [];
error2.values = [
{label: 'actual:', formatted: JSON.stringify([1])},
{label: 'expected:', formatted: JSON.stringify([2])}
];
const reporter = createReporter({color: true});
const runStatus = createRunStatus();
runStatus.failCount = 1;
runStatus.tests = [{
title: 'fail one',
error: error1
}, {
title: 'fail two',
error: error2
}];
const output = reporter.finish(runStatus);
compareLineOutput(t, output, flatten([
'',
' ' + colors.red('1 test failed'),
'',
' ' + colors.boldWhite('fail one'),
' ' + colors.gray(`${error1.source.file}:${error1.source.line}`),
'',
/error one message/,
'',
' actual:',
'',
' "abc"',
'',
' expected:',
'',
' "abd"',
'',
stackLineRegex, compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
'',
'',
'',
' ' + colors.boldWhite('fail two'),
' ' + colors.gray(`${error2.source.file}:${error2.source.line}`),
'',
indentString(codeExcerpt(error2.source), 2).split('\n'),
'',
/error two message/,
'',
' actual:',
'',
' [1]',
'',
' expected:',
'',
' [2]',
''
]));
t.end();
});
test('results when fail-fast is enabled', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.remainingCount = 1;
runStatus.failCount = 1;
runStatus.failFastEnabled = true;
runStatus.tests = [{
title: 'failed test'
}];
const output = reporter.finish(runStatus);
const expectedOutput = [
'\n ' + colors.red('1 test failed'),
'\n',
'\n ' + colors.magenta('`--fail-fast` is on. At least 1 test was skipped.'),
'\n'
].join('');
t.is(output, expectedOutput);
t.end();
});
test('results when fail-fast is enabled with multiple skipped tests', t => {
const reporter = new VerboseReporter({color: true});
const runStatus = createRunStatus();
runStatus.remainingCount = 2;
runStatus.failCount = 1;
runStatus.failFastEnabled = true;
runStatus.tests = [{
title: 'failed test'
}];
const output = reporter.finish(runStatus);
const expectedOutput = [
'\n ' + colors.red('1 test failed'),
'\n',
'\n ' + colors.magenta('`--fail-fast` is on. At least 2 tests were skipped.'),
'\n'
].join('');
t.is(output, expectedOutput);
t.end();
});
test('results without fail-fast if no failing tests', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.remainingCount = 1;
runStatus.failCount = 0;
runStatus.passCount = 1;
runStatus.failFastEnabled = true;
const output = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed'),
''
].join('\n');
t.is(output, expectedOutput);
t.end();
});
test('results without fail-fast if no skipped tests', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.remainingCount = 0;
runStatus.failCount = 1;
runStatus.failFastEnabled = true;
runStatus.tests = [{
title: 'failed test'
}];
const output = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.red('1 test failed'),
''
].join('\n');
t.is(output, expectedOutput);
t.end();
});
test('results with 1 previous failure', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.passCount = 1;
runStatus.exceptionCount = 1;
runStatus.previousFailCount = 1;
const output = reporter.finish(runStatus);
compareLineOutput(t, output, [
'',
' ' + colors.green('1 test passed'),
' ' + colors.red('1 uncaught exception'),
' ' + colors.red('1 previous failure in test files that were not rerun'),
''
]);
t.end();
});
test('results with 2 previous failures', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.passCount = 1;
runStatus.exceptionCount = 1;
runStatus.previousFailCount = 2;
const output = reporter.finish(runStatus);
compareLineOutput(t, output, [
'',
' ' + colors.green('1 test passed'),
' ' + colors.red('1 uncaught exception'),
' ' + colors.red('2 previous failures in test files that were not rerun'),
''
]);
t.end();
});
test('full-width line when sectioning', t => {
const reporter = createReporter();
const prevColumns = process.stdout.columns;
process.stdout.columns = 80;
const output = reporter.section();
process.stdout.columns = prevColumns;
t.is(output, colors.dimGray('\u2500'.repeat(80)));
t.end();
});
test('write calls console.error', t => {
const stub = sinon.stub(console, 'error');
const reporter = createReporter();
reporter.write('result');
t.true(stub.called);
console.error.restore();
t.end();
});
test('reporter.stdout and reporter.stderr both use process.stderr.write', t => {
const reporter = createReporter();
const stub = sinon.stub(process.stderr, 'write');
reporter.stdout('result');
reporter.stderr('result');
t.is(stub.callCount, 2);
process.stderr.write.restore();
t.end();
});
test('results when hasExclusive is enabled, but there are no known remaining tests', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.hasExclusive = true;
runStatus.passCount = 1;
const output = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed'),
''
].join('\n');
t.is(output, expectedOutput);
t.end();
});
test('results when hasExclusive is enabled, but there is one remaining tests', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.hasExclusive = true;
runStatus.testCount = 2;
runStatus.passCount = 1;
runStatus.failCount = 0;
runStatus.remainingCount = 1;
const output = reporter.finish(runStatus);
const expectedOutput = [
'\n ' + colors.green('1 test passed'),
'\n',
'\n ' + colors.magenta('The .only() modifier is used in some tests. 1 test was not run'),
'\n'
].join('');
t.is(output, expectedOutput);
t.end();
});
test('results when hasExclusive is enabled, but there are multiple remaining tests', t => {
const reporter = createReporter();
const runStatus = createRunStatus();
runStatus.hasExclusive = true;
runStatus.testCount = 3;
runStatus.passCount = 1;
runStatus.failCount = 0;
runStatus.remainingCount = 2;
const output = reporter.finish(runStatus);
const expectedOutput = [
'\n ' + colors.green('1 test passed'),
'\n',
'\n ' + colors.magenta('The .only() modifier is used in some tests. 2 tests were not run'),
'\n'
].join('');
t.is(output, expectedOutput);
t.end();
});
test('result when no-color flag is set', t => {
const reporter = new VerboseReporter({color: false, watching: true});
const runStatus = createRunStatus();
runStatus.hasExclusive = true;
runStatus.testCount = 3;
runStatus.passCount = 1;
runStatus.failCount = 0;
runStatus.remainingCount = 2;
const output = reporter.finish(runStatus);
const expectedOutput = [
'\n 1 test passed [17:19:12]',
'\n',
'\n The .only() modifier is used in some tests. 2 tests were not run',
'\n'
].join('');
t.is(output, expectedOutput);
t.end();
});
test('timestamp added when watching is enabled', t => {
const reporter = new VerboseReporter({color: true, watching: true});
const runStatus = createRunStatus();
runStatus.testCount = 1;
runStatus.passCount = 1;
runStatus.failCount = 0;
const actualOutput = reporter.finish(runStatus);
const expectedOutput = `\n ${colors.green('1 test passed') + time}\n`;
t.is(actualOutput, expectedOutput);
t.end();
});
test('successful test with logs', t => {
const reporter = createReporter();
const actualOutput = reporter.test({
title: 'successful test',
logs: ['log message 1\nwith a newline', 'log message 2']
}, {});
const expectedOutput = [
' ' + colors.green(figures.tick) + ' successful test',
' ' + colors.magenta(figures.info) + ' ' + colors.gray('log message 1'),
' ' + colors.gray('with a newline'),
' ' + colors.magenta(figures.info) + ' ' + colors.gray('log message 2')
].join('\n');
t.is(actualOutput, expectedOutput);
t.end();
});
test('failed test with logs', t => {
const reporter = createReporter();
const actualOutput = reporter.test({
title: 'failed test',
error: new Error('failure'),
logs: ['log message 1\nwith a newline', 'log message 2']
}, {});
const expectedOutput = [
' ' + colors.red(figures.cross) + ' failed test ' + colors.red('failure'),
' ' + colors.magenta(figures.info) + ' ' + colors.gray('log message 1'),
' ' + colors.gray('with a newline'),
' ' + colors.magenta(figures.info) + ' ' + colors.gray('log message 2')
].join('\n');
t.is(actualOutput, expectedOutput);
t.end();
});
test('results with errors and logs', t => {
const error1 = errorFromWorker(new AssertionError({message: 'error one message'}));
const err1Path = tempWrite.sync('a()');
error1.source = source(err1Path);
error1.statements = [];
error1.values = [
{label: 'actual:', formatted: JSON.stringify('abc')},
{label: 'expected:', formatted: JSON.stringify('abd')}
];
const reporter = createReporter({color: true});
const runStatus = createRunStatus();
runStatus.failCount = 1;
runStatus.tests = [{
title: 'fail one',
logs: ['log from failed test\nwith a newline', 'another log from failed test'],
error: error1
}];
const output = reporter.finish(runStatus);
compareLineOutput(t, output, flatten([
'',
' ' + colors.red('1 test failed'),
'',
' ' + colors.boldWhite('fail one'),
' ' + colors.magenta(figures.info) + ' ' + colors.gray('log from failed test'),
' ' + colors.gray('with a newline'),
' ' + colors.magenta(figures.info) + ' ' + colors.gray('another log from failed test'),
'',
' ' + colors.gray(`${error1.source.file}:${error1.source.line}`),
'',
indentString(codeExcerpt(error1.source), 2).split('\n'),
'',
/error one message/,
'',
' actual:',
'',
' "abc"',
'',
' expected:',
'',
' "abd"',
'',
stackLineRegex, compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
''
]));
t.end();
});