diff --git a/packages/vest/src/isolates/omitWhen.ts b/packages/vest/src/isolates/omitWhen.ts index f99cfa7b3..a32085cb4 100644 --- a/packages/vest/src/isolates/omitWhen.ts +++ b/packages/vest/src/isolates/omitWhen.ts @@ -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. @@ -27,10 +27,7 @@ export function omitWhen( { omitted: useWithinActiveOmitWhen() || - optionalFunctionValue( - conditional, - optionalFunctionValue(useCreateSuiteResult), - ), + optionalFunctionValue(conditional, LazyDraft()), }, callback, ); diff --git a/packages/vest/src/isolates/skipWhen.ts b/packages/vest/src/isolates/skipWhen.ts index 37ff4cd18..bd56bf047 100644 --- a/packages/vest/src/isolates/skipWhen.ts +++ b/packages/vest/src/isolates/skipWhen.ts @@ -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. @@ -29,10 +29,7 @@ export function skipWhen( // 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()), }, callback, ); diff --git a/packages/vest/src/suiteResult/selectors/LazyDraft.ts b/packages/vest/src/suiteResult/selectors/LazyDraft.ts new file mode 100644 index 000000000..e5a82407c --- /dev/null +++ b/packages/vest/src/suiteResult/selectors/LazyDraft.ts @@ -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 { + const emptySummary = constructSuiteResultObject(new SuiteSummary()); + + return new Proxy(emptySummary, { + get: (_, prop) => { + const result = useCreateSuiteResult(); + + return result[prop as keyof SuiteResult]; + }, + }) as SuiteResult; +} diff --git a/packages/vest/src/suiteResult/suiteResult.ts b/packages/vest/src/suiteResult/suiteResult.ts index 76086110d..897675254 100644 --- a/packages/vest/src/suiteResult/suiteResult.ts +++ b/packages/vest/src/suiteResult/suiteResult.ts @@ -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'; @@ -15,12 +20,16 @@ export function useCreateSuiteResult< // @vx-allow use-use const suiteName = useSuiteName(); - return freezeAssign>( - summary, - suiteSelectors(summary), - { - suiteName, - }, - ) as SuiteResult; + + return Object.freeze(constructSuiteResultObject(summary, suiteName)); }); } + +export function constructSuiteResultObject< + F extends TFieldName, + G extends TGroupName, +>(summary: SuiteSummary, suiteName?: Maybe): SuiteResult { + return assign(summary, suiteSelectors(summary), { + suiteName, + }) as SuiteResult; +} diff --git a/packages/vest/tsconfig.json b/packages/vest/tsconfig.json index 8feccd6d6..7c311562d 100644 --- a/packages/vest/tsconfig.json +++ b/packages/vest/tsconfig.json @@ -30,6 +30,7 @@ "./src/suiteResult/selectors/hasFailuresByTestObjects.ts" ], "collectFailures": ["./src/suiteResult/selectors/collectFailures.ts"], + "LazyDraft": ["./src/suiteResult/selectors/LazyDraft.ts"], "shouldSkipDoneRegistration": [ "./src/suiteResult/done/shouldSkipDoneRegistration.ts" ], diff --git a/vitest.config.ts b/vitest.config.ts index 736555f2b..4ad47d879 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -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', + ], }), ], }); diff --git a/yarn.lock b/yarn.lock index ba1474368..3c7908167 100644 --- a/yarn.lock +++ b/yarn.lock @@ -204,7 +204,7 @@ __metadata: languageName: node linkType: hard -"@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.10.4, @babel/code-frame@npm:^7.12.13, @babel/code-frame@npm:^7.16.0, @babel/code-frame@npm:^7.22.13, @babel/code-frame@npm:^7.23.5, @babel/code-frame@npm:^7.8.3": +"@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.10.4, @babel/code-frame@npm:^7.16.0, @babel/code-frame@npm:^7.22.13, @babel/code-frame@npm:^7.23.5, @babel/code-frame@npm:^7.8.3": version: 7.23.5 resolution: "@babel/code-frame@npm:7.23.5" dependencies: @@ -2551,15 +2551,6 @@ __metadata: languageName: node linkType: hard -"@jest/expect-utils@npm:^29.7.0": - version: 29.7.0 - resolution: "@jest/expect-utils@npm:29.7.0" - dependencies: - jest-get-type: ^29.6.3 - checksum: 75eb177f3d00b6331bcaa057e07c0ccb0733a1d0a1943e1d8db346779039cb7f103789f16e502f888a3096fb58c2300c38d1f3748b36a7fa762eb6f6d1b160ed - languageName: node - linkType: hard - "@jest/schemas@npm:^29.6.3": version: 29.6.3 resolution: "@jest/schemas@npm:29.6.3" @@ -3510,16 +3501,6 @@ __metadata: languageName: node linkType: hard -"@types/jest@npm:^29.5.12": - version: 29.5.12 - resolution: "@types/jest@npm:29.5.12" - dependencies: - expect: ^29.0.0 - pretty-format: ^29.0.0 - checksum: 19b1efdeed9d9a60a81edc8226cdeae5af7479e493eaed273e01243891c9651f7b8b4c08fc633a7d0d1d379b091c4179bbaa0807af62542325fd72f2dd17ce1c - languageName: node - linkType: hard - "@types/json-schema@npm:*, @types/json-schema@npm:^7.0.12, @types/json-schema@npm:^7.0.4, @types/json-schema@npm:^7.0.5, @types/json-schema@npm:^7.0.8, @types/json-schema@npm:^7.0.9": version: 7.0.14 resolution: "@types/json-schema@npm:7.0.14" @@ -3700,7 +3681,7 @@ __metadata: languageName: node linkType: hard -"@types/semver@npm:^7.3.12, @types/semver@npm:^7.5.0": +"@types/semver@npm:^7.5.0": version: 7.5.1 resolution: "@types/semver@npm:7.5.1" checksum: 2fffe938c7ac168711f245a16e1856a3578d77161ca17e29a05c3e02c7be3e9c5beefa29a3350f6c1bd982fb70aa28cc52e4845eb7d36246bcdc0377170d584d @@ -3735,13 +3716,6 @@ __metadata: languageName: node linkType: hard -"@types/stack-utils@npm:^2.0.0": - version: 2.0.1 - resolution: "@types/stack-utils@npm:2.0.1" - checksum: 205fdbe3326b7046d7eaf5e494d8084f2659086a266f3f9cf00bccc549c8e36e407f88168ad4383c8b07099957ad669f75f2532ed4bc70be2b037330f7bae019 - languageName: node - linkType: hard - "@types/ua-parser-js@npm:^0.7.36": version: 0.7.36 resolution: "@types/ua-parser-js@npm:0.7.36" @@ -3838,16 +3812,6 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/scope-manager@npm:5.54.0": - version: 5.54.0 - resolution: "@typescript-eslint/scope-manager@npm:5.54.0" - dependencies: - "@typescript-eslint/types": 5.54.0 - "@typescript-eslint/visitor-keys": 5.54.0 - checksum: e50f12396de0ddb94aab119bdd5f4769b80dd2c273e137fd25e5811e25114d7a3d3668cdb3c454aca9537e940744881d62a1fed2ec86f07f60533dc7382ae15c - languageName: node - linkType: hard - "@typescript-eslint/scope-manager@npm:6.21.0": version: 6.21.0 resolution: "@typescript-eslint/scope-manager@npm:6.21.0" @@ -3875,13 +3839,6 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/types@npm:5.54.0": - version: 5.54.0 - resolution: "@typescript-eslint/types@npm:5.54.0" - checksum: 0f66b1b93078f3afea6dfcd3d4e2f0abea4f60cd0c613c2cf13f85098e5bf786185484c9846ed80b6c4272de2c31a70c5a8aacb91314cf1b6da7dcb8855cb7ac - languageName: node - linkType: hard - "@typescript-eslint/types@npm:6.21.0": version: 6.21.0 resolution: "@typescript-eslint/types@npm:6.21.0" @@ -3889,24 +3846,6 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/typescript-estree@npm:5.54.0": - version: 5.54.0 - resolution: "@typescript-eslint/typescript-estree@npm:5.54.0" - dependencies: - "@typescript-eslint/types": 5.54.0 - "@typescript-eslint/visitor-keys": 5.54.0 - debug: ^4.3.4 - globby: ^11.1.0 - is-glob: ^4.0.3 - semver: ^7.3.7 - tsutils: ^3.21.0 - peerDependenciesMeta: - typescript: - optional: true - checksum: 377c75c34c4f95b7ab6218c1d96a6db3ea6ed6727711b6a09354582fe0157861dc1b6fb9e3f7113cd09741f713735d59d5ab5845457f5733a4ebad7470bf600a - languageName: node - linkType: hard - "@typescript-eslint/typescript-estree@npm:6.21.0": version: 6.21.0 resolution: "@typescript-eslint/typescript-estree@npm:6.21.0" @@ -3943,34 +3882,6 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/utils@npm:^5.10.0": - version: 5.54.0 - resolution: "@typescript-eslint/utils@npm:5.54.0" - dependencies: - "@types/json-schema": ^7.0.9 - "@types/semver": ^7.3.12 - "@typescript-eslint/scope-manager": 5.54.0 - "@typescript-eslint/types": 5.54.0 - "@typescript-eslint/typescript-estree": 5.54.0 - eslint-scope: ^5.1.1 - eslint-utils: ^3.0.0 - semver: ^7.3.7 - peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - checksum: b8f344fc2961c7af530b93e53d5a17b5084cdf550b381082e3fb7f349ef16e718d9eebde1b9fc2d8fc4ecf8d60d334b004359977247554265c1afc87323bed37 - languageName: node - linkType: hard - -"@typescript-eslint/visitor-keys@npm:5.54.0": - version: 5.54.0 - resolution: "@typescript-eslint/visitor-keys@npm:5.54.0" - dependencies: - "@typescript-eslint/types": 5.54.0 - eslint-visitor-keys: ^3.3.0 - checksum: 17fc323c09e6272b603cdaec30a99916600fbbb737e1fbc8c1727a487753b4363cea112277fa43e0562bff34bdd1de9ad73ff9433118b1fd469b112fad0313ca - languageName: node - linkType: hard - "@typescript-eslint/visitor-keys@npm:6.21.0": version: 6.21.0 resolution: "@typescript-eslint/visitor-keys@npm:6.21.0" @@ -4468,13 +4379,6 @@ __metadata: languageName: node linkType: hard -"ansi-styles@npm:^5.0.0": - version: 5.2.0 - resolution: "ansi-styles@npm:5.2.0" - checksum: d7f4e97ce0623aea6bc0d90dcd28881ee04cba06c570b97fd3391bd7a268eedfd9d5e2dd4fdcbdd82b8105df5faf6f24aaedc08eaf3da898e702db5948f63469 - languageName: node - linkType: hard - "ansi-styles@npm:^6.1.0": version: 6.2.1 resolution: "ansi-styles@npm:6.2.1" @@ -6170,13 +6074,6 @@ __metadata: languageName: node linkType: hard -"diff-sequences@npm:^29.6.3": - version: 29.6.3 - resolution: "diff-sequences@npm:29.6.3" - checksum: f4914158e1f2276343d98ff5b31fc004e7304f5470bf0f1adb2ac6955d85a531a6458d33e87667f98f6ae52ebd3891bb47d420bb48a5bd8b7a27ee25b20e33aa - languageName: node - linkType: hard - "dir-glob@npm:^3.0.1": version: 3.0.1 resolution: "dir-glob@npm:3.0.1" @@ -6652,13 +6549,6 @@ __metadata: languageName: node linkType: hard -"escape-string-regexp@npm:^2.0.0": - version: 2.0.0 - resolution: "escape-string-regexp@npm:2.0.0" - checksum: 9f8a2d5743677c16e85c810e3024d54f0c8dea6424fad3c79ef6666e81dd0846f7437f5e729dfcdac8981bc9e5294c39b4580814d114076b8d36318f46ae4395 - languageName: node - linkType: hard - "escape-string-regexp@npm:^4.0.0": version: 4.0.0 resolution: "escape-string-regexp@npm:4.0.0" @@ -6752,31 +6642,13 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-jest@npm:^27.9.0": - version: 27.9.0 - resolution: "eslint-plugin-jest@npm:27.9.0" - dependencies: - "@typescript-eslint/utils": ^5.10.0 - peerDependencies: - "@typescript-eslint/eslint-plugin": ^5.0.0 || ^6.0.0 || ^7.0.0 - eslint: ^7.0.0 || ^8.0.0 - jest: "*" - peerDependenciesMeta: - "@typescript-eslint/eslint-plugin": - optional: true - jest: - optional: true - checksum: e2a4b415105408de28ad146818fcc6f4e122f6a39c6b2216ec5c24a80393f1390298b20231b0467bc5fd730f6e24b05b89e1a6a3ce651fc159aa4174ecc233d0 - languageName: node - linkType: hard - "eslint-plugin-vest-internal@workspace:vx/eslint-plugin-vest-internal": version: 0.0.0-use.local resolution: "eslint-plugin-vest-internal@workspace:vx/eslint-plugin-vest-internal" languageName: unknown linkType: soft -"eslint-scope@npm:5.1.1, eslint-scope@npm:^5.1.1": +"eslint-scope@npm:5.1.1": version: 5.1.1 resolution: "eslint-scope@npm:5.1.1" dependencies: @@ -6796,24 +6668,6 @@ __metadata: languageName: node linkType: hard -"eslint-utils@npm:^3.0.0": - version: 3.0.0 - resolution: "eslint-utils@npm:3.0.0" - dependencies: - eslint-visitor-keys: ^2.0.0 - peerDependencies: - eslint: ">=5" - checksum: 0668fe02f5adab2e5a367eee5089f4c39033af20499df88fe4e6aba2015c20720404d8c3d6349b6f716b08fdf91b9da4e5d5481f265049278099c4c836ccb619 - languageName: node - linkType: hard - -"eslint-visitor-keys@npm:^2.0.0": - version: 2.1.0 - resolution: "eslint-visitor-keys@npm:2.1.0" - checksum: e3081d7dd2611a35f0388bbdc2f5da60b3a3c5b8b6e928daffff7391146b434d691577aa95064c8b7faad0b8a680266bcda0a42439c18c717b80e6718d7e267d - languageName: node - linkType: hard - "eslint-visitor-keys@npm:^3.3.0, eslint-visitor-keys@npm:^3.4.1, eslint-visitor-keys@npm:^3.4.3": version: 3.4.3 resolution: "eslint-visitor-keys@npm:3.4.3" @@ -7093,19 +6947,6 @@ __metadata: languageName: node linkType: hard -"expect@npm:^29.0.0": - version: 29.7.0 - resolution: "expect@npm:29.7.0" - dependencies: - "@jest/expect-utils": ^29.7.0 - jest-get-type: ^29.6.3 - jest-matcher-utils: ^29.7.0 - jest-message-util: ^29.7.0 - jest-util: ^29.7.0 - checksum: 9257f10288e149b81254a0fda8ffe8d54a7061cd61d7515779998b012579d2b8c22354b0eb901daf0145f347403da582f75f359f4810c007182ad3fb318b5c0c - languageName: node - linkType: hard - "express@npm:^4.17.3": version: 4.18.2 resolution: "express@npm:4.18.2" @@ -9134,54 +8975,6 @@ __metadata: languageName: node linkType: hard -"jest-diff@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-diff@npm:29.7.0" - dependencies: - chalk: ^4.0.0 - diff-sequences: ^29.6.3 - jest-get-type: ^29.6.3 - pretty-format: ^29.7.0 - checksum: 08e24a9dd43bfba1ef07a6374e5af138f53137b79ec3d5cc71a2303515335898888fa5409959172e1e05de966c9e714368d15e8994b0af7441f0721ee8e1bb77 - languageName: node - linkType: hard - -"jest-get-type@npm:^29.6.3": - version: 29.6.3 - resolution: "jest-get-type@npm:29.6.3" - checksum: 88ac9102d4679d768accae29f1e75f592b760b44277df288ad76ce5bf038c3f5ce3719dea8aa0f035dac30e9eb034b848ce716b9183ad7cc222d029f03e92205 - languageName: node - linkType: hard - -"jest-matcher-utils@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-matcher-utils@npm:29.7.0" - dependencies: - chalk: ^4.0.0 - jest-diff: ^29.7.0 - jest-get-type: ^29.6.3 - pretty-format: ^29.7.0 - checksum: d7259e5f995d915e8a37a8fd494cb7d6af24cd2a287b200f831717ba0d015190375f9f5dc35393b8ba2aae9b2ebd60984635269c7f8cff7d85b077543b7744cd - languageName: node - linkType: hard - -"jest-message-util@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-message-util@npm:29.7.0" - dependencies: - "@babel/code-frame": ^7.12.13 - "@jest/types": ^29.6.3 - "@types/stack-utils": ^2.0.0 - chalk: ^4.0.0 - graceful-fs: ^4.2.9 - micromatch: ^4.0.4 - pretty-format: ^29.7.0 - slash: ^3.0.0 - stack-utils: ^2.0.3 - checksum: a9d025b1c6726a2ff17d54cc694de088b0489456c69106be6b615db7a51b7beb66788bea7a59991a019d924fbf20f67d085a445aedb9a4d6760363f4d7d09930 - languageName: node - linkType: hard - "jest-util@npm:^29.7.0": version: 29.7.0 resolution: "jest-util@npm:29.7.0" @@ -11988,17 +11781,6 @@ __metadata: languageName: node linkType: hard -"pretty-format@npm:^29.0.0, pretty-format@npm:^29.7.0": - version: 29.7.0 - resolution: "pretty-format@npm:29.7.0" - dependencies: - "@jest/schemas": ^29.6.3 - ansi-styles: ^5.0.0 - react-is: ^18.0.0 - checksum: 032c1602383e71e9c0c02a01bbd25d6759d60e9c7cf21937dde8357aa753da348fcec5def5d1002c9678a8524d5fe099ad98861286550ef44de8808cc61e43b6 - languageName: node - linkType: hard - "pretty-quick@npm:^3.3.1": version: 3.3.1 resolution: "pretty-quick@npm:3.3.1" @@ -12308,13 +12090,6 @@ __metadata: languageName: node linkType: hard -"react-is@npm:^18.0.0": - version: 18.2.0 - resolution: "react-is@npm:18.2.0" - checksum: e72d0ba81b5922759e4aff17e0252bd29988f9642ed817f56b25a3e217e13eea8a7f2322af99a06edb779da12d5d636e9fda473d620df9a3da0df2a74141d53e - languageName: node - linkType: hard - "react-json-view-lite@npm:^1.2.0": version: 1.2.1 resolution: "react-json-view-lite@npm:1.2.1" @@ -12929,7 +12704,6 @@ __metadata: resolution: "root-workspace-0b6124@workspace:." dependencies: "@faker-js/faker": ^8.4.1 - "@types/jest": ^29.5.12 "@types/lodash": ^4.17.5 "@typescript-eslint/eslint-plugin": ^6.21.0 "@typescript-eslint/parser": ^6.21.0 @@ -12937,7 +12711,6 @@ __metadata: eslint-config-prettier: ^9.1.0 eslint-import-resolver-typescript: ^3.6.1 eslint-plugin-import: ^2.29.1 - eslint-plugin-jest: ^27.9.0 husky: ^8.0.3 lodash: ^4.17.21 prettier: ^3.3.1 @@ -13531,15 +13304,6 @@ __metadata: languageName: node linkType: hard -"stack-utils@npm:^2.0.3": - version: 2.0.6 - resolution: "stack-utils@npm:2.0.6" - dependencies: - escape-string-regexp: ^2.0.0 - checksum: 052bf4d25bbf5f78e06c1d5e67de2e088b06871fa04107ca8d3f0e9d9263326e2942c8bedee3545795fc77d787d443a538345eef74db2f8e35db3558c6f91ff7 - languageName: node - linkType: hard - "stackback@npm:0.0.2": version: 0.0.2 resolution: "stackback@npm:0.0.2" @@ -14047,13 +13811,6 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^1.8.1": - version: 1.14.1 - resolution: "tslib@npm:1.14.1" - checksum: dbe628ef87f66691d5d2959b3e41b9ca0045c3ee3c7c7b906cc1e328b39f199bb1ad9e671c39025bd56122ac57dfbf7385a94843b1cc07c60a4db74795829acd - languageName: node - linkType: hard - "tslib@npm:^2.0.3, tslib@npm:^2.1.0, tslib@npm:^2.4.0, tslib@npm:^2.6.0, tslib@npm:^2.6.1, tslib@npm:^2.6.2, tslib@npm:^2.6.3": version: 2.6.3 resolution: "tslib@npm:2.6.3" @@ -14061,17 +13818,6 @@ __metadata: languageName: node linkType: hard -"tsutils@npm:^3.21.0": - version: 3.21.0 - resolution: "tsutils@npm:3.21.0" - dependencies: - tslib: ^1.8.1 - peerDependencies: - typescript: ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" - checksum: 1843f4c1b2e0f975e08c4c21caa4af4f7f65a12ac1b81b3b8489366826259323feb3fc7a243123453d2d1a02314205a7634e048d4a8009921da19f99755cdc48 - languageName: node - linkType: hard - "type-check@npm:^0.4.0, type-check@npm:~0.4.0": version: 0.4.0 resolution: "type-check@npm:0.4.0"