Skip to content

Commit

Permalink
fix(vest): skipped tests should not override failed tests in each
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Feb 29, 2024
1 parent 57f032d commit 1ebd50a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ function handleCollision(
prevNode?: TIsolate,
): TIsolateTest {
if (IsolateInspector.usesKey(newNode)) {
return VestTest.cast(Reconciler.handleIsolateNodeWithKey(newNode));
return VestTest.cast(
Reconciler.handleIsolateNodeWithKey(newNode, VestTest.isNonActionable),
);
}

if (
Expand Down
31 changes: 31 additions & 0 deletions packages/vest/src/isolates/__tests__/each.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,35 @@ describe('each', () => {
});
});
});

it('Should retain failed/passing tests even after skipping', () => {
let run = 0;
const suite = vest.create((data: number[], only: number) => {
vest.only(`item.${only}`);

vest.each(data, item => {
vest.test(
`item.${item}`,
() => {
vest.enforce(item).isOdd();
},
item.toString(),
);
});
run++;
});
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
data.forEach((_, idx) => suite(data, idx + 1));
expect(suite.get().errors).toHaveLength(5);
expect(suite.hasErrors('item.1')).toBe(false);
expect(suite.hasErrors('item.2')).toBe(true);
expect(suite.hasErrors('item.3')).toBe(false);
expect(suite.hasErrors('item.4')).toBe(true);
expect(suite.hasErrors('item.5')).toBe(false);
expect(suite.hasErrors('item.6')).toBe(true);
expect(suite.hasErrors('item.7')).toBe(false);
expect(suite.hasErrors('item.8')).toBe(true);
expect(suite.hasErrors('item.9')).toBe(false);
expect(suite.hasErrors('item.10')).toBe(true);
});
});
31 changes: 22 additions & 9 deletions packages/vestjs-runtime/src/Reconciler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { ErrorStrings } from 'ErrorStrings';
import { Maybe, Nullable, invariant, isNullish } from 'vest-utils';
import {
Maybe,
Nullable,
invariant,
isNullish,
optionalFunctionValue,
} from 'vest-utils';

import { type TIsolate } from 'Isolate';
import { IsolateInspector } from 'IsolateInspector';
Expand All @@ -17,7 +23,7 @@ export interface IRecociler<I = any> {

function BaseReconciler(
currentNode: TIsolate,
historyNode: TIsolate
historyNode: TIsolate,
): TIsolate {
if (isNullish(historyNode)) {
return currentNode;
Expand Down Expand Up @@ -49,7 +55,7 @@ export class Reconciler {
static dropNextNodesOnReorder<I extends TIsolate>(
reorderLogic: (newNode: I, prevNode: Maybe<TIsolate>) => boolean,
newNode: I,
prevNode: Maybe<TIsolate>
prevNode: Maybe<TIsolate>,
): boolean {
const didReorder = reorderLogic(newNode, prevNode);

Expand All @@ -60,26 +66,33 @@ export class Reconciler {
return didReorder;
}

static handleIsolateNodeWithKey(node: TIsolate): TIsolate {
static handleIsolateNodeWithKey<I extends TIsolate>(
node: TIsolate,

// The revoke function allows the caller to revoke the previous node
revoke: ((node: I) => boolean) | false,
): TIsolate {
invariant(IsolateInspector.usesKey(node));

const prevNodeByKey = VestRuntime.useHistoryKey(node.key);

let nextNode = node;

if (!isNullish(prevNodeByKey)) {
if (
!isNullish(prevNodeByKey) &&
!optionalFunctionValue(revoke, prevNodeByKey)
) {
nextNode = prevNodeByKey;
}

VestRuntime.useSetIsolateKey(node.key, node);
VestRuntime.useSetIsolateKey(node.key, nextNode);

return nextNode;
}
}

function pickNextNode(
currentNode: TIsolate,
historyNode: Nullable<TIsolate>
historyNode: Nullable<TIsolate>,
): TIsolate {
if (isNullish(historyNode)) {
return handleNoHistoryNode(currentNode);
Expand All @@ -99,7 +112,7 @@ function pickNextNode(

function handleNoHistoryNode<I extends TIsolate>(newNode: I): I {
if (IsolateInspector.usesKey(newNode)) {
return Reconciler.handleIsolateNodeWithKey(newNode) as I;
return Reconciler.handleIsolateNodeWithKey(newNode, false) as I;
}

return newNode;
Expand Down

0 comments on commit 1ebd50a

Please sign in to comment.