Skip to content

Commit

Permalink
patch(vest): minify serialized values
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Dec 1, 2023
1 parent 3765ad9 commit 91661a6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
42 changes: 40 additions & 2 deletions packages/vest/src/exports/SuiteSerializer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { assign } from 'vest-utils';
import { IsolateSerializer } from 'vestjs-runtime';

import { CommonStates } from 'CommonStateMachine';
import { TIsolateSuite } from 'IsolateSuite';
import { IsolateTestPayload } from 'IsolateTest';
import { TestStatus } from 'IsolateTestStateMachine';
import { TFieldName, TGroupName } from 'SuiteResultTypes';
import { Suite } from 'SuiteTypes';
import { VestIsolateType } from 'VestIsolateType';
import { IsolateFocusedPayload } from 'focused';

export class SuiteSerializer {
Expand Down Expand Up @@ -34,7 +37,7 @@ const testMiniMap: Record<keyof IsolateTestPayload, string> = {
asyncTest: '_at', // asyncTest is not serialized
fieldName: 'fN',
groupName: 'gN',
message: 'msg',
message: 'ms',
severity: 'sv',
status: 'st',
testFn: '_tf', // testFn is not serialized
Expand All @@ -46,8 +49,43 @@ const focusMiniMap: Record<keyof IsolateFocusedPayload, string> = {
matchAll: 'mA',
};

const MiniMap = {
const MiniMap: MiniMap = {
keys: {
data: assign({}, testMiniMap, focusMiniMap),
},
values: {
status: {
CANCELED: 'C',
DONE: 'D',
FAILED: 'F',
INITIAL: 'I',
OMITTED: 'O',
PASSING: 'P',
PENDING: 'PE',
SKIPPED: 'S',
UNTESTED: 'U',
WARNING: 'W',
},
$type: {
Each: 'E',
Focused: 'F',
Group: 'G',
OmitWhen: 'OW',
SkipWhen: 'SW',
Suite: 'S',
Test: 'T',
},
},
};

type MiniMap = {
keys: {
data: Record<keyof IsolateTestPayload, string> &
Record<keyof IsolateFocusedPayload, string>;
};
values: {
status: Record<keyof typeof TestStatus, string> &
Record<keyof typeof CommonStates, string>;
$type: Record<keyof typeof VestIsolateType, string>;
};
};
31 changes: 30 additions & 1 deletion packages/vest/src/exports/__tests__/SuiteSerializer.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SuiteSerializer } from 'SuiteSerializer';
import { parse } from 'parser';
import * as vest from 'vest';

describe('SuiteSerializer', () => {
Expand Down Expand Up @@ -38,10 +39,38 @@ it('Should minify test payload', () => {

expect(parsed['C'][0]['D']).toBeDefined();
expect(parsed['C'][0]['D']['fN']).toBe('field_1');
expect(parsed['C'][0]['D']['msg']).toBe('field_1_message');
expect(parsed['C'][0]['D']['ms']).toBe('field_1_message');
expect(parsed['C'][0]['D']['sv']).toBe('error');
});

it('Should minify statuses', () => {
const suite = vest.create('suite_serialize_test', () => {
vest.test('field_1', 'field_1_message', () => false);
});

suite();
const serialized = SuiteSerializer.serialize(suite);

const parsed = JSON.parse(serialized);

expect(parsed['S']).toBe('D');
expect(parsed['C'][0]['S']).toBe('F');
});

it('Should minify isolate types', () => {
const suite = vest.create('suite_serialize_test', () => {
vest.test('field_1', 'field_1_message', () => false);
});

suite();
const serialized = SuiteSerializer.serialize(suite);

const parsed = JSON.parse(serialized);

expect(parsed['$']).toBe('S');
expect(parsed['C'][0]['$']).toBe('T');
});

describe('suite.resume', () => {
it('Should resume a suite from a serialized dump', () => {
const suite = vest.create(() => {
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`] = `"{"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"}"`;
exports[`SuiteSerializer Should produce a valid serialized dump 1`] = `"{"C":[{"D":{"fM":0,"m":["field_1"],"mA":false},"$":"F","S":"D"},{"D":{"sv":"error","fN":"field_1","ms":"field_1_message"},"$":"T","S":"F"},{"D":{"sv":"error","fN":"field_2","ms":"field_2_message"},"$":"T","S":"S"},{"C":[{"D":{"sv":"error","fN":"field_3","gN":"group_1","ms":"field_3_message_1"},"$":"T","S":"S"},{"D":{"sv":"error","fN":"field_3","gN":"group_1","ms":"field_3_message_2"},"$":"T","S":"S"},{"D":{"sv":"error","fN":"field_4","gN":"group_1","ms":"field_4_message"},"$":"T","S":"S"}],"$":"G","S":"D"},{"C":[{"D":{"sv":"error","fN":"field_5","ms":"field_5_message"},"$":"T","S":"S"}],"$":"SW","S":"D"}],"D":{"optional":{}},"$":"S","S":"D"}"`;

2 comments on commit 91661a6

@vercel
Copy link

@vercel vercel bot commented on 91661a6 Dec 1, 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-website.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-next.vercel.app
vest-next-ealush.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 91661a6 Dec 1, 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
www.vestjs.dev
vestjs.dev

Please sign in to comment.