UNPKG

1.49 kBJavaScriptView Raw
1'use strict';
2var fs = require('fs');
3var standardReporter = require('../standard-reporter');
4var path = require('path');
5var test = require('tape');
6var through2 = require('through2');
7var series = require('run-series');
8
9var fixturePath = path.join(__dirname, 'fixture.stdout');
10
11var types = ['json', 'stylish', 'checkstyle', 'none'];
12
13test('reporters', function t(assert) {
14 var tests = types.map(function makeTest(type) {
15 return checkType(type, assert);
16 });
17 series(tests, assert.end);
18});
19
20function checkType(type, assert) {
21 return function testType(done) {
22 var expectedStdout = path.join(__dirname, 'expected-' + type +
23 '.stdout');
24 var fixtureStream = fs.createReadStream(fixturePath, 'utf8');
25 var output = '';
26
27 var sink = through2(collectOutput, flush);
28
29 function collectOutput(chunk, enc, callback) {
30 output += chunk;
31 callback();
32 }
33
34 function flush(callback) {
35 fs.readFile(expectedStdout, 'utf8', onExpectedStdout);
36
37 function onExpectedStdout(err, stdout) {
38 if (err) {
39 assert.error(err);
40 }
41 assert.equal(output, stdout, type + ' reporter stdout');
42 callback();
43 }
44 }
45
46 sink.on('finish', done);
47
48 fixtureStream.pipe(standardReporter({
49 type: type,
50 colors: false,
51 sink: sink
52 }));
53
54 };
55}