Skip to content

Commit

Permalink
patch(vest): support nested omitWhen calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Feb 9, 2022
1 parent 070d0d5 commit f601e1c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 10 deletions.
63 changes: 63 additions & 0 deletions packages/vest/src/core/isolate/isolates/__tests__/omitWhen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,67 @@ describe('omitWhen', () => {
expect(cb4).toHaveBeenCalledTimes(1);
});
});

describe('nested calls', () => {
let suite;

describe('omitted in non-omitted', () => {
beforeEach(() => {
suite = vest.create(() => {
vest.omitWhen(false, () => {
vest.test('outer', () => false);

vest.omitWhen(true, () => {
vest.test('outer', () => false);
});
});
});
suite();
});
it('Should run `outer` and omit `inner`', () => {
expect(suite.get().testCount).toBe(1);
expect(suite.get().hasErrors('outer')).toBe(true);
expect(suite.get().hasErrors('inner')).toBe(false);
});
});

describe('omitted in omitted', () => {
beforeEach(() => {
suite = vest.create(() => {
vest.omitWhen(true, () => {
vest.test('outer', () => false);

vest.omitWhen(true, () => {
vest.test('outer', () => false);
});
});
});
suite();
});
it('Should omit both `outer` and `inner`', () => {
expect(suite.get().testCount).toBe(0);
expect(suite.get().hasErrors('outer')).toBe(false);
expect(suite.get().hasErrors('inner')).toBe(false);
});
});
describe('non-omitted in omitted', () => {
beforeEach(() => {
suite = vest.create(() => {
vest.omitWhen(true, () => {
vest.test('outer', () => false);

vest.omitWhen(false, () => {
vest.test('outer', () => false);
});
});
});
suite();
});
it('Should omit both', () => {
expect(suite.get().testCount).toBe(0);
expect(suite.get().hasErrors('outer')).toBe(false);
expect(suite.get().hasErrors('inner')).toBe(false);
});
});
});
});
10 changes: 6 additions & 4 deletions packages/vest/src/core/isolate/isolates/omitWhen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ export default function omitWhen(
isolate({ type: IsolateTypes.OMIT_WHEN }, () => {
ctx.run(
{
omitted: optionalFunctionValue(
conditional,
optionalFunctionValue(produceDraft)
),
omitted:
isOmitted() ||
optionalFunctionValue(
conditional,
optionalFunctionValue(produceDraft)
),
},
() => callback()
);
Expand Down
5 changes: 4 additions & 1 deletion packages/vest/src/core/isolate/isolates/skipWhen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import optionalFunctionValue from 'optionalFunctionValue';

import { IsolateTypes } from 'IsolateTypes';
import ctx from 'ctx';
import { isExcludedIndividually } from 'exclusive';
import { isolate } from 'isolate';
import { produceDraft, TDraftResult } from 'produceDraft';

Expand Down Expand Up @@ -36,3 +35,7 @@ export default function skipWhen(
);
});
}

export function isExcludedIndividually(): boolean {
return !!ctx.useX().skipped;
}
3 changes: 2 additions & 1 deletion packages/vest/src/core/test/lib/registerPrevRunTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import isPromise from 'isPromise';

import VestTest from 'VestTest';
import cancelOverriddenPendingTest from 'cancelOverriddenPendingTest';
import { isExcluded, isExcludedIndividually } from 'exclusive';
import { isExcluded } from 'exclusive';
import { isOmitted } from 'omitWhen';
import registerTest from 'registerTest';
import runAsyncTest from 'runAsyncTest';
import { isExcludedIndividually } from 'skipWhen';
import * as testCursor from 'testCursor';
import { useTestAtCursor, useSetTestAtCursor } from 'useTestAtCursor';

Expand Down
5 changes: 1 addition & 4 deletions packages/vest/src/hooks/exclusive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import optionalFunctionValue from 'optionalFunctionValue';
import VestTest from 'VestTest';
import ctx from 'ctx';
import { ERROR_HOOK_CALLED_OUTSIDE } from 'hookErrors';
import { isExcludedIndividually } from 'skipWhen';

type TExclusionItem = string | string[] | undefined;

Expand Down Expand Up @@ -37,10 +38,6 @@ export function skip(item: TExclusionItem): void {
skip.group = (item: TExclusionItem) =>
addTo(ExclusionGroup.SKIP, 'groups', item);

export function isExcludedIndividually(): boolean {
return !!ctx.useX().skipped;
}

//Checks whether a certain test profile excluded by any of the exclusion groups.

// eslint-disable-next-line complexity, max-statements, max-lines-per-function
Expand Down

1 comment on commit f601e1c

@vercel
Copy link

@vercel vercel bot commented on f601e1c Feb 9, 2022

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-ealush.vercel.app
vest-website.vercel.app
vest-next.vercel.app
vest-next-git-latest-ealush.vercel.app

Please sign in to comment.