Skip to content

Commit

Permalink
patch(vestjs-runtime): Minify Children
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 28, 2023
1 parent 5c435f9 commit 7ab22d3
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/vest/src/core/test/__tests__/test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe("Test Vest's `test` function", () => {
expect(testObject.key).toBe('keyboardcat');
expect(testObject.data.message).toBe('failure message');
expect(IsolateSerializer.serialize(testObject)).toMatchInlineSnapshot(
`"{"$":"Test","D":{"severity":"error","fieldName":"field_name","message":"failure message"},"S":"PASSING","k":"keyboardcat"}"`
`"{"$":"Test","D":{"severity":"error","fieldName":"field_name","message":"failure message"},"S":"PASSING","ky":"keyboardcat"}"`
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe('suite.resume', () => {
expect(suite.get()).not.toEqual(suite2.get());

SuiteSerializer.resume(suite2, serialized);

expect(suite.get()).isDeepCopyOf(suite2.get());

suite2();
Expand Down
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`] = `"{"children":[{"$":"Focused","D":{"focusMode":0,"match":["field_1"],"matchAll":false},"S":"DONE"},{"$":"Test","D":{"severity":"error","fieldName":"field_1","message":"field_1_message"},"S":"FAILED"},{"$":"Test","D":{"severity":"error","fieldName":"field_2","message":"field_2_message"},"S":"SKIPPED"},{"children":[{"$":"Test","D":{"severity":"error","fieldName":"field_3","groupName":"group_1","message":"field_3_message_1"},"S":"SKIPPED"},{"$":"Test","D":{"severity":"error","fieldName":"field_3","groupName":"group_1","message":"field_3_message_2"},"S":"SKIPPED"},{"$":"Test","D":{"severity":"error","fieldName":"field_4","groupName":"group_1","message":"field_4_message"},"S":"SKIPPED"}],"$":"Group","D":{},"S":"DONE"},{"children":[{"$":"Test","D":{"severity":"error","fieldName":"field_5","message":"field_5_message"},"S":"SKIPPED"}],"$":"SkipWhen","D":{},"S":"DONE"}],"$":"Suite","D":{"optional":{}},"S":"DONE"}"`;
exports[`SuiteSerializer Should produce a valid serialized dump 1`] = `"{"C":[{"$":"Focused","D":{"focusMode":0,"match":["field_1"],"matchAll":false},"S":"DONE"},{"$":"Test","D":{"severity":"error","fieldName":"field_1","message":"field_1_message"},"S":"FAILED"},{"$":"Test","D":{"severity":"error","fieldName":"field_2","message":"field_2_message"},"S":"SKIPPED"},{"C":[{"$":"Test","D":{"severity":"error","fieldName":"field_3","groupName":"group_1","message":"field_3_message_1"},"S":"SKIPPED"},{"$":"Test","D":{"severity":"error","fieldName":"field_3","groupName":"group_1","message":"field_3_message_2"},"S":"SKIPPED"},{"$":"Test","D":{"severity":"error","fieldName":"field_4","groupName":"group_1","message":"field_4_message"},"S":"SKIPPED"}],"$":"Group","D":{},"S":"DONE"},{"C":[{"$":"Test","D":{"severity":"error","fieldName":"field_5","message":"field_5_message"},"S":"SKIPPED"}],"$":"SkipWhen","D":{},"S":"DONE"}],"$":"Suite","D":{"optional":{}},"S":"DONE"}"`;
11 changes: 7 additions & 4 deletions packages/vestjs-runtime/src/Isolate/IsolateKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ export enum IsolateKeys {
AllowReorder = 'allowReorder',
Status = 'status',
AbortController = 'abortController',
Children = 'children',
}

enum MinifiedKeys {
export enum MinifiedKeys {
Type = '$',
Keys = 'K',
Key = 'k',
Keys = 'Ks',
Key = 'ky',
Parent = 'P',
Data = 'D',
AllowReorder = 'aR',
AllowReorder = 'AR',
Status = 'S',
Children = 'C',
}

export const KeyToMinified = {
Expand Down Expand Up @@ -48,4 +50,5 @@ export const ExcludedFromDump = [
IsolateKeys.AbortController,
IsolateKeys.Parent,
IsolateKeys.Keys,
IsolateKeys.Children,
];
19 changes: 11 additions & 8 deletions packages/vestjs-runtime/src/exports/IsolateSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ExcludedFromDump,
IsolateKeys,
KeyToMinified,
MinifiedKeys,
MinifiedToKey,
} from 'IsolateKeys';
import { IsolateMutator } from 'IsolateMutator';
Expand All @@ -40,7 +41,7 @@ export class IsolateSerializer {
while (queue.length) {
const current = queue.shift();

const children = IsolateSerializer.getChildren(current);
const children = IsolateSerializer.expandChildren(current);

for (const key in MinifiedToKey) {
const value = current[key];
Expand Down Expand Up @@ -82,8 +83,10 @@ export class IsolateSerializer {
return JSON.stringify(transformIsolate(isolate));
}

static getChildren(node: TIsolate): Nullable<TIsolate[]> {
return node.children ? [...node.children] : null;
static expandChildren(node: Record<string, any>): Nullable<TIsolate[]> {
return node[MinifiedKeys.Children]
? [...node[MinifiedKeys.Children]]
: null;
}

static validateIsolate(node: Record<string, any> | TIsolate): void {
Expand All @@ -100,14 +103,14 @@ function transformIsolate(isolate: TIsolate): Record<string, any> {
const next: Record<string, any> = {};

if (isolate.children) {
next.children = isolate.children.map(transformIsolate);
next[MinifiedKeys.Children] = isolate.children.map(transformIsolate);
}

for (const key in isolate) {
if (key === 'children') {
continue;
}

// Skip keys that should be excluded from the dump.
// While we're excluding children from the dump, they'll actually remain there
// due to the fact that we've already transformed them recursively beforehand
// thus renaming them to the minified key.
if (isKeyExcluededFromDump(key)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ describe('IsolateSerializer', () => {
expect(inflated).toMatchInlineSnapshot(`
{
"$type": "URoot",
"C": [
{
"$": "UChild_1",
"D": {
"some_data": true,
},
},
{
"$": "UChild_2",
"D": {},
},
{
"$": "UChild_3",
"D": {},
},
],
"children": [
{
"$type": "UChild_1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`IsolateSerializer serialize Should produce serialized dump 1`] = `"{"children":[{"$":"UChild_1","D":{"some_data":true}},{"$":"UChild_2","D":{}},{"$":"UChild_3","D":{}}],"$":"URoot","D":{"some_data":true}}"`;
exports[`IsolateSerializer serialize Should produce serialized dump 1`] = `"{"C":[{"$":"UChild_1","D":{"some_data":true}},{"$":"UChild_2","D":{}},{"$":"UChild_3","D":{}}],"$":"URoot","D":{"some_data":true}}"`;

2 comments on commit 7ab22d3

@vercel
Copy link

@vercel vercel bot commented on 7ab22d3 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

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

@vercel
Copy link

@vercel vercel bot commented on 7ab22d3 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.vercel.app
vest-website.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-next-ealush.vercel.app

Please sign in to comment.