Skip to content
Snippets Groups Projects
Select Git revision
  • 7eef0d3ed0acd1c67224c55b87395df06bde9753
  • main default protected
  • next
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • renovate/main-redis-5.x
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • 41.34.1
  • 41.34.0
  • 41.33.0
  • 41.32.3
  • 41.32.2
  • 41.32.1
  • 41.32.0
  • 41.31.1
  • 41.31.0
  • 41.30.5
  • 41.30.4
  • 41.30.3
  • 41.30.2
  • 41.30.1
  • 41.30.0
  • 41.29.1
  • 41.29.0
  • 41.28.2
  • 41.28.1
  • 41.28.0
41 results

comment.ts

Blame
  • pretty-stdout.spec.ts 2.43 KiB
    import chalk from 'chalk';
    import * as prettyStdout from './pretty-stdout';
    import { BunyanRecord } from './utils';
    
    jest.mock('chalk', () =>
      ['bgRed', 'blue', 'gray', 'green', 'magenta', 'red'].reduce(
        (r, c) => Object.defineProperty(r, c, { value: (s: string) => s }),
        {}
      )
    );
    
    describe('logger/pretty-stdout', () => {
      describe('getMeta(rec)', () => {
        it('returns empty string if null rec', () => {
          expect(prettyStdout.getMeta(null as any)).toEqual('');
        });
        it('returns empty string if empty rec', () => {
          expect(prettyStdout.getMeta({} as any)).toEqual('');
        });
        it('returns empty string if no meta fields', () => {
          const rec = {
            foo: 'bar',
          };
          expect(prettyStdout.getMeta(rec as any)).toEqual('');
        });
        it('supports single meta', () => {
          const rec = {
            foo: 'bar',
            repository: 'a/b',
          };
          expect(prettyStdout.getMeta(rec as any)).toEqual(
            chalk.gray(' (repository=a/b)')
          );
        });
        it('supports multi meta', () => {
          const rec = {
            foo: 'bar',
            branch: 'c',
            repository: 'a/b',
            module: 'test',
          };
          expect(prettyStdout.getMeta(rec as any)).toEqual(
            chalk.gray(' (repository=a/b, branch=c) [test]')
          );
        });
      });
      describe('getDetails(rec)', () => {
        it('returns empty string if null rec', () => {
          expect(prettyStdout.getDetails(null as any)).toEqual('');
        });
        it('returns empty string if empty rec', () => {
          expect(prettyStdout.getDetails({} as any)).toEqual('');
        });
        it('returns empty string if all are meta fields', () => {
          const rec = {
            branch: 'bar',
            v: 0,
          };
          expect(prettyStdout.getDetails(rec as any)).toEqual('');
        });
        it('supports a config', () => {
          const rec = {
            v: 0,
            config: {
              a: 'b',
              d: ['e', 'f'],
            },
          };
          expect(prettyStdout.getDetails(rec as any)).toMatchSnapshot();
        });
      });
      describe('formatRecord(rec)', () => {
        beforeEach(() => {
          process.env.FORCE_COLOR = '1';
        });
        afterEach(() => {
          delete process.env.FORCE_COLOR;
        });
        it('formats record', () => {
          const rec: BunyanRecord = {
            level: 10,
            msg: 'test message',
            v: 0,
            config: {
              a: 'b',
              d: ['e', 'f'],
            },
          };
          expect(prettyStdout.formatRecord(rec)).toMatchSnapshot();
        });
      });
    });