chore: disable string escaping in snapshots (#7131)

This commit is contained in:
Joshua Chen 2022-04-08 11:23:19 +08:00 committed by GitHub
parent 4134ebb3fb
commit 9145ae88cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 1881 additions and 1884 deletions

View file

@ -3,16 +3,16 @@
exports[`error prints objects 1`] = `
[
[
"[ERROR] {\\"a\\":1}",
"[ERROR] {"a":1}",
],
[
"[ERROR] undefined",
"[ERROR] undefined",
],
[
"[ERROR] 1,2,3",
"[ERROR] 1,2,3",
],
[
"[ERROR] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
"[ERROR] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
],
]
`;
@ -20,16 +20,16 @@ exports[`error prints objects 1`] = `
exports[`info prints objects 1`] = `
[
[
"[INFO] {\\"a\\":1}",
"[INFO] {"a":1}",
],
[
"[INFO] undefined",
"[INFO] undefined",
],
[
"[INFO] 1,2,3",
"[INFO] 1,2,3",
],
[
"[INFO] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
"[INFO] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
],
]
`;
@ -37,16 +37,16 @@ exports[`info prints objects 1`] = `
exports[`success prints objects 1`] = `
[
[
"[SUCCESS] {\\"a\\":1}",
"[SUCCESS] {"a":1}",
],
[
"[SUCCESS] undefined",
"[SUCCESS] undefined",
],
[
"[SUCCESS] 1,2,3",
"[SUCCESS] 1,2,3",
],
[
"[SUCCESS] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
"[SUCCESS] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
],
]
`;
@ -54,16 +54,16 @@ exports[`success prints objects 1`] = `
exports[`warn prints objects 1`] = `
[
[
"[WARNING] {\\"a\\":1}",
"[WARNING] {"a":1}",
],
[
"[WARNING] undefined",
"[WARNING] undefined",
],
[
"[WARNING] 1,2,3",
"[WARNING] 1,2,3",
],
[
"[WARNING] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
"[WARNING] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
],
]
`;

View file

@ -8,24 +8,25 @@
import {jest} from '@jest/globals';
import logger from '../index';
// cSpell:ignore mkeep
describe('formatters', () => {
it('path', () => {
// cSpell:ignore mhey
expect(logger.path('hey')).toMatchInlineSnapshot(`"\\"hey\\""`);
expect(logger.path('keepAnsi')).toMatchInlineSnapshot(`""keepAnsi""`);
});
it('url', () => {
expect(logger.url('https://docusaurus.io/')).toMatchInlineSnapshot(
`"https://docusaurus.io/"`,
expect(logger.url('https://docusaurus.io/keepAnsi')).toMatchInlineSnapshot(
`"https://docusaurus.io/keepAnsi"`,
);
});
it('id', () => {
expect(logger.name('hey')).toMatchInlineSnapshot(`"hey"`);
expect(logger.name('keepAnsi')).toMatchInlineSnapshot(`"keepAnsi"`);
});
it('code', () => {
expect(logger.code('hey')).toMatchInlineSnapshot(`"\`hey\`"`);
expect(logger.code('keepAnsi')).toMatchInlineSnapshot(`"\`keepAnsi\`"`);
});
it('subdue', () => {
expect(logger.subdue('hey')).toMatchInlineSnapshot(`"hey"`);
expect(logger.subdue('keepAnsi')).toMatchInlineSnapshot(`"keepAnsi"`);
});
});
@ -33,9 +34,10 @@ describe('interpolate', () => {
it('formats text with variables & arrays', () => {
const name = 'Josh';
const items = [1, 'hi', 'Hmmm'];
expect(logger.interpolate`Hello ${name}! Here are your goodies:${items}`)
.toMatchInlineSnapshot(`
"Hello Josh! Here are your goodies:
expect(
logger.interpolate`(keepAnsi) Hello ${name}! Here are your goodies:${items}`,
).toMatchInlineSnapshot(`
"(keepAnsi) Hello Josh! Here are your goodies:
- 1
- hi
- Hmmm"
@ -43,20 +45,20 @@ describe('interpolate', () => {
});
it('recognizes valid flags', () => {
expect(
logger.interpolate`The package at path=${'packages/docusaurus'} has number=${10} files. name=${'Babel'} is exported here subdue=${'(as a preset)'} that you can with code=${"require.resolve('@docusaurus/core/lib/babel/preset')"}`,
logger.interpolate`(keepAnsi) The package at path=${'packages/docusaurus'} has number=${10} files. name=${'Babel'} is exported here subdue=${'(as a preset)'} that you can with code=${"require.resolve('@docusaurus/core/lib/babel/preset')"}`,
).toMatchInlineSnapshot(
`"The package at \\"packages/docusaurus\\" has 10 files. Babel is exported here (as a preset) that you can with \`require.resolve('@docusaurus/core/lib/babel/preset')\`"`,
`"(keepAnsi) The package at "packages/docusaurus" has 10 files. Babel is exported here (as a preset) that you can with \`require.resolve('@docusaurus/core/lib/babel/preset')\`"`,
);
});
it('interpolates arrays with flags', () => {
expect(
logger.interpolate`The following commands are available:code=${[
logger.interpolate`(keepAnsi) The following commands are available:code=${[
'docusaurus start',
'docusaurus build',
'docusaurus deploy',
]}`,
).toMatchInlineSnapshot(`
"The following commands are available:
"(keepAnsi) The following commands are available:
- \`docusaurus start\`
- \`docusaurus build\`
- \`docusaurus deploy\`"
@ -64,15 +66,15 @@ describe('interpolate', () => {
});
it('prints detached flags as-is', () => {
expect(
logger.interpolate`You can use placeholders like code= ${'and it will'} be replaced with the succeeding arguments`,
logger.interpolate`(keepAnsi) You can use placeholders like code= ${'and it will'} be replaced with the succeeding arguments`,
).toMatchInlineSnapshot(
`"You can use placeholders like code= and it will be replaced with the succeeding arguments"`,
`"(keepAnsi) You can use placeholders like code= and it will be replaced with the succeeding arguments"`,
);
});
it('throws with bad flags', () => {
expect(
() =>
logger.interpolate`I mistyped this: cde=${'this code'} and I will be damned`,
logger.interpolate`(keepAnsi) I mistyped this: cde=${'this code'} and I will be damned`,
).toThrowErrorMatchingInlineSnapshot(
`"Bad Docusaurus logging message. This is likely an internal bug, please report it."`,
);