diff --git a/packages/vest/src/hooks/focused/__tests__/__snapshots__/focused.test.ts.snap b/packages/vest/src/hooks/focused/__tests__/__snapshots__/focused.test.ts.snap index 854c4f94a..c1a83994a 100644 --- a/packages/vest/src/hooks/focused/__tests__/__snapshots__/focused.test.ts.snap +++ b/packages/vest/src/hooks/focused/__tests__/__snapshots__/focused.test.ts.snap @@ -3,6 +3,7 @@ exports[`Top Level Focus Top Level Skip When passing false Should run all fields 1`] = ` { "done": [Function], + "dump": [Function], "errorCount": 3, "errors": [ SummaryFailure { @@ -77,6 +78,7 @@ exports[`Top Level Focus Top Level Skip When passing false Should run all fields exports[`Top Level Focus Top Level Skip When passing undefined Should run all fields 1`] = ` { "done": [Function], + "dump": [Function], "errorCount": 3, "errors": [ SummaryFailure { diff --git a/packages/vest/src/suite/__tests__/__snapshots__/staticSuite.test.ts.snap b/packages/vest/src/suite/__tests__/__snapshots__/staticSuite.test.ts.snap new file mode 100644 index 000000000..4a47a41cd --- /dev/null +++ b/packages/vest/src/suite/__tests__/__snapshots__/staticSuite.test.ts.snap @@ -0,0 +1,173 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`staticSuite dump should output a dump of the suite 1`] = ` +{ + "$type": "Suite", + "allowReorder": undefined, + "children": [ + { + "$type": "Test", + "allowReorder": undefined, + "children": null, + "data": { + "fieldName": "t1", + "severity": "error", + "status": "FAILED", + "testFn": [Function], + }, + "key": null, + "keys": null, + "output": undefined, + "parent": [Circular], + }, + { + "$type": "Test", + "allowReorder": undefined, + "children": null, + "data": { + "fieldName": "t2", + "severity": "error", + "status": "FAILED", + "testFn": [Function], + }, + "key": null, + "keys": null, + "output": undefined, + "parent": [Circular], + }, + { + "$type": "Group", + "allowReorder": undefined, + "children": [ + { + "$type": "Test", + "allowReorder": undefined, + "children": null, + "data": { + "fieldName": "t1", + "groupName": "g1", + "severity": "error", + "status": "SKIPPED", + "testFn": [Function], + }, + "key": null, + "keys": null, + "output": undefined, + "parent": [Circular], + }, + { + "$type": "Test", + "allowReorder": undefined, + "children": null, + "data": { + "fieldName": "t3", + "groupName": "g1", + "severity": "error", + "status": "FAILED", + "testFn": [Function], + }, + "key": null, + "keys": null, + "output": undefined, + "parent": [Circular], + }, + ], + "data": {}, + "key": null, + "keys": null, + "output": undefined, + "parent": [Circular], + }, + ], + "data": { + "optional": {}, + }, + "key": null, + "keys": null, + "output": { + "done": [Function], + "errorCount": 3, + "errors": [ + SummaryFailure { + "fieldName": "t1", + "groupName": undefined, + "message": undefined, + }, + SummaryFailure { + "fieldName": "t2", + "groupName": undefined, + "message": undefined, + }, + SummaryFailure { + "fieldName": "t3", + "groupName": "g1", + "message": undefined, + }, + ], + "getError": [Function], + "getErrors": [Function], + "getErrorsByGroup": [Function], + "getWarning": [Function], + "getWarnings": [Function], + "getWarningsByGroup": [Function], + "groups": { + "g1": { + "t1": SummaryBase { + "errorCount": 0, + "errors": [], + "testCount": 0, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + "t3": SummaryBase { + "errorCount": 1, + "errors": [], + "testCount": 1, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + }, + }, + "hasErrors": [Function], + "hasErrorsByGroup": [Function], + "hasWarnings": [Function], + "hasWarningsByGroup": [Function], + "isValid": [Function], + "isValidByGroup": [Function], + "suiteName": undefined, + "testCount": 3, + "tests": { + "t1": { + "errorCount": 1, + "errors": [], + "testCount": 1, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + "t2": SummaryBase { + "errorCount": 1, + "errors": [], + "testCount": 1, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + "t3": SummaryBase { + "errorCount": 1, + "errors": [], + "testCount": 1, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + }, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + "parent": null, +} +`; diff --git a/packages/vest/src/suite/__tests__/staticSuite.test.ts b/packages/vest/src/suite/__tests__/staticSuite.test.ts index 526087646..31b29c6bd 100644 --- a/packages/vest/src/suite/__tests__/staticSuite.test.ts +++ b/packages/vest/src/suite/__tests__/staticSuite.test.ts @@ -1,3 +1,4 @@ +import { VestIsolateType } from 'VestIsolateType'; import * as vest from 'vest'; import { staticSuite } from 'vest'; @@ -68,4 +69,38 @@ describe('staticSuite', () => { }); }); }); + + describe('dump', () => { + it('should output a dump of the suite', () => { + const suite = staticSuite(() => { + vest.test('t1', () => false); + vest.test('t2', () => false); + + vest.group('g1', () => { + vest.test('t1', () => false); + vest.test('t3', () => false); + }); + }); + + const res = suite(); + + expect(res.dump()).toHaveProperty('$type', VestIsolateType.Suite); + expect(res.dump()).toHaveProperty('children'); + expect(res.dump().children).toHaveLength(3); + expect(res.dump().children?.[0]).toHaveProperty( + '$type', + VestIsolateType.Test + ); + expect(res.dump().children?.[1]).toHaveProperty( + '$type', + VestIsolateType.Test + ); + expect(res.dump().children?.[2]).toHaveProperty( + '$type', + VestIsolateType.Group + ); + + expect(res.dump()).toMatchSnapshot(); + }); + }); }); diff --git a/packages/vest/src/suite/staticSuite.ts b/packages/vest/src/suite/staticSuite.ts index 98f872888..5a6e80df9 100644 --- a/packages/vest/src/suite/staticSuite.ts +++ b/packages/vest/src/suite/staticSuite.ts @@ -1,5 +1,6 @@ import { CB, assign } from 'vest-utils'; +import { TIsolateSuite } from 'IsolateSuite'; import { SuiteRunResult, TFieldName, TGroupName } from 'SuiteResultTypes'; import { createSuite } from 'createSuite'; import { TTypedMethods, getTypedMethods } from 'getTypedMethods'; @@ -27,7 +28,20 @@ export function staticSuite< T extends CB = CB >(suiteCallback: T): StaticSuite { return assign( - (...args: Parameters) => createSuite(suiteCallback)(...args), + (...args: Parameters) => { + const suite = createSuite(suiteCallback); + + const result = suite(...args); + + return Object.freeze( + assign( + { + dump: suite.dump, + }, + result + ) + ); + }, { ...getTypedMethods(), } @@ -38,4 +52,7 @@ type StaticSuite< F extends TFieldName = string, G extends TGroupName = string, T extends CB = CB -> = ((...args: Parameters) => SuiteRunResult) & TTypedMethods; +> = ((...args: Parameters) => SuiteRunResult & { + dump: CB; +}) & + TTypedMethods;