1 | 'use strict';
|
2 |
|
3 | var concat = require('concat-stream');
|
4 | var tap = require('tap');
|
5 | var tape = require('../');
|
6 |
|
7 |
|
8 |
|
9 | tap.test('no comment', function (assert) {
|
10 | assert.plan(1);
|
11 |
|
12 | var verify = function (output) {
|
13 | assert.deepEqual(output.toString('utf8').split('\n'), [
|
14 | 'TAP version 13',
|
15 | '# no comment',
|
16 | '',
|
17 | '1..0',
|
18 | '# tests 0',
|
19 | '# pass 0',
|
20 | '',
|
21 | '# ok',
|
22 | ''
|
23 | ]);
|
24 | };
|
25 |
|
26 | var test = tape.createHarness();
|
27 | test.createStream().pipe(concat(verify));
|
28 | test('no comment', function (t) {
|
29 | t.end();
|
30 | });
|
31 | });
|
32 |
|
33 |
|
34 | tap.test('missing argument', function (assert) {
|
35 | assert.plan(1);
|
36 | var test = tape.createHarness();
|
37 | test.createStream();
|
38 | test('missing argument', function (t) {
|
39 | try {
|
40 | t.comment();
|
41 | t.end();
|
42 | } catch (err) {
|
43 | assert.equal(err.constructor, TypeError);
|
44 | } finally {
|
45 | assert.end();
|
46 | }
|
47 | });
|
48 | });
|
49 |
|
50 |
|
51 | tap.test('null argument', function (assert) {
|
52 | assert.plan(1);
|
53 | var test = tape.createHarness();
|
54 | test.createStream();
|
55 | test('null argument', function (t) {
|
56 | try {
|
57 | t.comment(null);
|
58 | t.end();
|
59 | } catch (err) {
|
60 | assert.equal(err.constructor, TypeError);
|
61 | } finally {
|
62 | assert.end();
|
63 | }
|
64 | });
|
65 | });
|
66 |
|
67 |
|
68 | tap.test('whitespace', function (assert) {
|
69 | assert.plan(1);
|
70 |
|
71 | var verify = function (output) {
|
72 | assert.equal(output.toString('utf8'), [
|
73 | 'TAP version 13',
|
74 | '# whitespace',
|
75 | '# ',
|
76 | '# a',
|
77 | '# a',
|
78 | '# a',
|
79 | '',
|
80 | '1..0',
|
81 | '# tests 0',
|
82 | '# pass 0',
|
83 | '',
|
84 | '# ok',
|
85 | ''
|
86 | ].join('\n'));
|
87 | };
|
88 |
|
89 | var test = tape.createHarness();
|
90 | test.createStream().pipe(concat(verify));
|
91 | test('whitespace', function (t) {
|
92 | t.comment(' ');
|
93 | t.comment(' a');
|
94 | t.comment('a ');
|
95 | t.comment(' a ');
|
96 | t.end();
|
97 | });
|
98 | });
|
99 |
|
100 |
|
101 | tap.test('non-string types', function (assert) {
|
102 | assert.plan(1);
|
103 |
|
104 | var verify = function (output) {
|
105 | assert.equal(output.toString('utf8'), [
|
106 | 'TAP version 13',
|
107 | '# non-string types',
|
108 | '# true',
|
109 | '# false',
|
110 | '# 42',
|
111 | '# 6.66',
|
112 | '# [object Object]',
|
113 | '# [object Object]',
|
114 | '# [object Object]',
|
115 | '# function ConstructorFunction() {}',
|
116 | '',
|
117 | '1..0',
|
118 | '# tests 0',
|
119 | '# pass 0',
|
120 | '',
|
121 | '# ok',
|
122 | ''
|
123 | ].join('\n'));
|
124 | };
|
125 |
|
126 | var test = tape.createHarness();
|
127 | test.createStream().pipe(concat(verify));
|
128 | test('non-string types', function (t) {
|
129 | t.comment(true);
|
130 | t.comment(false);
|
131 | t.comment(42);
|
132 | t.comment(6.66);
|
133 | t.comment({});
|
134 | t.comment({ answer: 42 });
|
135 | function ConstructorFunction() {}
|
136 | t.comment(new ConstructorFunction());
|
137 | t.comment(ConstructorFunction);
|
138 | t.end();
|
139 | });
|
140 | });
|
141 |
|
142 | tap.test('multiline string', function (assert) {
|
143 | assert.plan(1);
|
144 |
|
145 | var verify = function (output) {
|
146 | assert.equal(output.toString('utf8'), [
|
147 | 'TAP version 13',
|
148 | '# multiline strings',
|
149 | '# a',
|
150 | '# b',
|
151 | '# c',
|
152 | '# d',
|
153 | '',
|
154 | '1..0',
|
155 | '# tests 0',
|
156 | '# pass 0',
|
157 | '',
|
158 | '# ok',
|
159 | ''
|
160 | ].join('\n'));
|
161 | };
|
162 |
|
163 | var test = tape.createHarness();
|
164 | test.createStream().pipe(concat(verify));
|
165 | test('multiline strings', function (t) {
|
166 | t.comment([
|
167 | 'a',
|
168 | 'b'
|
169 | ].join('\n'));
|
170 | t.comment([
|
171 | 'c',
|
172 | 'd'
|
173 | ].join('\r\n'));
|
174 | t.end();
|
175 | });
|
176 | });
|
177 |
|
178 | tap.test('comment with createStream/objectMode', function (assert) {
|
179 | assert.plan(1);
|
180 |
|
181 | var test = tape.createHarness();
|
182 | test.createStream({ objectMode: true }).on('data', function (row) {
|
183 | if (typeof row === 'string') {
|
184 | assert.equal(row, 'comment message');
|
185 | }
|
186 | });
|
187 | test('t.comment', function (t) {
|
188 | t.comment('comment message');
|
189 | t.end();
|
190 | });
|
191 | });
|