test: enable a few jest eslint rules (#6900)

* test: enable a few jest eslint rules

* more
This commit is contained in:
Joshua Chen 2022-03-12 08:43:09 +08:00 committed by GitHub
parent 1efc6c6091
commit aa5a2d4c04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
155 changed files with 3644 additions and 3478 deletions

View file

@ -0,0 +1,69 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`error prints objects 1`] = `
Array [
Array [
"[ERROR] {\\"a\\":1}",
],
Array [
"[ERROR] undefined",
],
Array [
"[ERROR] 1,2,3",
],
Array [
"[ERROR] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
],
]
`;
exports[`info prints objects 1`] = `
Array [
Array [
"[INFO] {\\"a\\":1}",
],
Array [
"[INFO] undefined",
],
Array [
"[INFO] 1,2,3",
],
Array [
"[INFO] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
],
]
`;
exports[`success prints objects 1`] = `
Array [
Array [
"[SUCCESS] {\\"a\\":1}",
],
Array [
"[SUCCESS] undefined",
],
Array [
"[SUCCESS] 1,2,3",
],
Array [
"[SUCCESS] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
],
]
`;
exports[`warn prints objects 1`] = `
Array [
Array [
"[WARNING] {\\"a\\":1}",
],
Array [
"[WARNING] undefined",
],
Array [
"[WARNING] 1,2,3",
],
Array [
"[WARNING] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
],
]
`;

View file

@ -9,22 +9,22 @@ import {jest} from '@jest/globals';
import logger from '../index';
describe('formatters', () => {
test('path', () => {
it('path', () => {
expect(logger.path('hey')).toMatchInlineSnapshot(`"hey"`);
});
test('id', () => {
it('id', () => {
expect(logger.name('hey')).toMatchInlineSnapshot(`"hey"`);
});
test('code', () => {
it('code', () => {
expect(logger.code('hey')).toMatchInlineSnapshot(`"\`hey\`"`);
});
test('subdue', () => {
it('subdue', () => {
expect(logger.subdue('hey')).toMatchInlineSnapshot(`"hey"`);
});
});
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 packages/docusaurus has 10 files. Babel is exported here (as a preset) that you can with \`require.resolve('@docusaurus/core/lib/babel/preset')\`"`,
);
});
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', () => {
- \`docusaurus deploy\`"
`);
});
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 [
"[INFO] {\\"a\\":1}",
],
Array [
"[INFO] undefined",
],
Array [
"[INFO] 1,2,3",
],
Array [
"[INFO] 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 [
"[WARNING] {\\"a\\":1}",
],
Array [
"[WARNING] undefined",
],
Array [
"[WARNING] 1,2,3",
],
Array [
"[WARNING] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
],
]
`);
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 [
"[ERROR] {\\"a\\":1}",
],
Array [
"[ERROR] undefined",
],
Array [
"[ERROR] 1,2,3",
],
Array [
"[ERROR] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
],
]
`);
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 [
"[SUCCESS] {\\"a\\":1}",
],
Array [
"[SUCCESS] undefined",
],
Array [
"[SUCCESS] 1,2,3",
],
Array [
"[SUCCESS] Sat Nov 13 2021 00:00:00 GMT+0000 (Coordinated Universal Time)",
],
]
`);
expect(consoleMock.mock.calls).toMatchSnapshot();
});
});