From e45eec181c11b250f63dfaf34f85b90b5b57fbe8 Mon Sep 17 00:00:00 2001 From: Evyatar Date: Sun, 12 Nov 2023 00:18:24 +0200 Subject: [PATCH] patch(vest): Change test status from within events --- packages/vest/src/core/VestBus/VestBus.ts | 21 ++++++++++++++++--- .../core/test/testLevelFlowControl/runTest.ts | 4 +--- .../__tests__/useProduceSuiteSummary.test.ts | 2 +- vx/config/jest/jest.setupAfterEnv.ts | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/vest/src/core/VestBus/VestBus.ts b/packages/vest/src/core/VestBus/VestBus.ts index 4299347bf..c9703da19 100644 --- a/packages/vest/src/core/VestBus/VestBus.ts +++ b/packages/vest/src/core/VestBus/VestBus.ts @@ -1,5 +1,5 @@ -import { CB } from 'vest-utils'; -import { Bus } from 'vestjs-runtime'; +import { CB, ValueOf } from 'vest-utils'; +import { Bus, RuntimeEvents, TIsolate } from 'vestjs-runtime'; import { Events } from 'BusEvents'; import { TIsolateTest } from 'IsolateTest'; @@ -11,6 +11,7 @@ import { import { TFieldName } from 'SuiteResultTypes'; import { TestWalker } from 'TestWalker'; import { VestTest } from 'VestTest'; +import { isIsolateTest } from 'isIsolateTest'; import { useOmitOptionalFields } from 'omitOptionalFields'; import { useRunDoneCallbacks, useRunFieldCallbacks } from 'runCallbacks'; @@ -39,6 +40,18 @@ export function useInitVestBus() { /* Let's just invalidate the suite cache for now */ }); + on(RuntimeEvents.ISOLATE_PENDING, (isolate: TIsolate) => { + if (isIsolateTest(isolate)) { + VestTest.setPending(isolate); + } + }); + + on(RuntimeEvents.ISOLATE_DONE, (isolate: TIsolate) => { + if (isIsolateTest(isolate)) { + VestBus.emit(Events.TEST_COMPLETED, isolate); + } + }); + on(Events.DONE_TEST_OMISSION_PASS, () => { /* We NEED to refresh the cache here. Don't ask */ }); @@ -85,7 +98,7 @@ export function useInitVestBus() { }).off; } - function on(event: Events | '*', cb: (...args: any[]) => void) { + function on(event: VestEvents, cb: (...args: any[]) => void) { VestBus.on(event, (...args: any[]) => { // This is more concise, but it might be an overkill // if we're adding events that don't need to invalidate the cache @@ -94,3 +107,5 @@ export function useInitVestBus() { }); } } + +type VestEvents = Events | ValueOf | '*'; diff --git a/packages/vest/src/core/test/testLevelFlowControl/runTest.ts b/packages/vest/src/core/test/testLevelFlowControl/runTest.ts index daeb766b3..a2f9d5d4d 100644 --- a/packages/vest/src/core/test/testLevelFlowControl/runTest.ts +++ b/packages/vest/src/core/test/testLevelFlowControl/runTest.ts @@ -98,7 +98,7 @@ function useRunAsyncTest(testObject: TIsolateTest): Promise | undefined { const { asyncTest, message } = VestTest.getData(testObject); if (!isPromise(asyncTest)) return; - VestTest.setPending(testObject); + // VestTest.setPending(testObject); const VestBus = Bus.useBus(); @@ -125,6 +125,4 @@ function onTestCompleted(VestBus: BusType, testObject: TIsolateTest) { // Attempts passing if the test is not already failed. // or is not canceled/omitted. VestTest.pass(testObject); - - VestBus.emit(Events.TEST_COMPLETED, testObject); } diff --git a/packages/vest/src/suiteResult/__tests__/useProduceSuiteSummary.test.ts b/packages/vest/src/suiteResult/__tests__/useProduceSuiteSummary.test.ts index cd22c8488..8ea791f8e 100644 --- a/packages/vest/src/suiteResult/__tests__/useProduceSuiteSummary.test.ts +++ b/packages/vest/src/suiteResult/__tests__/useProduceSuiteSummary.test.ts @@ -88,7 +88,7 @@ describe('useProduceSuiteSummary', () => { dummyTest.failing('field_1', 'message'); }); const res = suite(); - expect(res).toMatchObject(suite.get()); + expect(ser(res)).toEqual(ser(suite.get())); expect(suite.get()).toBe(suite.get()); }); diff --git a/vx/config/jest/jest.setupAfterEnv.ts b/vx/config/jest/jest.setupAfterEnv.ts index fc5d4d3f5..034ac71e4 100644 --- a/vx/config/jest/jest.setupAfterEnv.ts +++ b/vx/config/jest/jest.setupAfterEnv.ts @@ -17,7 +17,7 @@ const isDeepCopyOf = ( if (clone !== source) { return { pass: false, - message: () => 'Source and clone are not identical', + message: () => `Source and clone are not identical`, }; } }