Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.

Commit

Permalink
fix: we at least detect the failure, but lose the route
Browse files Browse the repository at this point in the history
  • Loading branch information
FauxFaux committed Mar 20, 2020
1 parent 27c81db commit 36c7e5b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/translator/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function renderDiag(context: Context, failure: Result) {
return `\n ${diag.type}: ${failure.name}\n${stackAndMaybeCode}`;
}

return inspect({...failure.diag}, {depth: 3, colors: true}).replace(
return inspect(failure, {depth: 3, colors: true}).replace(
/^/gm,
' ',
);
Expand Down
15 changes: 7 additions & 8 deletions lib/tree/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ export interface AssertNode {
export type TreeNode = ChildNode | AssertNode;

export class BuildTree {
readonly ours: TreeNode[] = [];
private readonly ours: TreeNode[] = [];
private currentChild?: BuildTree;
private readonly comments: string[] = [];

constructor(parser: TapParser) {
parser.on('comment', (comment) => this.comments.push(comment));
parser.on('child', (child) => {
if (undefined !== this.currentChild) {
throw new Error(
Expand All @@ -33,7 +35,7 @@ export class BuildTree {
this.ours.push({
kind: 'child',
result,
children: [...this.currentChild.ours],
children: [...this.currentChild.finished()],
});
this.currentChild = undefined;
} else {
Expand All @@ -45,13 +47,10 @@ export class BuildTree {
});
}

collapse(path: string[], results: TreeNode[]): void {
if (this.ours) {
results.push(...this.ours);
}

finished(): TreeNode[] {
if (this.currentChild) {
this.currentChild.collapse([...path, 'unknown'], results);
this.ours.push(...this.currentChild.finished());
}
return this.ours;
}
}
12 changes: 3 additions & 9 deletions lib/tree/flatten.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import type {SerializableError, TestResult} from '@jest/test-result';
import type { SerializableError, TestResult } from '@jest/test-result';
import type { Result } from 'tap-parser';
import type { BuildTree, ChildNode, TreeNode } from './builder';
import type { BuildTree, ChildNode } from './builder';
import { pushExceptionFailure, pushTestResults } from '../translator/render';
import { Context } from '../context';

export function flatten(context: Context, result: TestResult, builder: BuildTree): void {
const events = builder.ours;
const events = builder.finished();
const first = events[0];
if (first?.kind === 'child') {
handle(context, result, first, []);
}
if (events.length > 1) {
pushExceptionFailure(context, result, new Error('invalid root array length') as SerializableError, 'events.length');
}

const path: string[] = [];
const results: TreeNode[] = [];
builder.ours.length = 0;
builder.collapse(path, results);
console.log(path, results);
}

function handle(context: Context, result: TestResult, node: ChildNode, path: string[]): void {
Expand Down
3 changes: 2 additions & 1 deletion lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ declare module 'tap-parser' {
interface TapParser extends NodeJS.WritableStream {}

class TapParser {
on(event: 'child', handler: (child: TapParser) => void): this;
on(event: 'assert', handler: (result: Result) => void): this;
on(event: 'child', handler: (child: TapParser) => void): this;
on(event: 'comment', handler: (comment: string) => void): this;
}

namespace TapParser {
Expand Down
14 changes: 14 additions & 0 deletions test/__snapshots__/terminations.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`translation of terminations handles a test which timed out 1`] = `
"
✕ bravo
Result {
ok: <yellow>false</>,
id: <yellow>2</>,
name: <green>'timeout!'</>,
diag: { signal: <green>'SIGTERM'</>, expired: <green>'TAP'</>, test: <green>'bravo'</> },
fullname: <green>'timeout.js bravo'</>
}
"
`;
4 changes: 2 additions & 2 deletions test/terminations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { testTranslation } from './translate.spec';
describe('translation of terminations', () => {
it('handles a test which timed out', async () => {
const result = await testTranslation('./fixtures/timeout.tap');
expect(result.failureMessage).toBeUndefined();
expect(result.numFailingTests).toBe(0);
expect(result.numFailingTests).toBe(1);
expect(result.numPendingTests).toBe(0);
expect(result.numPassingTests).toBe(1);
expect(result.skipped).toBe(false);
expect(result.failureMessage).toMatchSnapshot();
expect(result.testResults).toStrictEqual([
expect.objectContaining({
title: 'alpha',
Expand Down

0 comments on commit 36c7e5b

Please sign in to comment.