Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default {
},
snapshotSerializers: [
'<rootDir>/jest/snapshotPathNormalizer.ts',
'jest-serializer-ansi-escapes',
'jest-serializer-react-helmet-async',
],
snapshotFormat: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"image-size": "^1.0.1",
"jest": "^28.1.1",
"jest-environment-jsdom": "^28.1.1",
"jest-serializer-ansi-escapes": "^2.0.1",
"jest-serializer-react-helmet-async": "^1.0.21",
"lerna": "^5.1.4",
"lerna-changelog": "^2.2.0",
Expand Down
28 changes: 17 additions & 11 deletions packages/docusaurus-logger/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@
import {jest} from '@jest/globals';
import logger from '../index';

// cSpell:ignore mkeep
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, snapshots become cSpell friendly as well.


describe('formatters', () => {
it('path', () => {
expect(logger.path('keepAnsi')).toMatchInlineSnapshot(`""keepAnsi""`);
expect(logger.path('keepAnsi')).toMatchInlineSnapshot(
`"<cyan><underline>"keepAnsi"</underline></color>"`,
);
});
it('url', () => {
expect(logger.url('https://docusaurus.io/keepAnsi')).toMatchInlineSnapshot(
`"https://docusaurus.io/keepAnsi"`,
`"<cyan><underline>https://docusaurus.io/keepAnsi</underline></color>"`,
);
});
it('id', () => {
expect(logger.name('keepAnsi')).toMatchInlineSnapshot(`"keepAnsi"`);
expect(logger.name('keepAnsi')).toMatchInlineSnapshot(
`"<blue><bold>keepAnsi</intensity></color>"`,
);
});
it('code', () => {
expect(logger.code('keepAnsi')).toMatchInlineSnapshot(`"\`keepAnsi\`"`);
expect(logger.code('keepAnsi')).toMatchInlineSnapshot(
`"<cyan>\`keepAnsi\`</color>"`,
);
});
it('subdue', () => {
expect(logger.subdue('keepAnsi')).toMatchInlineSnapshot(`"keepAnsi"`);
expect(logger.subdue('keepAnsi')).toMatchInlineSnapshot(
`"<gray>keepAnsi</color>"`,
);
});
});

Expand All @@ -47,7 +53,7 @@ describe('interpolate', () => {
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')"}`,
).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', () => {
Expand All @@ -59,9 +65,9 @@ describe('interpolate', () => {
]}`,
).toMatchInlineSnapshot(`
"(keepAnsi) The following commands are available:
- \`docusaurus start\`
- \`docusaurus build\`
- \`docusaurus deploy\`"
- <cyan>\`docusaurus start\`</color>
- <cyan>\`docusaurus build\`</color>
- <cyan>\`docusaurus deploy\`</color>"
`);
});
it('prints detached flags as-is', () => {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9470,6 +9470,11 @@ jest-runtime@^28.1.1:
slash "^3.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:
version "1.0.21"
resolved "https://registry.yarnpkg.com/jest-serializer-react-helmet-async/-/jest-serializer-react-helmet-async-1.0.21.tgz#bf2aee7522909bc4c933a0911db236b92db4685c"
Expand Down