UNPKG

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