Skip to content

Commit

Permalink
Lazy Draft works
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Aug 7, 2024
1 parent 1496987 commit 689fc94
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 20 deletions.
7 changes: 2 additions & 5 deletions packages/vest/src/isolates/omitWhen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import type { CB } from 'vest-utils';
import { optionalFunctionValue } from 'vest-utils';
import { Isolate } from 'vestjs-runtime';

import { LazyDraft } from 'LazyDraft';
import { SuiteContext, useOmitted } from 'SuiteContext';
import { TFieldName, TGroupName } from 'SuiteResultTypes';
import { VestIsolateType } from 'VestIsolateType';
import { TDraftCondition } from 'getTypedMethods';
import { useCreateSuiteResult } from 'suiteResult';

/**
* Conditionally omits tests from the suite.
Expand All @@ -27,10 +27,7 @@ export function omitWhen<F extends TFieldName, G extends TGroupName>(
{
omitted:
useWithinActiveOmitWhen() ||
optionalFunctionValue(
conditional,
optionalFunctionValue(useCreateSuiteResult),
),
optionalFunctionValue(conditional, LazyDraft<F, G>()),
},
callback,
);
Expand Down
7 changes: 2 additions & 5 deletions packages/vest/src/isolates/skipWhen.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CB, optionalFunctionValue } from 'vest-utils';
import { Isolate } from 'vestjs-runtime';

import { LazyDraft } from 'LazyDraft';
import { SuiteContext, useSkipped } from 'SuiteContext';
import { TFieldName, TGroupName } from 'SuiteResultTypes';
import { VestIsolateType } from 'VestIsolateType';
import { TDraftCondition } from 'getTypedMethods';
import { useCreateSuiteResult } from 'suiteResult';

/**
* Conditionally skips running tests within the callback.
Expand All @@ -29,10 +29,7 @@ export function skipWhen<F extends TFieldName, G extends TGroupName>(
// we should skip the test if the parent conditional is true.
useIsExcludedIndividually() ||
// Otherwise, we should skip the test if the conditional is true.
optionalFunctionValue(
condition,
optionalFunctionValue(useCreateSuiteResult),
),
optionalFunctionValue(condition, LazyDraft<F, G>()),
},
callback,
);
Expand Down
24 changes: 24 additions & 0 deletions packages/vest/src/suiteResult/selectors/LazyDraft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
SuiteResult,
SuiteSummary,
TFieldName,
TGroupName,
} from 'SuiteResultTypes';
import { constructSuiteResultObject, useCreateSuiteResult } from 'suiteResult';

// @vx-allow use-use
export function LazyDraft<
F extends TFieldName,
G extends TGroupName,
>(): SuiteResult<F, G> {
const emptySummary = constructSuiteResultObject(new SuiteSummary<F, G>());

return new Proxy(emptySummary, {
get: (_, prop) => {
// @vx-allow use-use
const result = useCreateSuiteResult<F, G>();

return result[prop as keyof SuiteResult<F, G>];
},
}) as SuiteResult<F, G>;
}
27 changes: 18 additions & 9 deletions packages/vest/src/suiteResult/suiteResult.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { freezeAssign } from 'vest-utils';
import { assign, Maybe } from 'vest-utils';

import { useSuiteName, useSuiteResultCache } from 'Runtime';
import { SuiteResult, TFieldName, TGroupName } from 'SuiteResultTypes';
import {
SuiteResult,
SuiteSummary,
TFieldName,
TGroupName,
} from 'SuiteResultTypes';
import { suiteSelectors } from 'suiteSelectors';
import { useProduceSuiteSummary } from 'useProduceSuiteSummary';

Expand All @@ -15,12 +20,16 @@ export function useCreateSuiteResult<

// @vx-allow use-use
const suiteName = useSuiteName();
return freezeAssign<SuiteResult<F, G>>(
summary,
suiteSelectors<F, G>(summary),
{
suiteName,
},
) as SuiteResult<F, G>;

return Object.freeze(constructSuiteResultObject<F, G>(summary, suiteName));
});
}

export function constructSuiteResultObject<
F extends TFieldName,
G extends TGroupName,
>(summary: SuiteSummary<F, G>, suiteName?: Maybe<string>): SuiteResult<F, G> {
return assign(summary, suiteSelectors<F, G>(summary), {
suiteName,
}) as SuiteResult<F, G>;
}
1 change: 1 addition & 0 deletions packages/vest/tsconfig.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ export default defineConfig({
plugins: [
tsconfigPaths({
loose: true,
projects: ["packages/vest-utils","packages/context","packages/vestjs-runtime","packages/vast","packages/n4s","packages/vest","packages/anyone"],
projects: [
'packages/vest-utils',
'packages/context',
'packages/vestjs-runtime',
'packages/vast',
'packages/n4s',
'packages/vest',
'packages/anyone',
],
}),
],
});

0 comments on commit 689fc94

Please sign in to comment.