Skip to content

Commit

Permalink
strip stack traces from snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Jul 22, 2020
1 parent 851fd9e commit b57e11e
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/dev/build/lib/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<stacktrace>');
while (isStackTrace(v[start + 1])) v.splice(start + 1, 1);
return v;
}
)
);

beforeEach(() => {
testWriter.messages.length = 0;
jest.clearAllMocks();
Expand Down Expand Up @@ -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)",
" │ <stacktrace>",
"",
]
`);
Expand Down

0 comments on commit b57e11e

Please sign in to comment.