14
} from 'react-devtools-shared/src/utils';
15
import {stackToComponentSources} from 'react-devtools-shared/src/devtools/utils';
16
import {
17
- format,
17
+ formatConsoleArguments,
18
+ formatConsoleArgumentsToSingleString,
19
formatWithStyles,
20
gt,
21
gte,
124
});
125
});
126
126
- describe('format', () => {
127
- // @reactVersion >= 16.0
127
+ describe('formatConsoleArgumentsToSingleString', () => {
128
it('should format simple strings', () => {
129
- expect(format('a', 'b', 'c')).toEqual('a b c');
129
+ expect(formatConsoleArgumentsToSingleString('a', 'b', 'c')).toEqual(
130
+ 'a b c',
131
+ );
132
});
133
132
- // @reactVersion >= 16.0
134
it('should format multiple argument types', () => {
134
- expect(format('abc', 123, true)).toEqual('abc 123 true');
135
+ expect(formatConsoleArgumentsToSingleString('abc', 123, true)).toEqual(
136
+ 'abc 123 true',
137
+ );
138
});
139
137
- // @reactVersion >= 16.0
140
it('should support string substitutions', () => {
139
- expect(format('a %s b %s c', 123, true)).toEqual('a 123 b true c');
141
+ expect(
142
+ formatConsoleArgumentsToSingleString('a %s b %s c', 123, true),
143
+ ).toEqual('a 123 b true c');
144
});
145
142
- // @reactVersion >= 16.0
146
it('should gracefully handle Symbol types', () => {
144
- expect(format(Symbol('a'), 'b', Symbol('c'))).toEqual(
145
- 'Symbol(a) b Symbol(c)',
146
- );
147
+ expect(
148
+ formatConsoleArgumentsToSingleString(Symbol('a'), 'b', Symbol('c')),
149
+ ).toEqual('Symbol(a) b Symbol(c)');
150
});
151
149
- // @reactVersion >= 16.0
152
it('should gracefully handle Symbol type for the first argument', () => {
151
- expect(format(Symbol('abc'), 123)).toEqual('Symbol(abc) 123');
153
+ expect(formatConsoleArgumentsToSingleString(Symbol('abc'), 123)).toEqual(
154
+ 'Symbol(abc) 123',
155
+ );
156
});
157
});
158
159
describe('formatWithStyles', () => {
156
- // @reactVersion >= 16.0
160
it('should format empty arrays', () => {
161
expect(formatWithStyles([])).toEqual([]);
162
expect(formatWithStyles([], 'gray')).toEqual([]);
163
expect(formatWithStyles(undefined)).toEqual(undefined);
164
});
165
163
- // @reactVersion >= 16.0
166
it('should bail out of strings with styles', () => {
167
expect(
168
formatWithStyles(['%ca', 'color: green', 'b', 'c'], 'color: gray'),
169
).toEqual(['%ca', 'color: green', 'b', 'c']);
170
});
171
170
- // @reactVersion >= 16.0
172
it('should format simple strings', () => {
173
expect(formatWithStyles(['a'])).toEqual(['a']);
174
187
]);
188
});
189
189
- // @reactVersion >= 16.0
190
it('should format string substituions', () => {
191
expect(
192
formatWithStyles(['%s %s %s', 'a', 'b', 'c'], 'color: gray'),
199
);
200
});
201
202
- // @reactVersion >= 16.0
202
it('should support multiple argument types', () => {
203
const symbol = Symbol('a');
204
expect(
218
]);
219
});
220
222
- // @reactVersion >= 16.0
221
it('should properly format escaped string substituions', () => {
222
expect(formatWithStyles(['%%s'], 'color: gray')).toEqual([
223
'%c%s',
232
expect(formatWithStyles(['%%c%c'], 'color: gray')).toEqual(['%%c%c']);
233
});
234
237
- // @reactVersion >= 16.0
235
it('should format non string inputs as the first argument', () => {
236
expect(formatWithStyles([{foo: 'bar'}])).toEqual([{foo: 'bar'}]);
237
expect(formatWithStyles([[1, 2, 3]])).toEqual([[1, 2, 3]]);
384
});
385
});
386
});
387
+
388
+ describe('formatConsoleArguments', () => {
389
+ it('works with empty arguments list', () => {
390
+ expect(formatConsoleArguments(...[])).toEqual([]);
391
+ });
392
+
393
+ it('works for string without escape sequences', () => {
394
+ expect(
395
+ formatConsoleArguments('This is the template', 'And another string'),
396
+ ).toEqual(['This is the template', 'And another string']);
397
+ });
398
+
399
+ it('works with strings templates', () => {
400
+ expect(formatConsoleArguments('This is %s template', 'the')).toEqual([
401
+ 'This is the template',
402
+ ]);
403
+ });
404
+
405
+ it('skips %%s', () => {
406
+ expect(formatConsoleArguments('This %%s is %s template', 'the')).toEqual([
407
+ 'This %%s is the template',
408
+ ]);
409
+ });
410
+
411
+ it('works with %%%s', () => {
412
+ expect(
413
+ formatConsoleArguments('This %%%s is %s template', 'test', 'the'),
414
+ ).toEqual(['This %%test is the template']);
415
+ });
416
+
417
+ it("doesn't inline objects", () => {
418
+ expect(
419
+ formatConsoleArguments('This is %s template with object %o', 'the', {}),
420
+ ).toEqual(['This is the template with object %o', {}]);
421
+ });
422
+
423
+ it("doesn't inline css", () => {
424
+ expect(
425
+ formatConsoleArguments(
426
+ 'This is template with %c %s object %o',
427
+ 'color: rgba(...)',
428
+ 'the',
429
+ {},
430
+ ),
431
+ ).toEqual([
432
+ 'This is template with %c the object %o',
433
+ 'color: rgba(...)',
434
+ {},
435
+ ]);
436
+ });
437
+ });
438
});