Skip to content

Commit d8d42b6

Browse files
committed
[Tests] use string encoding with concat-stream and exec
- also be explicit with `exec` encoding
1 parent f7d074e commit d8d42b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+255
-315
lines changed

test/anonymous-fn.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ tap.test('inside anonymous functions', function (tt) {
1111
tt.plan(1);
1212

1313
var test = tape.createHarness();
14-
var tc = function (rows) {
15-
var body = stripFullStack(rows.toString('utf8'));
14+
15+
test.createStream().pipe(concat({ encoding: 'string' }, function (rows) {
16+
var body = stripFullStack(rows);
1617

1718
tt.same(body, [
1819
'TAP version 13',
@@ -35,9 +36,7 @@ tap.test('inside anonymous functions', function (tt) {
3536
'# fail 1',
3637
''
3738
]);
38-
};
39-
40-
test.createStream().pipe(concat(tc));
39+
}));
4140

4241
test('wrapped test failure', testWrapper(function (t) {
4342
t.fail('fail');

test/array.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ tap.test('array test', function (tt) {
1010

1111
var test = tape.createHarness();
1212

13-
test.createStream().pipe(concat(function (rows) {
14-
tt.same(rows.toString('utf8'), [
13+
test.createStream().pipe(concat({ encoding: 'string' }, function (rows) {
14+
tt.same(rows, [
1515
'TAP version 13',
1616
'# array',
1717
'ok 1 should be deeply equivalent',

test/assertion.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ tap.test('using a custom assertion', function (tt) {
1212

1313
var test = tape.createHarness();
1414
var count = 0;
15-
test.createStream().pipe(concat(function (body) {
16-
tt.same(stripFullStack(body.toString('utf8')), [].concat(
15+
test.createStream().pipe(concat({ encoding: 'string' }, function (body) {
16+
tt.same(stripFullStack(body), [].concat(
1717
'TAP version 13',
1818
'# with a custom assertion',
1919
'ok ' + ++count + ' true is ok',

test/async-await.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ try {
2525

2626
tap.test('async1', function (t) {
2727
runProgram('async-await', 'async1.js', function (r) {
28-
t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [
28+
t.deepEqual(stripFullStack(r.stdout), [
2929
'TAP version 13',
3030
'# async1',
3131
'ok 1 before await',
@@ -40,14 +40,14 @@ tap.test('async1', function (t) {
4040
''
4141
]);
4242
t.same(r.exitCode, 0);
43-
t.same(stripDeprecations(r.stderr.toString('utf8')), '');
43+
t.same(stripDeprecations(r.stderr), '');
4444
t.end();
4545
});
4646
});
4747

4848
tap.test('async2', function (t) {
4949
runProgram('async-await', 'async2.js', function (r) {
50-
var stdout = r.stdout.toString('utf8');
50+
var stdout = r.stdout;
5151
var lines = stdout.split('\n').filter(function (line) {
5252
return !(/^(\s+)at(\s+)<anonymous>$/).test(line);
5353
});
@@ -76,14 +76,14 @@ tap.test('async2', function (t) {
7676
''
7777
]);
7878
t.same(r.exitCode, 1);
79-
t.same(stripDeprecations(r.stderr.toString('utf8')), '');
79+
t.same(stripDeprecations(r.stderr), '');
8080
t.end();
8181
});
8282
});
8383

8484
tap.test('async3', function (t) {
8585
runProgram('async-await', 'async3.js', function (r) {
86-
t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [
86+
t.deepEqual(stripFullStack(r.stdout), [
8787
'TAP version 13',
8888
'# async3',
8989
'ok 1 before await',
@@ -98,14 +98,14 @@ tap.test('async3', function (t) {
9898
''
9999
]);
100100
t.same(r.exitCode, 0);
101-
t.same(stripDeprecations(r.stderr.toString('utf8')), '');
101+
t.same(stripDeprecations(r.stderr), '');
102102
t.end();
103103
});
104104
});
105105

106106
tap.test('async4', function (t) {
107107
runProgram('async-await', 'async4.js', function (r) {
108-
t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [
108+
t.deepEqual(stripFullStack(r.stdout), [
109109
'TAP version 13',
110110
'# async4',
111111
'ok 1 before await',
@@ -127,14 +127,14 @@ tap.test('async4', function (t) {
127127
''
128128
]);
129129
t.same(r.exitCode, 1);
130-
t.same(stripDeprecations(r.stderr.toString('utf8')), '');
130+
t.same(stripDeprecations(r.stderr), '');
131131
t.end();
132132
});
133133
});
134134

135135
tap.test('async5', function (t) {
136136
runProgram('async-await', 'async5.js', function (r) {
137-
t.same(stripFullStack(r.stdout.toString('utf8')), [
137+
t.same(stripFullStack(r.stdout), [
138138
'TAP version 13',
139139
'# async5',
140140
'ok 1 before server',
@@ -181,29 +181,28 @@ tap.test('async5', function (t) {
181181
''
182182
]);
183183
t.same(r.exitCode, 1);
184-
t.same(stripDeprecations(r.stderr.toString('utf8')), '');
184+
t.same(stripDeprecations(r.stderr), '');
185185
t.end();
186186
});
187187
});
188188

189189
tap.test('sync-error', function (t) {
190190
runProgram('async-await', 'sync-error.js', function (r) {
191-
t.same(stripFullStack(r.stdout.toString('utf8')), [
191+
t.same(stripFullStack(r.stdout), [
192192
'TAP version 13',
193193
'# sync-error',
194194
'ok 1 before throw',
195195
''
196196
]);
197197
t.same(r.exitCode, 1);
198198

199-
var stderr = r.stderr.toString('utf8');
200-
var lines = stderr.split('\n');
199+
var lines = r.stderr.split('\n');
201200
lines = lines.filter(function (line) {
202201
return !(/\(timers.js:/).test(line)
203202
&& !(/\(internal\/timers.js:/).test(line)
204203
&& !(/Immediate\.next/).test(line);
205204
});
206-
stderr = lines.join('\n');
205+
var stderr = lines.join('\n');
207206

208207
t.same(stripFullStack(stripDeprecations(stderr)), [].concat(
209208
'$TEST/async-await/sync-error.js:7',
@@ -228,12 +227,11 @@ tap.test('sync-error', function (t) {
228227

229228
tap.test('async-error', function (t) {
230229
runProgram('async-await', 'async-error.js', function (r) {
231-
var stdout = r.stdout.toString('utf8');
232-
var lines = stdout.split('\n');
230+
var lines = r.stdout.split('\n');
233231
lines = lines.filter(function (line) {
234232
return !(/^(\s+)at(\s+)<anonymous>$/).test(line);
235233
});
236-
stdout = lines.join('\n');
234+
var stdout = lines.join('\n');
237235

238236
t.same(stripFullStack(stdout), [
239237
'TAP version 13',
@@ -257,7 +255,7 @@ tap.test('async-error', function (t) {
257255
]);
258256
t.same(r.exitCode, 1);
259257

260-
var stderr = stripDeprecations(r.stderr.toString('utf8'));
258+
var stderr = stripDeprecations(r.stderr);
261259
var stderrLines = stderr.split('\n').filter(function (line) {
262260
return !(/\(timers.js:/).test(line)
263261
&& !(/\(internal\/timers.js:/).test(line)
@@ -271,12 +269,11 @@ tap.test('async-error', function (t) {
271269

272270
tap.test('async-bug', function (t) {
273271
runProgram('async-await', 'async-bug.js', function (r) {
274-
var stdout = r.stdout.toString('utf8');
275-
var lines = stdout.split('\n');
272+
var lines = r.stdout.split('\n');
276273
lines = lines.filter(function (line) {
277274
return !(/^(\s+)at(\s+)<anonymous>$/).test(line);
278275
});
279-
stdout = lines.join('\n');
276+
var stdout = lines.join('\n');
280277

281278
t.same(stripFullStack(stdout), [
282279
'TAP version 13',
@@ -301,7 +298,7 @@ tap.test('async-bug', function (t) {
301298
]);
302299
t.same(r.exitCode, 1);
303300

304-
var stderr = stripDeprecations(r.stderr.toString('utf8'));
301+
var stderr = stripDeprecations(r.stderr);
305302

306303
t.same(stderr, '');
307304
t.end();

test/capture.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ tap.test('capture: output', function (tt) {
1414

1515
var test = tape.createHarness();
1616
var count = 0;
17-
test.createStream().pipe(concat(function (body) {
18-
tt.same(stripFullStack(body.toString('utf8')), [].concat(
17+
test.createStream().pipe(concat({ encoding: 'string' }, function (body) {
18+
tt.same(stripFullStack(body), [].concat(
1919
'TAP version 13',
2020
'# argument validation',
2121
v.primitives.map(function (x) {

test/captureFn.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ tap.test('captureFn: output', function (tt) {
1414

1515
var test = tape.createHarness();
1616
var count = 0;
17-
test.createStream().pipe(concat(function (body) {
18-
tt.same(stripFullStack(body.toString('utf8')), [].concat(
17+
test.createStream().pipe(concat({ encoding: 'string' }, function (body) {
18+
tt.same(stripFullStack(body), [].concat(
1919
'TAP version 13',
2020
'# argument validation',
2121
v.nonFunctions.map(function (x) {

test/circular-things.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ tap.test('circular test', function (assert) {
1010
var test = tape.createHarness({ exit: false });
1111
assert.plan(1);
1212

13-
test.createStream().pipe(concat(function (body) {
14-
assert.deepEqual(stripFullStack(body.toString('utf8')), [
13+
test.createStream().pipe(concat({ encoding: 'string' }, function (body) {
14+
assert.deepEqual(stripFullStack(body), [
1515
'TAP version 13',
1616
'# circular',
1717
'not ok 1 should be strictly equal',

test/comment.js

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ var tape = require('../');
99
tap.test('no comment', function (assert) {
1010
assert.plan(1);
1111

12-
var verify = function (output) {
13-
assert.deepEqual(output.toString('utf8').split('\n'), [
12+
var test = tape.createHarness();
13+
test.createStream().pipe(concat({ encoding: 'string' }, function (output) {
14+
assert.deepEqual(output.split('\n'), [
1415
'TAP version 13',
1516
'# no comment',
1617
'',
@@ -21,10 +22,7 @@ tap.test('no comment', function (assert) {
2122
'# ok',
2223
''
2324
]);
24-
};
25-
26-
var test = tape.createHarness();
27-
test.createStream().pipe(concat(verify));
25+
}));
2826
test('no comment', function (t) {
2927
t.end();
3028
});
@@ -68,8 +66,9 @@ tap.test('null argument', function (assert) {
6866
tap.test('whitespace', function (assert) {
6967
assert.plan(1);
7068

71-
var verify = function (output) {
72-
assert.equal(output.toString('utf8'), [
69+
var test = tape.createHarness();
70+
test.createStream().pipe(concat({ encoding: 'string' }, function (output) {
71+
assert.equal(output, [
7372
'TAP version 13',
7473
'# whitespace',
7574
'# ',
@@ -84,10 +83,7 @@ tap.test('whitespace', function (assert) {
8483
'# ok',
8584
''
8685
].join('\n'));
87-
};
88-
89-
var test = tape.createHarness();
90-
test.createStream().pipe(concat(verify));
86+
}));
9187
test('whitespace', function (t) {
9288
t.comment(' ');
9389
t.comment(' a');
@@ -101,8 +97,9 @@ tap.test('whitespace', function (assert) {
10197
tap.test('non-string types', function (assert) {
10298
assert.plan(1);
10399

104-
var verify = function (output) {
105-
assert.equal(output.toString('utf8'), [
100+
var test = tape.createHarness();
101+
test.createStream().pipe(concat({ encoding: 'string' }, function (output) {
102+
assert.equal(output, [
106103
'TAP version 13',
107104
'# non-string types',
108105
'# true',
@@ -121,10 +118,8 @@ tap.test('non-string types', function (assert) {
121118
'# ok',
122119
''
123120
].join('\n'));
124-
};
121+
}));
125122

126-
var test = tape.createHarness();
127-
test.createStream().pipe(concat(verify));
128123
test('non-string types', function (t) {
129124
t.comment(true);
130125
t.comment(false);
@@ -142,8 +137,9 @@ tap.test('non-string types', function (assert) {
142137
tap.test('multiline string', function (assert) {
143138
assert.plan(1);
144139

145-
var verify = function (output) {
146-
assert.equal(output.toString('utf8'), [
140+
var test = tape.createHarness();
141+
test.createStream().pipe(concat({ encoding: 'string' }, function (output) {
142+
assert.equal(output, [
147143
'TAP version 13',
148144
'# multiline strings',
149145
'# a',
@@ -158,10 +154,7 @@ tap.test('multiline string', function (assert) {
158154
'# ok',
159155
''
160156
].join('\n'));
161-
};
162-
163-
var test = tape.createHarness();
164-
test.createStream().pipe(concat(verify));
157+
}));
165158
test('multiline strings', function (t) {
166159
t.comment([
167160
'a',

test/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ module.exports.runProgram = function (folderName, fileName, cb) {
116116
path.join(__dirname, folderName, fileName)
117117
]);
118118

119-
ps.stdout.pipe(concat(function (stdoutRows) {
119+
ps.stdout.pipe(concat({ encoding: 'string' }, function (stdoutRows) {
120120
result.stdout = stdoutRows;
121121
}));
122-
ps.stderr.pipe(concat(function (stderrRows) {
122+
ps.stderr.pipe(concat({ encoding: 'string' }, function (stderrRows) {
123123
result.stderr = stderrRows;
124124
}));
125125

test/deep-equal-failure.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ tap.test('deep equal failure', function (assert) {
1616
assert.plan(3);
1717

1818
stream.pipe(parser);
19-
stream.pipe(concat(function (body) {
20-
assert.deepEqual(stripFullStack(body.toString('utf8')), [
19+
stream.pipe(concat({ encoding: 'string' }, function (body) {
20+
assert.deepEqual(stripFullStack(body), [
2121
'TAP version 13',
2222
'# deep equal',
2323
'not ok 1 should be strictly equal',
@@ -78,8 +78,8 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {
7878
assert.plan(3);
7979

8080
stream.pipe(parser);
81-
stream.pipe(concat(function (body) {
82-
assert.deepEqual(stripFullStack(body.toString('utf8')), [
81+
stream.pipe(concat({ encoding: 'string' }, function (body) {
82+
assert.deepEqual(stripFullStack(body), [
8383
'TAP version 13',
8484
'# deep equal',
8585
'not ok 1 should be strictly equal',
@@ -140,8 +140,8 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
140140
assert.plan(3);
141141

142142
stream.pipe(parser);
143-
stream.pipe(concat(function (body) {
144-
assert.deepEqual(stripFullStack(body.toString('utf8')), [
143+
stream.pipe(concat({ encoding: 'string' }, function (body) {
144+
assert.deepEqual(stripFullStack(body), [
145145
'TAP version 13',
146146
'# deep equal',
147147
'not ok 1 should be strictly equal',

0 commit comments

Comments
 (0)