From b57e11eda28a4e1b7fe59503a5c41e9b07303ea3 Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 21 Jul 2020 18:25:15 -0700 Subject: [PATCH] strip stack traces from snapshots --- src/dev/build/lib/runner.test.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/dev/build/lib/runner.test.ts b/src/dev/build/lib/runner.test.ts index 6f3180e796a50..0e17f2f590e3d 100644 --- a/src/dev/build/lib/runner.test.ts +++ b/src/dev/build/lib/runner.test.ts @@ -17,7 +17,12 @@ * under the License. */ -import { ToolingLog, ToolingLogCollectingWriter, createStripAnsiSerializer } from '@kbn/dev-utils'; +import { + ToolingLog, + ToolingLogCollectingWriter, + createStripAnsiSerializer, + createRecursiveSerializer, +} from '@kbn/dev-utils'; import { Config } from './config'; import { createRunner } from './runner'; import { Build } from './build'; @@ -31,6 +36,21 @@ log.setWriters([testWriter]); expect.addSnapshotSerializer(createStripAnsiSerializer()); +const STACK_TRACE = /(\│\s+)at .+ \(.+\)$/; +const isStackTrace = (x: any) => typeof x === 'string' && STACK_TRACE.test(x); + +expect.addSnapshotSerializer( + createRecursiveSerializer( + (v) => Array.isArray(v) && v.some(isStackTrace), + (v) => { + const start = v.findIndex(isStackTrace); + v[start] = v[start].replace(STACK_TRACE, '$1'); + while (isStackTrace(v[start + 1])) v.splice(start + 1, 1); + return v; + } + ) +); + beforeEach(() => { testWriter.messages.length = 0; jest.clearAllMocks(); @@ -196,8 +216,7 @@ describe('task rejection', () => { " info [ kibana ] foo", " │ERROR failure 0 sec", " │ERROR Error: FOO", - " │ at Object.it (/Users/spalger/kbn-dev/master/kibana/src/dev/build/lib/runner.test.ts:183:19)", - " │ at process._tickCallback (internal/process/next_tick.js:68:7)", + " │ ", "", ] `);