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 3e976a5 commit d6e883f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 277 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 @@ -6,7 +6,7 @@ import { SuiteContext, useOmitted } from 'SuiteContext';
import { TFieldName, TGroupName } from 'SuiteResultTypes';
import { VestIsolateType } from 'VestIsolateType';
import { TDraftCondition } from 'getTypedMethods';
import { useCreateSuiteResult } from 'suiteResult';
import { LazyDraft } from 'LazyDraft';

/**
* 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
Expand Up @@ -5,7 +5,7 @@ import { SuiteContext, useSkipped } from 'SuiteContext';
import { TFieldName, TGroupName } from 'SuiteResultTypes';
import { VestIsolateType } from 'VestIsolateType';
import { TDraftCondition } from 'getTypedMethods';
import { useCreateSuiteResult } from 'suiteResult';
import { LazyDraft } from 'LazyDraft';

/**
* 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
22 changes: 22 additions & 0 deletions packages/vest/src/suiteResult/selectors/LazyDraft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { constructSuiteResultObject, useCreateSuiteResult } from 'suiteResult';
import {
SuiteResult,
SuiteSummary,
TFieldName,
TGroupName,
} from 'SuiteResultTypes';

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) => {
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',
],
}),
],
});
Loading

0 comments on commit d6e883f

Please sign in to comment.