Skip to content

Commit

Permalink
use comparison instead of inline snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Feb 7, 2020
1 parent 36ec899 commit fcd7a03
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions src/core/server/logging/layouts/pattern_layout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ test('`format()` correctly formats record with meta data.', () => {
to: 'v8',
},
})
).toMatchInlineSnapshot(
`"[2012-02-01T00:00:00.000Z][DEBUG][context-meta][{\\"from\\":\\"v7\\",\\"to\\":\\"v8\\"}] message-meta"`
);
).toBe('[2012-02-01T00:00:00.000Z][DEBUG][context-meta][{"from":"v7","to":"v8"}] message-meta');

expect(
layout.format({
Expand All @@ -146,7 +144,7 @@ test('`format()` correctly formats record with meta data.', () => {
pid: 5355,
meta: {},
})
).toMatchInlineSnapshot(`"[2012-02-01T00:00:00.000Z][DEBUG][context-meta][{}] message-meta"`);
).toBe('[2012-02-01T00:00:00.000Z][DEBUG][context-meta][{}] message-meta');

expect(
layout.format({
Expand All @@ -156,7 +154,7 @@ test('`format()` correctly formats record with meta data.', () => {
timestamp: new Date(Date.UTC(2012, 1, 1)),
pid: 5355,
})
).toMatchInlineSnapshot(`"[2012-02-01T00:00:00.000Z][DEBUG][context-meta] message-meta"`);
).toBe('[2012-02-01T00:00:00.000Z][DEBUG][context-meta] message-meta');
});

test('`format()` correctly formats record with highlighting.', () => {
Expand Down Expand Up @@ -188,9 +186,7 @@ test('`format()` allows specifying pattern with meta.', () => {
to: 'v8',
},
};
expect(layout.format(record)).toMatchInlineSnapshot(
`"context-[{\\"from\\":\\"v7\\",\\"to\\":\\"v8\\"}]-message"`
);
expect(layout.format(record)).toBe('context-[{"from":"v7","to":"v8"}]-message');
});

describe('format', () => {
Expand All @@ -213,85 +209,77 @@ describe('format', () => {
it('ISO8601', () => {
const layout = new PatternLayout('[{timestamp{ISO8601}}][{context}]');

expect(layout.format(record)).toMatchInlineSnapshot(
`"[2012-02-01T00:00:00.000Z][context]"`
);
expect(layout.format(record)).toBe('[2012-02-01T00:00:00.000Z][context]');
});

it('ISO8601_TZ', () => {
const layout = new PatternLayout(
'[{timestamp{ISO8601_TZ}{America/Los_Angeles}}][{context}]'
);

expect(layout.format(record)).toMatchInlineSnapshot(
`"[2012-01-31T16:00:00,000-0800][context]"`
);
expect(layout.format(record)).toBe('[2012-01-31T16:00:00,000-0800][context]');
});

it('ABSOLUTE', () => {
const layout = new PatternLayout('[{timestamp{ABSOLUTE}}][{context}]');

expect(layout.format(record)).toMatchInlineSnapshot(`"[01:00:00,000][context]"`);
expect(layout.format(record)).toBe('[01:00:00,000][context]');
});

it('UNIX', () => {
const layout = new PatternLayout('[{timestamp{UNIX}}][{context}]');

expect(layout.format(record)).toMatchInlineSnapshot(`"[1328054400][context]"`);
expect(layout.format(record)).toBe('[1328054400][context]');
});

it('UNIX_MILLIS', () => {
const layout = new PatternLayout('[{timestamp{UNIX_MILLIS}}][{context}]');

expect(layout.format(record)).toMatchInlineSnapshot(`"[1328054400000][context]"`);
expect(layout.format(record)).toBe('[1328054400000][context]');
});
});

describe('supports specifying a predefined format and timezone', () => {
it('ISO8601', () => {
const layout = new PatternLayout('[{timestamp{ISO8601}{America/Los_Angeles}}][{context}]');

expect(layout.format(record)).toMatchInlineSnapshot(
`"[2012-02-01T00:00:00.000Z][context]"`
);
expect(layout.format(record)).toBe('[2012-02-01T00:00:00.000Z][context]');
});

it('ISO8601_TZ', () => {
const layout = new PatternLayout(
'[{timestamp{ISO8601_TZ}{America/Los_Angeles}}][{context}]'
);

expect(layout.format(record)).toMatchInlineSnapshot(
`"[2012-01-31T16:00:00,000-0800][context]"`
);
expect(layout.format(record)).toBe('[2012-01-31T16:00:00,000-0800][context]');
});

it('ABSOLUTE', () => {
const layout = new PatternLayout('[{timestamp{ABSOLUTE}{America/Los_Angeles}}][{context}]');

expect(layout.format(record)).toMatchInlineSnapshot(`"[16:00:00,000][context]"`);
expect(layout.format(record)).toBe('[16:00:00,000][context]');
});

it('UNIX', () => {
const layout = new PatternLayout('[{timestamp{UNIX}{America/Los_Angeles}}][{context}]');

expect(layout.format(record)).toMatchInlineSnapshot(`"[1328054400][context]"`);
expect(layout.format(record)).toBe('[1328054400][context]');
});

it('UNIX_MILLIS', () => {
const layout = new PatternLayout(
'[{timestamp{UNIX_MILLIS}{America/Los_Angeles}}][{context}]'
);

expect(layout.format(record)).toMatchInlineSnapshot(`"[1328054400000][context]"`);
expect(layout.format(record)).toBe('[1328054400000][context]');
});
});
it('formats several conversions patterns correctly', () => {
const layout = new PatternLayout(
'[{timestamp{ABSOLUTE}{America/Los_Angeles}}][{context}][{timestamp{UNIX}}]'
);

expect(layout.format(record)).toMatchInlineSnapshot(`"[16:00:00,000][context][1328054400]"`);
expect(layout.format(record)).toBe('[16:00:00,000][context][1328054400]');
});
});
});
Expand Down

0 comments on commit fcd7a03

Please sign in to comment.