Skip to content

Commit

Permalink
patch(vest): hasRemainingTest with or without fieldName
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 13, 2023
1 parent 484baec commit 0626dce
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import wait from 'wait';
import { SuiteWalker } from 'SuiteWalker';
import * as vest from 'vest';

describe('SuiteWalker.hasRemainingTests', () => {
describe('SuiteWalker.hasRemainingWithTestNameMatching', () => {
let hasRemaining: boolean | null = null;
let count = 0;

Expand All @@ -15,7 +15,7 @@ describe('SuiteWalker.hasRemainingTests', () => {
describe('When no remaining tests', () => {
it('should return false', () => {
vest.create(() => {
hasRemaining = SuiteWalker.hasRemainingTests();
hasRemaining = SuiteWalker.hasRemainingWithTestNameMatching();
})();
expect(hasRemaining).toBe(false);
});
Expand All @@ -27,7 +27,7 @@ describe('SuiteWalker.hasRemainingTests', () => {
vest.test('f1', async () => {
await wait(100);
});
hasRemaining = SuiteWalker.hasRemainingTests();
hasRemaining = SuiteWalker.hasRemainingWithTestNameMatching();
})();

expect(hasRemaining).toBe(true);
Expand All @@ -40,7 +40,7 @@ describe('SuiteWalker.hasRemainingTests', () => {
await wait(100);
});
count++;
hasRemaining = SuiteWalker.hasRemainingTests();
hasRemaining = SuiteWalker.hasRemainingWithTestNameMatching();
});
suite();
suite();
Expand All @@ -58,7 +58,7 @@ describe('SuiteWalker.hasRemainingTests', () => {
await wait(100);
});
count++;
hasRemaining = SuiteWalker.hasRemainingTests();
hasRemaining = SuiteWalker.hasRemainingWithTestNameMatching();
});

suite();
Expand All @@ -73,7 +73,7 @@ describe('SuiteWalker.hasRemainingTests', () => {
describe('When no remaining tests', () => {
it('Should return false', () => {
vest.create(() => {
hasRemaining = SuiteWalker.hasRemainingTests('f1');
hasRemaining = SuiteWalker.hasRemainingWithTestNameMatching('f1');
})();
expect(hasRemaining).toBe(false);
});
Expand All @@ -85,7 +85,7 @@ describe('SuiteWalker.hasRemainingTests', () => {
vest.test('f1', async () => {
await wait(100);
});
hasRemaining = SuiteWalker.hasRemainingTests('f1');
hasRemaining = SuiteWalker.hasRemainingWithTestNameMatching('f1');
})();
expect(hasRemaining).toBe(true);
});
Expand All @@ -97,7 +97,7 @@ describe('SuiteWalker.hasRemainingTests', () => {
await wait(100);
});
count++;
hasRemaining = SuiteWalker.hasRemainingTests('f1');
hasRemaining = SuiteWalker.hasRemainingWithTestNameMatching('f1');
});
suite();
suite();
Expand All @@ -116,8 +116,8 @@ describe('SuiteWalker.hasRemainingTests', () => {
});
count++;
hasRemaining =
SuiteWalker.hasRemainingTests('f1') &&
SuiteWalker.hasRemainingTests('f2');
SuiteWalker.hasRemainingWithTestNameMatching('f1') &&
SuiteWalker.hasRemainingWithTestNameMatching('f2');
});

suite();
Expand Down
32 changes: 21 additions & 11 deletions packages/vest/src/suite/SuiteWalker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Predicates, type Predicate } from 'vest-utils';
import { Predicates, type Predicate, isNullish } from 'vest-utils';
import { TIsolate, VestRuntime, Walker } from 'vestjs-runtime';

import { CommonStates } from 'CommonStateMachine';
Expand All @@ -17,19 +17,29 @@ export class SuiteWalker {
return false;
}

return Walker.some(root, (isolate: TIsolate) => {
return (
(isolate.status === CommonStates.PENDING && predicate?.(isolate)) ??
true
);
});
return Walker.some(
root,
Predicates.all(isPendingStatus, predicate ?? true)
);
}

static hasRemainingTests(fieldName?: TFieldName): boolean {
// Checks whether there are pending isolates in the tree.
// If a fieldname is provided, will only check tests with a matching fieldname.
static hasRemainingWithTestNameMatching(fieldName?: TFieldName): boolean {
return SuiteWalker.hasPending(
Predicates.all(VestTest.is, (testObject: TIsolateTest) => {
return matchesOrHasNoFieldName(VestTest.getData(testObject), fieldName);
})
Predicates.any(
isNullish(fieldName),
Predicates.all(VestTest.is, (testObject: TIsolateTest) => {
return matchesOrHasNoFieldName(
VestTest.getData(testObject),
fieldName
);
})
)
);
}
}

function isPendingStatus(isolate: TIsolate) {
return isolate.status === CommonStates.PENDING;
}
2 changes: 1 addition & 1 deletion packages/vest/src/suite/runCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useRunFieldCallbacks(fieldName?: TFieldName): void {

if (
fieldName &&
!SuiteWalker.hasRemainingTests(fieldName) &&
!SuiteWalker.hasRemainingWithTestNameMatching(fieldName) &&
isArray(fieldCallbacks[fieldName])
) {
callEach(fieldCallbacks[fieldName]);
Expand Down
4 changes: 2 additions & 2 deletions packages/vest/src/suiteResult/suiteRunResult.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { SuiteWalker } from 'SuiteWalker';
import { assign } from 'vest-utils';
import { VestRuntime } from 'vestjs-runtime';

Expand All @@ -8,6 +7,7 @@ import {
TFieldName,
TGroupName,
} from 'SuiteResultTypes';
import { SuiteWalker } from 'SuiteWalker';
import { useDeferDoneCallback } from 'deferDoneCallback';
import { shouldSkipDoneRegistration } from 'shouldSkipDoneRegistration';
import { useCreateSuiteResult } from 'suiteResult';
Expand Down Expand Up @@ -43,7 +43,7 @@ function done<F extends TFieldName, G extends TGroupName>(
return output;
}
const useDoneCallback = () => callback(useCreateSuiteResult());
if (!SuiteWalker.hasRemainingTests(fieldName)) {
if (!SuiteWalker.hasRemainingWithTestNameMatching(fieldName)) {
useDoneCallback();
return output;
}
Expand Down

2 comments on commit 0626dce

@vercel
Copy link

@vercel vercel bot commented on 0626dce Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-next.vercel.app
vest-website.vercel.app
vest-next-ealush.vercel.app
vest-next-git-latest-ealush.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 0626dce Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest – ./website

vest.vercel.app
vest-ealush.vercel.app
vest-git-latest-ealush.vercel.app
vestjs.dev
www.vestjs.dev

Please sign in to comment.