diff --git a/packages/vest/src/core/test/__tests__/test.test.ts b/packages/vest/src/core/test/__tests__/test.test.ts index 64722f5ee..a96258033 100644 --- a/packages/vest/src/core/test/__tests__/test.test.ts +++ b/packages/vest/src/core/test/__tests__/test.test.ts @@ -1,13 +1,13 @@ import { faker } from '@faker-js/faker'; -import { ErrorStrings } from 'ErrorStrings'; -import { TIsolateTest } from 'IsolateTest'; -import { VestTest } from 'VestTest'; import { text } from 'vest-utils'; import { IsolateSerializer } from 'vestjs-runtime'; import { describe, it, expect, vi } from 'vitest'; import { TestPromise } from '../../../testUtils/testPromise'; +import { ErrorStrings } from 'ErrorStrings'; +import { TIsolateTest } from 'IsolateTest'; +import { VestTest } from 'VestTest'; import { enforce } from 'vest'; import * as vest from 'vest'; @@ -193,7 +193,7 @@ describe("Test Vest's `test` function", () => { expect(testObject.data.fieldName).toBe('field_name'); expect(testObject.key).toBe('keyboardcat'); expect(testObject.data.message).toBe('failure message'); - expect(IsolateSerializer.serialize(testObject)).toMatchSnapshot(); + expect(IsolateSerializer.serialize(testObject, v => v)).toMatchSnapshot(); }); it('throws when field name is not a string', () => { diff --git a/packages/vest/src/exports/SuiteSerializer.ts b/packages/vest/src/exports/SuiteSerializer.ts index 89ed205b6..810e905ca 100644 --- a/packages/vest/src/exports/SuiteSerializer.ts +++ b/packages/vest/src/exports/SuiteSerializer.ts @@ -1,7 +1,9 @@ import { CB } from 'vest-utils'; import { IsolateSerializer } from 'vestjs-runtime'; +import { IsolateKeys } from 'vestjs-runtime/src/Isolate/IsolateKeys'; import { TIsolateSuite } from 'IsolateSuite'; +import { TestStatus } from 'IsolateTestStateMachine'; import { TFieldName, TGroupName } from 'SuiteResultTypes'; import { Suite } from 'SuiteTypes'; @@ -11,9 +13,9 @@ export type Dumpable = { export class SuiteSerializer { static serialize(suite: Dumpable) { - const dump = { ...suite.dump(), output: undefined }; + const dump = { ...suite.dump() }; - return IsolateSerializer.serialize(dump); + return IsolateSerializer.serialize(dump, suiteSerializerReplacer); } static deserialize( @@ -31,3 +33,31 @@ export class SuiteSerializer { suite.resume(suiteRoot); } } + +function suiteSerializerReplacer(value: any, key: string) { + if (key === 'output') { + return undefined; + } + + if (key === IsolateKeys.Status) { + if (AllowedStatuses.has(value)) { + return value; + } + + return undefined; + } + + if (DisallowedKeys.has(key)) { + return undefined; + } + + return value; +} + +const AllowedStatuses = new Set([ + TestStatus.FAILED, + TestStatus.PASSING, + TestStatus.WARNING, +]); + +const DisallowedKeys = new Set(['focusMode', 'match', 'matchAll', 'severity']); diff --git a/packages/vest/src/exports/__tests__/SuiteSerializer.test.ts b/packages/vest/src/exports/__tests__/SuiteSerializer.test.ts index ca58221dd..aad2216ec 100644 --- a/packages/vest/src/exports/__tests__/SuiteSerializer.test.ts +++ b/packages/vest/src/exports/__tests__/SuiteSerializer.test.ts @@ -1,6 +1,6 @@ -import { SuiteSerializer } from 'SuiteSerializer'; import { describe, it, expect } from 'vitest'; +import { SuiteSerializer } from 'SuiteSerializer'; import * as vest from 'vest'; describe('SuiteSerializer', () => { @@ -48,7 +48,6 @@ describe('suite.resume', () => { }); suite(); - suite.get(); const serialized = SuiteSerializer.serialize(suite); diff --git a/packages/vest/src/exports/__tests__/__snapshots__/SuiteSerializer.test.ts.snap b/packages/vest/src/exports/__tests__/__snapshots__/SuiteSerializer.test.ts.snap index a5a5fa44f..a3d1c5545 100644 --- a/packages/vest/src/exports/__tests__/__snapshots__/SuiteSerializer.test.ts.snap +++ b/packages/vest/src/exports/__tests__/__snapshots__/SuiteSerializer.test.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`SuiteSerializer > Should produce a valid serialized dump 1`] = `"[{"0":"Suite","1":"9","2":{},"a":[{"0":"Focused","1":"9","2":{"focusMode":0,"match":["d"],"matchAll":false}},{"0":"3","1":"FAILED","2":{"4":"5","6":"d","7":"field_1_message"}},{"0":"3","1":"8","2":{"4":"5","6":"field_2","7":"field_2_message"}},{"0":"Group","1":"9","a":[{"0":"3","1":"8","2":{"4":"5","6":"e","7":"field_3_message_1","b":"c"}},{"0":"3","1":"8","2":{"4":"5","6":"e","7":"field_3_message_2","b":"c"}},{"0":"3","1":"8","2":{"4":"5","6":"field_4","7":"field_4_message","b":"c"}}]},{"0":"SkipWhen","1":"9","a":[{"0":"3","1":"8","2":{"4":"5","6":"field_5","7":"field_5_message"}}]}]},{"0":"$type","1":"status","2":"data","3":"Test","4":"severity","5":"error","6":"fieldName","7":"message","8":"SKIPPED","9":"DONE","a":"children","b":"groupName","c":"group_1","d":"field_1","e":"field_3"}]"`; +exports[`SuiteSerializer > Should produce a valid serialized dump 1`] = `"[{"0":"Suite","1":{},"5":[{"0":"Focused","1":{}},{"0":"2","1":{"3":"field_1","4":"field_1_message"},"status":"FAILED"},{"0":"2","1":{"3":"field_2","4":"field_2_message"}},{"0":"Group","5":[{"0":"2","1":{"3":"8","4":"field_3_message_1","6":"7"}},{"0":"2","1":{"3":"8","4":"field_3_message_2","6":"7"}},{"0":"2","1":{"3":"field_4","4":"field_4_message","6":"7"}}]},{"0":"SkipWhen","5":[{"0":"2","1":{"3":"field_5","4":"field_5_message"}}]}]},{"0":"$type","1":"data","2":"Test","3":"fieldName","4":"message","5":"children","6":"groupName","7":"group_1","8":"field_3"}]"`; exports[`suite.resume > Running the suite after resuming > Sanity - suite should run as expected > Should have correct state after resuming 1`] = ` { diff --git a/packages/vest/src/suiteResult/selectors/useProduceSuiteSummary.ts b/packages/vest/src/suiteResult/selectors/useProduceSuiteSummary.ts index bf5e5922b..67b0ac7a0 100644 --- a/packages/vest/src/suiteResult/selectors/useProduceSuiteSummary.ts +++ b/packages/vest/src/suiteResult/selectors/useProduceSuiteSummary.ts @@ -62,7 +62,7 @@ function addSummaryStats( summary.pendingCount++; } - if (!VestTest.isNonActionable(testObject)) { + if (shouldCountTestRun(testObject)) { summary.testCount++; } @@ -141,7 +141,9 @@ function appendTestObject( } // Increment the test count. - nextSummaryKey.testCount++; + if (shouldCountTestRun(testObject)) { + nextSummaryKey.testCount++; + } return nextSummaryKey; @@ -164,3 +166,9 @@ function baseTestStats() { warnings: [], }); } + +function shouldCountTestRun( + testObject: TIsolateTest, +): boolean { + return VestTest.isTested(testObject) || VestTest.isPending(testObject); +}