Skip to content

Commit

Permalink
patch(vestjs-runtime): Initialize isolate with status
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 11, 2023
1 parent e45eec1 commit 12f83b8
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 58 deletions.
38 changes: 19 additions & 19 deletions packages/vest/src/core/__tests__/serializedDump.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
export const dump = {
children: [
{
children: null,
$type: 'Test',
children: null,
data: {
severity: 'error',
status: 'FAILED',
fieldName: 't1',
},
key: null,
status: 'FAILED',
},
{
children: [
{
children: null,
$type: 'Test',
children: null,
data: {
severity: 'error',
status: 'FAILED',
fieldName: 't2',
groupName: 'g1',
message: 't2 message',
severity: 'error',
},
key: null,
status: 'FAILED',
},
{
children: null,
$type: 'Test',
children: null,
data: {
severity: 'error',
status: 'PASSING',
fieldName: 't3',
groupName: 'g1',
message: 't3 message',
severity: 'error',
},
key: null,
status: 'PASSING',
},
{
children: null,
$type: 'Test',
children: null,
data: {
severity: 'warning',
status: 'WARNING',
fieldName: 't4',
groupName: 'g1',
},
key: null,
status: 'WARNING',
},
],
$type: 'Group',
Expand All @@ -54,8 +54,8 @@ export const dump = {
{
children: [
{
children: null,
$type: 'Focused',
children: null,
data: {
focusMode: 1,
match: [],
Expand All @@ -64,44 +64,44 @@ export const dump = {
key: null,
},
{
children: null,
$type: 'Test',
children: null,
data: {
severity: 'error',
status: 'SKIPPED',
fieldName: 't5',
},
key: 'key1',
status: 'SKIPPED',
},
],
$type: 'Group',
key: null,
},
{
$type: 'Each',
allowReorder: true,
children: [
{
children: null,
$type: 'Test',
children: null,
data: {
severity: 'error',
status: 'FAILED',
fieldName: 't6',
},
key: 'a',
status: 'FAILED',
},
{
children: null,
$type: 'Test',
children: null,
data: {
severity: 'error',
status: 'FAILED',
fieldName: 't6',
},
key: 'b',
status: 'FAILED',
},
],
$type: 'Each',
allowReorder: true,
key: null,
},
],
Expand Down
15 changes: 6 additions & 9 deletions packages/vest/src/core/isolate/IsolateTest/VestTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class VestTest {
}

static statusEquals(test: TIsolateTest, status: TestStatus): boolean {
return VestTest.getData(test).status === status;
return test.status === status;
}

// Mutate
Expand Down Expand Up @@ -158,13 +158,10 @@ export class VestTest {
status: TestStateMachineAction,
payload?: any
): void {
VestTest.setData(test, current => ({
...current,
status: TestStateMachine.staticTransition(
current.status,
status,
payload
),
}));
test.status = TestStateMachine.staticTransition(
test.status,
status,
payload
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ exports[`IsolateTest TestObject constructor 1`] = `
"fieldName": "unicycle",
"message": "I am Root.",
"severity": "error",
"status": "UNTESTED",
"testFn": [MockFunction],
"type": "Test",
},
"key": null,
"keys": {},
"output": null,
"parent": null,
"status": "UNTESTED",
}
`;

Expand All @@ -29,13 +29,13 @@ exports[`IsolateTest testObject.warn Should mark the test as warning 1`] = `
"fieldName": "unicycle",
"message": "I am Root.",
"severity": "warning",
"status": "UNTESTED",
"testFn": [MockFunction],
"type": "Test",
},
"key": null,
"keys": {},
"output": null,
"parent": null,
"status": "UNTESTED",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ exports[`Test Vest's \`test\` function test params creates a test without a key
"fieldName": "field_name",
"message": "failure message",
"severity": "error",
"status": "PASSING",
"testFn": [Function],
},
"key": null,
Expand Down Expand Up @@ -65,6 +64,7 @@ exports[`Test Vest's \`test\` function test params creates a test without a key
},
"parent": null,
},
"status": "PASSING",
}
`;

Expand All @@ -77,7 +77,6 @@ exports[`Test Vest's \`test\` function test params creates a test without a mess
"abortController": AbortController {},
"fieldName": "field_name",
"severity": "error",
"status": "PASSING",
"testFn": [Function],
},
"key": "keyboardcat",
Expand Down Expand Up @@ -134,6 +133,7 @@ exports[`Test Vest's \`test\` function test params creates a test without a mess
},
"parent": null,
},
"status": "PASSING",
}
`;

Expand All @@ -146,7 +146,6 @@ exports[`Test Vest's \`test\` function test params creates a test without a mess
"abortController": AbortController {},
"fieldName": "field_name",
"severity": "error",
"status": "PASSING",
"testFn": [Function],
},
"key": null,
Expand Down Expand Up @@ -201,5 +200,6 @@ exports[`Test Vest's \`test\` function test params creates a test without a mess
},
"parent": null,
},
"status": "PASSING",
}
`;
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","status":"PASSING","abortController":{},"fieldName":"field_name","message":"failure message"},"k":"keyboardcat"}"`
`"{"$":"Test","D":{"severity":"error","abortController":{},"fieldName":"field_name","message":"failure message"},"S":"PASSING","k":"keyboardcat"}"`
);
});

Expand Down
23 changes: 6 additions & 17 deletions packages/vest/src/core/test/testLevelFlowControl/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
isPromise,
isStringValue,
BusType,
text,
deferThrow,
} from 'vest-utils';
import { Bus, VestRuntime } from 'vestjs-runtime';

import { Events } from 'BusEvents';
import { isPromise, isStringValue, text, deferThrow } from 'vest-utils';
import { VestRuntime } from 'vestjs-runtime';

import { ErrorStrings } from 'ErrorStrings';
import { TIsolateTest } from 'IsolateTest';
import { SuiteContext } from 'SuiteContext';
Expand Down Expand Up @@ -63,8 +56,6 @@ function runSyncTest(testObject: TIsolateTest): TestResult {
* runs test, if async - adds to pending array
*/
function useRunTest(testObject: TIsolateTest): Promise<void> | undefined {
const VestBus = Bus.useBus();

// Run test callback.
// If a promise is returned, set as async and
// Move to pending list.
Expand All @@ -77,7 +68,7 @@ function useRunTest(testObject: TIsolateTest): Promise<void> | undefined {
return useRunAsyncTest(testObject);
}

onTestCompleted(VestBus, testObject);
onTestCompleted(testObject);
} catch (e) {
// Probably unreachable. If we get here, it means that
// something was really wrong and should be reported.
Expand All @@ -100,10 +91,8 @@ function useRunAsyncTest(testObject: TIsolateTest): Promise<void> | undefined {
if (!isPromise(asyncTest)) return;
// VestTest.setPending(testObject);

const VestBus = Bus.useBus();

const done = VestRuntime.persist(() => {
onTestCompleted(VestBus, testObject);
onTestCompleted(testObject);
});
const fail = VestRuntime.persist((rejectionMessage?: string) => {
if (VestTest.isCanceled(testObject)) {
Expand All @@ -121,7 +110,7 @@ function useRunAsyncTest(testObject: TIsolateTest): Promise<void> | undefined {
return asyncTest.then(done, fail);
}

function onTestCompleted(VestBus: BusType, testObject: TIsolateTest) {
function onTestCompleted(testObject: TIsolateTest) {
// Attempts passing if the test is not already failed.
// or is not canceled/omitted.
VestTest.pass(testObject);
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}},{"$":"Test","D":{"severity":"error","status":"FAILED","abortController":{},"fieldName":"field_1","message":"field_1_message"}},{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_2","message":"field_2_message"}},{"children":[{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_3","groupName":"group_1","message":"field_3_message_1"}},{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_3","groupName":"group_1","message":"field_3_message_2"}},{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_4","groupName":"group_1","message":"field_4_message"}}],"$":"Group","D":{}},{"children":[{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_5","message":"field_5_message"}}],"$":"SkipWhen","D":{}}],"$":"Suite","D":{"optional":{}}}"`;
exports[`SuiteSerializer Should produce a valid serialized dump 1`] = `"{"children":[{"$":"Focused","D":{"focusMode":0,"match":["field_1"],"matchAll":false}},{"$":"Test","D":{"severity":"error","abortController":{},"fieldName":"field_1","message":"field_1_message"},"S":"FAILED"},{"$":"Test","D":{"severity":"error","abortController":{},"fieldName":"field_2","message":"field_2_message"},"S":"SKIPPED"},{"children":[{"$":"Test","D":{"severity":"error","abortController":{},"fieldName":"field_3","groupName":"group_1","message":"field_3_message_1"},"S":"SKIPPED"},{"$":"Test","D":{"severity":"error","abortController":{},"fieldName":"field_3","groupName":"group_1","message":"field_3_message_2"},"S":"SKIPPED"},{"$":"Test","D":{"severity":"error","abortController":{},"fieldName":"field_4","groupName":"group_1","message":"field_4_message"},"S":"SKIPPED"}],"$":"Group","D":{}},{"children":[{"$":"Test","D":{"severity":"error","abortController":{},"fieldName":"field_5","message":"field_5_message"},"S":"SKIPPED"}],"$":"SkipWhen","D":{}}],"$":"Suite","D":{"optional":{}}}"`;
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ exports[`staticSuite dump should output a dump of the suite 1`] = `
"abortController": AbortController {},
"fieldName": "t1",
"severity": "error",
"status": "FAILED",
"testFn": [Function],
},
"key": null,
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "FAILED",
},
{
"$type": "Test",
Expand All @@ -29,13 +29,13 @@ exports[`staticSuite dump should output a dump of the suite 1`] = `
"abortController": AbortController {},
"fieldName": "t2",
"severity": "error",
"status": "FAILED",
"testFn": [Function],
},
"key": null,
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "FAILED",
},
{
"$type": "Group",
Expand All @@ -50,13 +50,13 @@ exports[`staticSuite dump should output a dump of the suite 1`] = `
"fieldName": "t1",
"groupName": "g1",
"severity": "error",
"status": "SKIPPED",
"testFn": [Function],
},
"key": null,
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "SKIPPED",
},
{
"$type": "Test",
Expand All @@ -67,13 +67,13 @@ exports[`staticSuite dump should output a dump of the suite 1`] = `
"fieldName": "t3",
"groupName": "g1",
"severity": "error",
"status": "FAILED",
"testFn": [Function],
},
"key": null,
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "FAILED",
},
],
"data": {},
Expand Down
4 changes: 3 additions & 1 deletion packages/vestjs-runtime/src/Isolate/Isolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ function baseIsolate(
payload: Maybe<IsolatePayload> = undefined,
key: IsolateKey = null
): TIsolate {
const { allowReorder, ...data } = payload ?? {};
const { allowReorder, status, ...data } = payload ?? {};
return {
[IsolateKeys.AllowReorder]: allowReorder,
[IsolateKeys.Keys]: null,
[IsolateKeys.Parent]: null,
[IsolateKeys.Type]: type,
[IsolateKeys.Data]: data as IsolateData,
...(status && { [IsolateKeys.Status]: status }),
children: null,
key,
output: null,
Expand All @@ -132,4 +133,5 @@ type IsolateData = Record<string, any>;
type IsolatePayload = IsolateData & IsolateFeatures;
type IsolateFeatures = {
[IsolateKeys.AllowReorder]?: boolean;
[IsolateKeys.Status]?: string;
};
4 changes: 3 additions & 1 deletion packages/vestjs-runtime/src/exports/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { TIsolate } from 'Isolate';
import { IsolateKeys } from 'IsolateKeys';

export function genTestIsolate(data: Record<string, any> = {}): TIsolate {
export function genTestIsolate(payload: Record<string, any> = {}): TIsolate {
const { status, ...data } = payload;
return {
children: [],
data,
Expand All @@ -10,5 +11,6 @@ export function genTestIsolate(data: Record<string, any> = {}): TIsolate {
output: null,
parent: null,
[IsolateKeys.Type]: 'UnitTest',
...(status && { status }),
};
}

2 comments on commit 12f83b8

@vercel
Copy link

@vercel vercel bot commented on 12f83b8 Nov 11, 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-git-latest-ealush.vercel.app
vest.vercel.app
www.vestjs.dev
vestjs.dev

@vercel
Copy link

@vercel vercel bot commented on 12f83b8 Nov 11, 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.vercel.app
vest-next-ealush.vercel.app
vest-next-git-latest-ealush.vercel.app

Please sign in to comment.