UNPKG

4.26 kBJavaScriptView Raw
1'use strict';
2
3var concat = require('concat-stream');
4var tap = require('tap');
5var tape = require('../');
6
7// Exploratory test to ascertain proper output when no t.comment() call
8// is made.
9tap.test('no comment', function (assert) {
10 assert.plan(1);
11
12 var verify = function (output) {
13 assert.equal(output.toString('utf8'), [
14 'TAP version 13',
15 '# no comment',
16 '',
17 '1..0',
18 '# tests 0',
19 '# pass 0',
20 '',
21 '# ok',
22 ''
23 ].join('\n'));
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// Exploratory test, can we call t.comment() passing nothing?
34tap.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// Exploratory test, can we call t.comment() passing nothing?
51tap.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// Exploratory test, how is whitespace treated?
69tap.test('whitespace', function (assert) {
70 assert.plan(1);
71
72 var verify = function (output) {
73 assert.equal(output.toString('utf8'), [
74 'TAP version 13',
75 '# whitespace',
76 '# ',
77 '# a',
78 '# a',
79 '# a',
80 '',
81 '1..0',
82 '# tests 0',
83 '# pass 0',
84 '',
85 '# ok',
86 ''
87 ].join('\n'));
88 };
89
90 var test = tape.createHarness();
91 test.createStream().pipe(concat(verify));
92 test('whitespace', function (t) {
93 t.comment(' ');
94 t.comment(' a');
95 t.comment('a ');
96 t.comment(' a ');
97 t.end();
98 });
99});
100
101// Exploratory test, how about passing types other than strings?
102tap.test('non-string types', function (assert) {
103 assert.plan(1);
104
105 var verify = function (output) {
106 assert.equal(output.toString('utf8'), [
107 'TAP version 13',
108 '# non-string types',
109 '# true',
110 '# false',
111 '# 42',
112 '# 6.66',
113 '# [object Object]',
114 '# [object Object]',
115 '# [object Object]',
116 '# function ConstructorFunction() {}',
117 '',
118 '1..0',
119 '# tests 0',
120 '# pass 0',
121 '',
122 '# ok',
123 ''
124 ].join('\n'));
125 };
126
127 var test = tape.createHarness();
128 test.createStream().pipe(concat(verify));
129 test('non-string types', function (t) {
130 t.comment(true);
131 t.comment(false);
132 t.comment(42);
133 t.comment(6.66);
134 t.comment({});
135 t.comment({'answer': 42});
136 function ConstructorFunction() {}
137 t.comment(new ConstructorFunction());
138 t.comment(ConstructorFunction);
139 t.end();
140 });
141});
142
143tap.test('multiline string', function (assert) {
144 assert.plan(1);
145
146 var verify = function (output) {
147 assert.equal(output.toString('utf8'), [
148 'TAP version 13',
149 '# multiline strings',
150 '# a',
151 '# b',
152 '# c',
153 '# d',
154 '',
155 '1..0',
156 '# tests 0',
157 '# pass 0',
158 '',
159 '# ok',
160 ''
161 ].join('\n'));
162 };
163
164 var test = tape.createHarness();
165 test.createStream().pipe(concat(verify));
166 test('multiline strings', function (t) {
167 t.comment([
168 'a',
169 'b',
170 ].join('\n'));
171 t.comment([
172 'c',
173 'd',
174 ].join('\r\n'));
175 t.end();
176 });
177});