|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var test = require('tape'); |
| 4 | +var stream = require('stream'); |
| 5 | +var path = require('path'); |
| 6 | +var fs = require('fs'); |
| 7 | +var faucet = require('../..'); |
| 8 | + |
| 9 | +function createFormatter() { |
| 10 | + return faucet({ width: 80 }); |
| 11 | +} |
| 12 | + |
| 13 | +function streamifyString(string) { |
| 14 | + return new stream.Readable({ |
| 15 | + read: function () { |
| 16 | + this.push(string); |
| 17 | + this.push(null); |
| 18 | + } |
| 19 | + }); |
| 20 | +} |
| 21 | + |
| 22 | +function stringifyStream(theStream, callback) { |
| 23 | + var output = ''; |
| 24 | + theStream.on('data', function (chunk) { |
| 25 | + output += chunk; |
| 26 | + }).on('end', function () { |
| 27 | + callback(output); |
| 28 | + }); |
| 29 | +} |
| 30 | + |
| 31 | +function getFilePath(name) { |
| 32 | + return path.join(__dirname, name + '.tap'); |
| 33 | +} |
| 34 | + |
| 35 | +function checkFormatting(t, name, expectedExcerpt) { |
| 36 | + var tapString = fs.readFileSync(getFilePath(name), 'utf-8'); |
| 37 | + var formattedStream = streamifyString(tapString).pipe(createFormatter()); |
| 38 | + stringifyStream(formattedStream, function (actualOutput) { |
| 39 | + var contains = actualOutput.indexOf(expectedExcerpt) > 0; |
| 40 | + |
| 41 | + t.ok(contains, 'Looking for "' + expectedExcerpt + '" in the "' + name + '" input.'); |
| 42 | + |
| 43 | + t.end(); |
| 44 | + }); |
| 45 | +} |
| 46 | + |
| 47 | +test('A long successful assertion message should be cut.', function (t) { |
| 48 | + checkFormatting(t, 'succeeded', 'should start with "Unrecogn...'); |
| 49 | +}); |
| 50 | + |
| 51 | +test('A long failed assertion message should be cut.', function (t) { |
| 52 | + checkFormatting(t, 'failed', 'should start with "Unre...'); |
| 53 | +}); |
0 commit comments