Skip to content

Commit

Permalink
patch(vest): Serialize focused data keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 29, 2023
1 parent cc01f3b commit c1aaa64
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
16 changes: 13 additions & 3 deletions packages/vest/src/exports/SuiteSerializer.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { assign } from 'vest-utils';
import { IsolateSerializer } from 'vestjs-runtime';

import { TIsolateSuite } from 'IsolateSuite';
import { IsolateTestPayload } from 'IsolateTest';
import { TFieldName, TGroupName } from 'SuiteResultTypes';
import { Suite } from 'SuiteTypes';
import { IsolateFocusedPayload } from 'focused';

export class SuiteSerializer {
static serialize(suite: Suite<TFieldName, TGroupName>) {
const dump = { ...suite.dump(), output: undefined };

return IsolateSerializer.serialize(dump, miniMap);
return IsolateSerializer.serialize(dump, MiniMap);
}

static deserialize(
serialized: string | TIsolateSuite | Record<string, any>
): TIsolateSuite {
return IsolateSerializer.deserialize(serialized, miniMap) as TIsolateSuite;
return IsolateSerializer.deserialize(serialized, MiniMap) as TIsolateSuite;
}

static resume(
Expand All @@ -28,7 +30,7 @@ export class SuiteSerializer {
}
}

const miniMap: Record<keyof IsolateTestPayload, string> = {
const testMiniMap: Record<keyof IsolateTestPayload, string> = {
asyncTest: '_at', // asyncTest is not serialized
fieldName: 'fN',
groupName: 'gN',
Expand All @@ -37,3 +39,11 @@ const miniMap: Record<keyof IsolateTestPayload, string> = {
status: 'st',
testFn: '_tf', // testFn is not serialized
};

const focusMiniMap: Record<keyof IsolateFocusedPayload, string> = {
focusMode: 'fM',
match: 'm',
matchAll: 'mA',
};

const MiniMap = assign({}, testMiniMap, focusMiniMap);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SuiteSerializer Should produce a valid serialized dump 1`] = `"{"C":[{"D":{"focusMode":0,"match":["field_1"],"matchAll":false},"$":"Focused","S":"DONE"},{"D":{"sv":"error","fN":"field_1","msg":"field_1_message"},"$":"Test","S":"FAILED"},{"D":{"sv":"error","fN":"field_2","msg":"field_2_message"},"$":"Test","S":"SKIPPED"},{"C":[{"D":{"sv":"error","fN":"field_3","gN":"group_1","msg":"field_3_message_1"},"$":"Test","S":"SKIPPED"},{"D":{"sv":"error","fN":"field_3","gN":"group_1","msg":"field_3_message_2"},"$":"Test","S":"SKIPPED"},{"D":{"sv":"error","fN":"field_4","gN":"group_1","msg":"field_4_message"},"$":"Test","S":"SKIPPED"}],"$":"Group","S":"DONE"},{"C":[{"D":{"sv":"error","fN":"field_5","msg":"field_5_message"},"$":"Test","S":"SKIPPED"}],"$":"SkipWhen","S":"DONE"}],"D":{"optional":{}},"$":"Suite","S":"DONE"}"`;
exports[`SuiteSerializer Should produce a valid serialized dump 1`] = `"{"C":[{"D":{"fM":0,"m":["field_1"],"mA":false},"$":"Focused","S":"DONE"},{"D":{"sv":"error","fN":"field_1","msg":"field_1_message"},"$":"Test","S":"FAILED"},{"D":{"sv":"error","fN":"field_2","msg":"field_2_message"},"$":"Test","S":"SKIPPED"},{"C":[{"D":{"sv":"error","fN":"field_3","gN":"group_1","msg":"field_3_message_1"},"$":"Test","S":"SKIPPED"},{"D":{"sv":"error","fN":"field_3","gN":"group_1","msg":"field_3_message_2"},"$":"Test","S":"SKIPPED"},{"D":{"sv":"error","fN":"field_4","gN":"group_1","msg":"field_4_message"},"$":"Test","S":"SKIPPED"}],"$":"Group","S":"DONE"},{"C":[{"D":{"sv":"error","fN":"field_5","msg":"field_5_message"},"$":"Test","S":"SKIPPED"}],"$":"SkipWhen","S":"DONE"}],"D":{"optional":{}},"$":"Suite","S":"DONE"}"`;
6 changes: 4 additions & 2 deletions packages/vest/src/hooks/focused/focused.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export type ExclusionItem = Maybe<OneOrMoreOf<string>>;
export type FieldExclusion<F extends TFieldName> = Maybe<OneOrMoreOf<F>>;
export type GroupExclusion<G extends TGroupName> = Maybe<OneOrMoreOf<G>>;

export type TIsolateFocused = TIsolate<{
export type TIsolateFocused = TIsolate<IsolateFocusedPayload>;

export type IsolateFocusedPayload = {
focusMode: FocusModes;
match: FieldExclusion<TFieldName>;
matchAll: boolean;
}>;
};

export function IsolateFocused(
focusMode: FocusModes,
Expand Down

2 comments on commit c1aaa64

@vercel
Copy link

@vercel vercel bot commented on c1aaa64 Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-next-ealush.vercel.app
vest-next.vercel.app
vest-website.vercel.app
vest-next-git-latest-ealush.vercel.app

@vercel
Copy link

@vercel vercel bot commented on c1aaa64 Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest – ./website

vest-ealush.vercel.app
vest.vercel.app
vest-git-latest-ealush.vercel.app
vestjs.dev
www.vestjs.dev

Please sign in to comment.