test(logger): use jest-serializer-ansi-escapes (#7685)

* chore(logger): use jest-serializer-ansi-escapes

* move serialiser to jest.config
This commit is contained in:
Tom Mrazauskas 2022-06-27 10:03:51 +03:00 committed by GitHub
parent 7720a1cfd8
commit bb558ffcb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 11 deletions

1
jest.config.mjs vendored
View file

@ -80,6 +80,7 @@ export default {
}, },
snapshotSerializers: [ snapshotSerializers: [
'<rootDir>/jest/snapshotPathNormalizer.ts', '<rootDir>/jest/snapshotPathNormalizer.ts',
'jest-serializer-ansi-escapes',
'jest-serializer-react-helmet-async', 'jest-serializer-react-helmet-async',
], ],
snapshotFormat: { snapshotFormat: {

View file

@ -94,6 +94,7 @@
"image-size": "^1.0.1", "image-size": "^1.0.1",
"jest": "^28.1.1", "jest": "^28.1.1",
"jest-environment-jsdom": "^28.1.1", "jest-environment-jsdom": "^28.1.1",
"jest-serializer-ansi-escapes": "^2.0.1",
"jest-serializer-react-helmet-async": "^1.0.21", "jest-serializer-react-helmet-async": "^1.0.21",
"lerna": "^5.1.4", "lerna": "^5.1.4",
"lerna-changelog": "^2.2.0", "lerna-changelog": "^2.2.0",

View file

@ -8,25 +8,31 @@
import {jest} from '@jest/globals'; import {jest} from '@jest/globals';
import logger from '../index'; import logger from '../index';
// cSpell:ignore mkeep
describe('formatters', () => { describe('formatters', () => {
it('path', () => { it('path', () => {
expect(logger.path('keepAnsi')).toMatchInlineSnapshot(`""keepAnsi""`); expect(logger.path('keepAnsi')).toMatchInlineSnapshot(
`"<cyan><underline>"keepAnsi"</underline></color>"`,
);
}); });
it('url', () => { it('url', () => {
expect(logger.url('https://docusaurus.io/keepAnsi')).toMatchInlineSnapshot( expect(logger.url('https://docusaurus.io/keepAnsi')).toMatchInlineSnapshot(
`"https://docusaurus.io/keepAnsi"`, `"<cyan><underline>https://docusaurus.io/keepAnsi</underline></color>"`,
); );
}); });
it('id', () => { it('id', () => {
expect(logger.name('keepAnsi')).toMatchInlineSnapshot(`"keepAnsi"`); expect(logger.name('keepAnsi')).toMatchInlineSnapshot(
`"<blue><bold>keepAnsi</intensity></color>"`,
);
}); });
it('code', () => { it('code', () => {
expect(logger.code('keepAnsi')).toMatchInlineSnapshot(`"\`keepAnsi\`"`); expect(logger.code('keepAnsi')).toMatchInlineSnapshot(
`"<cyan>\`keepAnsi\`</color>"`,
);
}); });
it('subdue', () => { it('subdue', () => {
expect(logger.subdue('keepAnsi')).toMatchInlineSnapshot(`"keepAnsi"`); expect(logger.subdue('keepAnsi')).toMatchInlineSnapshot(
`"<gray>keepAnsi</color>"`,
);
}); });
}); });
@ -47,7 +53,7 @@ describe('interpolate', () => {
expect( expect(
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')"}`, 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( ).toMatchInlineSnapshot(
`"(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')\`"`, `"(keepAnsi) The package at <cyan><underline>"packages/docusaurus"</underline></color> has <yellow>10</color> files. <blue><bold>Babel</intensity></color> is exported here <gray>(as a preset)</color> that you can with <cyan>\`require.resolve('@docusaurus/core/lib/babel/preset')\`</color>"`,
); );
}); });
it('interpolates arrays with flags', () => { it('interpolates arrays with flags', () => {
@ -59,9 +65,9 @@ describe('interpolate', () => {
]}`, ]}`,
).toMatchInlineSnapshot(` ).toMatchInlineSnapshot(`
"(keepAnsi) The following commands are available: "(keepAnsi) The following commands are available:
- \`docusaurus start\` - <cyan>\`docusaurus start\`</color>
- \`docusaurus build\` - <cyan>\`docusaurus build\`</color>
- \`docusaurus deploy\`" - <cyan>\`docusaurus deploy\`</color>"
`); `);
}); });
it('prints detached flags as-is', () => { it('prints detached flags as-is', () => {

View file

@ -9470,6 +9470,11 @@ jest-runtime@^28.1.1:
slash "^3.0.0" slash "^3.0.0"
strip-bom "^4.0.0" strip-bom "^4.0.0"
jest-serializer-ansi-escapes@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/jest-serializer-ansi-escapes/-/jest-serializer-ansi-escapes-2.0.1.tgz#053fc7f2d8629ad127afb6a31e542b65c6ad7806"
integrity sha512-+BuVKZQutcejSuODTleG/CV+8OVONZSOSrtrQRG8isTLu367JVKK+/yaG2jGs5O6MPBZ88WNy5jg8hqhd/p6pw==
jest-serializer-react-helmet-async@^1.0.21: jest-serializer-react-helmet-async@^1.0.21:
version "1.0.21" version "1.0.21"
resolved "https://registry.yarnpkg.com/jest-serializer-react-helmet-async/-/jest-serializer-react-helmet-async-1.0.21.tgz#bf2aee7522909bc4c933a0911db236b92db4685c" resolved "https://registry.yarnpkg.com/jest-serializer-react-helmet-async/-/jest-serializer-react-helmet-async-1.0.21.tgz#bf2aee7522909bc4c933a0911db236b92db4685c"