deno.land / std@0.166.0 / node / _tools / test / parallel / test-console-group.js

test-console-group.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
// deno-fmt-ignore-file// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.// Taken from Node 18.12.0// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';require('../common');const { hijackStdout, hijackStderr, restoreStdout, restoreStderr} = require('../common/hijackstdio');
const assert = require('assert');const Console = require('console').Console;
let c, stdout, stderr;
function setup(groupIndentation) { stdout = ''; hijackStdout(function(data) { stdout += data; });
stderr = ''; hijackStderr(function(data) { stderr += data; });
c = new Console({ stdout: process.stdout, stderr: process.stderr, colorMode: false, groupIndentation: groupIndentation });}
function teardown() { restoreStdout(); restoreStderr();}
// Basic group() functionality{ setup(); const expectedOut = 'This is the outer level\n' + ' Level 2\n' + ' Level 3\n' + ' Back to level 2\n' + 'Back to the outer level\n' + 'Still at the outer level\n';

const expectedErr = ' More of level 3\n';
c.log('This is the outer level'); c.group(); c.log('Level 2'); c.group(); c.log('Level 3'); c.warn('More of level 3'); c.groupEnd(); c.log('Back to level 2'); c.groupEnd(); c.log('Back to the outer level'); c.groupEnd(); c.log('Still at the outer level');
assert.strictEqual(stdout, expectedOut); assert.strictEqual(stderr, expectedErr); teardown();}
// Group indentation is tracked per Console instance.{ setup(); const expectedOut = 'No indentation\n' + 'None here either\n' + ' Now the first console is indenting\n' + 'But the second one does not\n'; const expectedErr = '';
const c2 = new Console(process.stdout, process.stderr); c.log('No indentation'); c2.log('None here either'); c.group(); c.log('Now the first console is indenting'); c2.log('But the second one does not');
assert.strictEqual(stdout, expectedOut); assert.strictEqual(stderr, expectedErr); teardown();}
// Make sure labels work.{ setup(); const expectedOut = 'This is a label\n' + ' And this is the data for that label\n'; const expectedErr = '';
c.group('This is a label'); c.log('And this is the data for that label');
assert.strictEqual(stdout, expectedOut); assert.strictEqual(stderr, expectedErr); teardown();}
// Check that console.groupCollapsed() is an alias of console.group(){ setup(); const expectedOut = 'Label\n' + ' Level 2\n' + ' Level 3\n'; const expectedErr = '';
c.groupCollapsed('Label'); c.log('Level 2'); c.groupCollapsed(); c.log('Level 3');
assert.strictEqual(stdout, expectedOut); assert.strictEqual(stderr, expectedErr); teardown();}
// Check that multiline strings and object output are indented properly.{ setup(); const expectedOut = 'not indented\n' + ' indented\n' + ' also indented\n' + ' {\n' + " also: 'a',\n" + " multiline: 'object',\n" + " should: 'be',\n" + " indented: 'properly',\n" + " kthx: 'bai'\n" + ' }\n'; const expectedErr = '';
c.log('not indented'); c.group(); c.log('indented\nalso indented'); c.log({ also: 'a', multiline: 'object', should: 'be', indented: 'properly', kthx: 'bai' });
assert.strictEqual(stdout, expectedOut); assert.strictEqual(stderr, expectedErr); teardown();}
// Check that the kGroupIndent symbol property is not enumerable{ const keys = Reflect.ownKeys(console) .filter((val) => Object.prototype.propertyIsEnumerable.call(console, val)) .map((val) => val.toString()); assert(!keys.includes('Symbol(groupIndent)'), 'groupIndent should not be enumerable');}
// Check custom groupIndentation.{ setup(3); const expectedOut = 'Set the groupIndentation parameter to 3\n' + 'This is the outer level\n' + ' Level 2\n' + ' Level 3\n' + ' Back to level 2\n' + 'Back to the outer level\n' + 'Still at the outer level\n';

const expectedErr = ' More of level 3\n';
c.log('Set the groupIndentation parameter to 3'); c.log('This is the outer level'); c.group(); c.log('Level 2'); c.group(); c.log('Level 3'); c.warn('More of level 3'); c.groupEnd(); c.log('Back to level 2'); c.groupEnd(); c.log('Back to the outer level'); c.groupEnd(); c.log('Still at the outer level');
assert.strictEqual(stdout, expectedOut); assert.strictEqual(stderr, expectedErr); teardown();}
// Check the correctness of the groupIndentation parameter.{ // TypeError [null, 'str', [], false, true, {}].forEach((e) => { assert.throws( () => { new Console({ stdout: process.stdout, stderr: process.stderr, groupIndentation: e }); }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' } ); });
// RangeError for integer [NaN, 1.01].forEach((e) => { assert.throws( () => { new Console({ stdout: process.stdout, stderr: process.stderr, groupIndentation: e }); }, { code: 'ERR_OUT_OF_RANGE', name: 'RangeError', message: /an integer/, } ); });
// RangeError [-1, 1001].forEach((e) => { assert.throws( () => { new Console({ stdout: process.stdout, stderr: process.stderr, groupIndentation: e }); }, { code: 'ERR_OUT_OF_RANGE', name: 'RangeError', message: />= 0 && <= 1000/, } ); });}
std

Version Info

Tagged at
a year ago