mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-06 04:42:40 +02:00
test: enable a few jest eslint rules (#6900)
* test: enable a few jest eslint rules * more
This commit is contained in:
parent
1efc6c6091
commit
aa5a2d4c04
155 changed files with 3644 additions and 3478 deletions
|
@ -0,0 +1,69 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`error prints objects 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"[31m[1m[ERROR][22m {\\"a\\":1}[39m",
|
||||
],
|
||||
Array [
|
||||
"[31m[1m[ERROR][22m undefined[39m",
|
||||
],
|
||||
Array [
|
||||
"[31m[1m[ERROR][22m 1,2,3[39m",
|
||||
],
|
||||
Array [
|
||||
"[31m[1m[ERROR][22m Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)[39m",
|
||||
],
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`info prints objects 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"[36m[1m[INFO][22m[39m {\\"a\\":1}",
|
||||
],
|
||||
Array [
|
||||
"[36m[1m[INFO][22m[39m undefined",
|
||||
],
|
||||
Array [
|
||||
"[36m[1m[INFO][22m[39m 1,2,3",
|
||||
],
|
||||
Array [
|
||||
"[36m[1m[INFO][22m[39m Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
|
||||
],
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`success prints objects 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"[32m[1m[SUCCESS][22m[39m {\\"a\\":1}",
|
||||
],
|
||||
Array [
|
||||
"[32m[1m[SUCCESS][22m[39m undefined",
|
||||
],
|
||||
Array [
|
||||
"[32m[1m[SUCCESS][22m[39m 1,2,3",
|
||||
],
|
||||
Array [
|
||||
"[32m[1m[SUCCESS][22m[39m Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
|
||||
],
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`warn prints objects 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"[33m[1m[WARNING][22m {\\"a\\":1}[39m",
|
||||
],
|
||||
Array [
|
||||
"[33m[1m[WARNING][22m undefined[39m",
|
||||
],
|
||||
Array [
|
||||
"[33m[1m[WARNING][22m 1,2,3[39m",
|
||||
],
|
||||
Array [
|
||||
"[33m[1m[WARNING][22m Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)[39m",
|
||||
],
|
||||
]
|
||||
`;
|
|
@ -9,22 +9,22 @@ import {jest} from '@jest/globals';
|
|||
import logger from '../index';
|
||||
|
||||
describe('formatters', () => {
|
||||
test('path', () => {
|
||||
it('path', () => {
|
||||
expect(logger.path('hey')).toMatchInlineSnapshot(`"[36m[4mhey[24m[39m"`);
|
||||
});
|
||||
test('id', () => {
|
||||
it('id', () => {
|
||||
expect(logger.name('hey')).toMatchInlineSnapshot(`"[34m[1mhey[22m[39m"`);
|
||||
});
|
||||
test('code', () => {
|
||||
it('code', () => {
|
||||
expect(logger.code('hey')).toMatchInlineSnapshot(`"[36m\`hey\`[39m"`);
|
||||
});
|
||||
test('subdue', () => {
|
||||
it('subdue', () => {
|
||||
expect(logger.subdue('hey')).toMatchInlineSnapshot(`"[90mhey[39m"`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('interpolate', () => {
|
||||
test('should format text with variables & arrays', () => {
|
||||
it('formats text with variables & arrays', () => {
|
||||
const name = 'Josh';
|
||||
const items = [1, 'hi', 'Hmmm'];
|
||||
expect(logger.interpolate`Hello ${name}! Here are your goodies:${items}`)
|
||||
|
@ -35,14 +35,14 @@ describe('interpolate', () => {
|
|||
- Hmmm"
|
||||
`);
|
||||
});
|
||||
test('should recognize valid flags', () => {
|
||||
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')"}`,
|
||||
).toMatchInlineSnapshot(
|
||||
`"The package at [36m[4mpackages/docusaurus[24m[39m has [33m10[39m files. [34m[1mBabel[22m[39m is exported here [90m(as a preset)[39m that you can with [36m\`require.resolve('@docusaurus/core/lib/babel/preset')\`[39m"`,
|
||||
);
|
||||
});
|
||||
test('should interpolate arrays with flags', () => {
|
||||
it('interpolates arrays with flags', () => {
|
||||
expect(
|
||||
logger.interpolate`The following commands are available:code=${[
|
||||
'docusaurus start',
|
||||
|
@ -56,14 +56,14 @@ describe('interpolate', () => {
|
|||
- [36m\`docusaurus deploy\`[39m"
|
||||
`);
|
||||
});
|
||||
test('should print detached flags as-is', () => {
|
||||
it('prints detached flags as-is', () => {
|
||||
expect(
|
||||
logger.interpolate`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"`,
|
||||
);
|
||||
});
|
||||
test('should throw with bad flags', () => {
|
||||
it('throws with bad flags', () => {
|
||||
expect(
|
||||
() =>
|
||||
logger.interpolate`I mistyped this: cde=${'this code'} and I will be damned`,
|
||||
|
@ -75,104 +75,44 @@ describe('interpolate', () => {
|
|||
|
||||
describe('info', () => {
|
||||
const consoleMock = jest.spyOn(console, 'info').mockImplementation(() => {});
|
||||
test('should print objects', () => {
|
||||
it('prints objects', () => {
|
||||
logger.info({a: 1});
|
||||
logger.info(undefined);
|
||||
logger.info([1, 2, 3]);
|
||||
logger.info(new Date(2021, 10, 13));
|
||||
expect(consoleMock.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
"[36m[1m[INFO][22m[39m {\\"a\\":1}",
|
||||
],
|
||||
Array [
|
||||
"[36m[1m[INFO][22m[39m undefined",
|
||||
],
|
||||
Array [
|
||||
"[36m[1m[INFO][22m[39m 1,2,3",
|
||||
],
|
||||
Array [
|
||||
"[36m[1m[INFO][22m[39m Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
|
||||
],
|
||||
]
|
||||
`);
|
||||
expect(consoleMock.mock.calls).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('warn', () => {
|
||||
const consoleMock = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
test('should print objects', () => {
|
||||
it('prints objects', () => {
|
||||
logger.warn({a: 1});
|
||||
logger.warn(undefined);
|
||||
logger.warn([1, 2, 3]);
|
||||
logger.warn(new Date(2021, 10, 13));
|
||||
expect(consoleMock.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
"[33m[1m[WARNING][22m {\\"a\\":1}[39m",
|
||||
],
|
||||
Array [
|
||||
"[33m[1m[WARNING][22m undefined[39m",
|
||||
],
|
||||
Array [
|
||||
"[33m[1m[WARNING][22m 1,2,3[39m",
|
||||
],
|
||||
Array [
|
||||
"[33m[1m[WARNING][22m Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)[39m",
|
||||
],
|
||||
]
|
||||
`);
|
||||
expect(consoleMock.mock.calls).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('error', () => {
|
||||
const consoleMock = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
test('should print objects', () => {
|
||||
it('prints objects', () => {
|
||||
logger.error({a: 1});
|
||||
logger.error(undefined);
|
||||
logger.error([1, 2, 3]);
|
||||
logger.error(new Date(2021, 10, 13));
|
||||
expect(consoleMock.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
"[31m[1m[ERROR][22m {\\"a\\":1}[39m",
|
||||
],
|
||||
Array [
|
||||
"[31m[1m[ERROR][22m undefined[39m",
|
||||
],
|
||||
Array [
|
||||
"[31m[1m[ERROR][22m 1,2,3[39m",
|
||||
],
|
||||
Array [
|
||||
"[31m[1m[ERROR][22m Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)[39m",
|
||||
],
|
||||
]
|
||||
`);
|
||||
expect(consoleMock.mock.calls).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('success', () => {
|
||||
const consoleMock = jest.spyOn(console, 'log').mockImplementation(() => {});
|
||||
test('should print objects', () => {
|
||||
it('prints objects', () => {
|
||||
logger.success({a: 1});
|
||||
logger.success(undefined);
|
||||
logger.success([1, 2, 3]);
|
||||
logger.success(new Date(2021, 10, 13));
|
||||
expect(consoleMock.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
"[32m[1m[SUCCESS][22m[39m {\\"a\\":1}",
|
||||
],
|
||||
Array [
|
||||
"[32m[1m[SUCCESS][22m[39m undefined",
|
||||
],
|
||||
Array [
|
||||
"[32m[1m[SUCCESS][22m[39m 1,2,3",
|
||||
],
|
||||
Array [
|
||||
"[32m[1m[SUCCESS][22m[39m Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
|
||||
],
|
||||
]
|
||||
`);
|
||||
expect(consoleMock.mock.calls).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue