Skip to content

Commit

Permalink
patch(vestjs-runtime): set isolate status as pending
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 7, 2023
1 parent c9457e9 commit 7ca4a56
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports[`IsolateTest TestObject constructor 1`] = `
"keys": {},
"output": null,
"parent": null,
"status": "INITIAL",
}
`;

Expand Down Expand Up @@ -53,5 +54,6 @@ exports[`IsolateTest testObject.warn Should mark the test as warning 1`] = `
"keys": {},
"output": null,
"parent": null,
"status": "INITIAL",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ exports[`Test Vest's \`test\` function test params creates a test without a key
"warnings": [],
},
"parent": null,
"status": "DONE",
},
"status": "DONE",
}
`;

Expand Down Expand Up @@ -149,7 +151,9 @@ exports[`Test Vest's \`test\` function test params creates a test without a mess
"warnings": [],
},
"parent": null,
"status": "DONE",
},
"status": "DONE",
}
`;

Expand Down Expand Up @@ -224,6 +228,8 @@ exports[`Test Vest's \`test\` function test params creates a test without a mess
"warnings": [],
},
"parent": null,
"status": "DONE",
},
"status": "DONE",
}
`;
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","status":"PASSING","abortController":{},"fieldName":"field_name","message":"failure message"},"S":"DONE","k":"keyboardcat"}"`
);
});

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},"S":"DONE"},{"$":"Test","D":{"severity":"error","status":"FAILED","abortController":{},"fieldName":"field_1","message":"field_1_message"},"S":"DONE"},{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_2","message":"field_2_message"},"S":"DONE"},{"children":[{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_3","groupName":"group_1","message":"field_3_message_1"},"S":"DONE"},{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_3","groupName":"group_1","message":"field_3_message_2"},"S":"DONE"},{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_4","groupName":"group_1","message":"field_4_message"},"S":"DONE"}],"$":"Group","D":{},"S":"DONE"},{"children":[{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_5","message":"field_5_message"},"S":"DONE"}],"$":"SkipWhen","D":{},"S":"DONE"}],"$":"Suite","D":{"optional":{}},"S":"DONE"}"`;
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ exports[`staticSuite dump should output a dump of the suite 1`] = `
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "DONE",
},
{
"$type": "Test",
Expand All @@ -52,6 +53,7 @@ exports[`staticSuite dump should output a dump of the suite 1`] = `
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "DONE",
},
{
"$type": "Group",
Expand Down Expand Up @@ -81,6 +83,7 @@ exports[`staticSuite dump should output a dump of the suite 1`] = `
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "DONE",
},
{
"$type": "Test",
Expand All @@ -106,13 +109,15 @@ exports[`staticSuite dump should output a dump of the suite 1`] = `
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "DONE",
},
],
"data": {},
"key": null,
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "DONE",
},
],
"data": {
Expand Down Expand Up @@ -212,5 +217,6 @@ exports[`staticSuite dump should output a dump of the suite 1`] = `
"warnings": [],
},
"parent": null,
"status": "DONE",
}
`;
9 changes: 9 additions & 0 deletions packages/vestjs-runtime/src/Isolate/Isolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CB, Maybe, Nullable, isNotNullish, isPromise } from 'vest-utils';

import { IsolateKeys } from 'IsolateKeys';
import { IsolateMutator } from 'IsolateMutator';
import { IsolateStatus } from 'IsolateStatus';
import { Reconciler } from 'Reconciler';
import * as VestRuntime from 'VestRuntime';

Expand All @@ -13,6 +14,7 @@ export type TIsolate<P extends IsolatePayload = IsolatePayload> = {
[IsolateKeys.Type]: string;
[IsolateKeys.Keys]: Nullable<Record<string, TIsolate>>;
[IsolateKeys.Data]: DataOnly<P>;
[IsolateKeys.Status]: IsolateStatus;
children: Nullable<TIsolate[]>;
key: IsolateKey;
output: any;
Expand Down Expand Up @@ -85,11 +87,17 @@ function useRunAsNew<Callback extends CB = CB>(
const output = callback(current);

if (isPromise(output)) {
IsolateMutator.setPending(current);

output.then(iso => {
if (Isolate.isIsolate(iso)) {
IsolateMutator.addChild(current, iso);
}

IsolateMutator.setDone(current);
});
} else {
IsolateMutator.setDone(current);
}

return output;
Expand All @@ -112,6 +120,7 @@ function baseIsolate(
[IsolateKeys.Parent]: null,
[IsolateKeys.Type]: type,
[IsolateKeys.Data]: data as IsolateData,
[IsolateKeys.Status]: IsolateStatus.INITIAL,
children: null,
key,
output: null,
Expand Down
3 changes: 3 additions & 0 deletions packages/vestjs-runtime/src/Isolate/IsolateKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum IsolateKeys {
Parent = 'parent',
Data = 'data',
AllowReorder = 'allowReorder',
Status = 'status',
}

enum MinifiedKeys {
Expand All @@ -14,6 +15,7 @@ enum MinifiedKeys {
Parent = 'P',
Data = 'D',
AllowReorder = 'aR',
Status = 'S',
}

export const KeyToMinified = {
Expand All @@ -23,6 +25,7 @@ export const KeyToMinified = {
[IsolateKeys.Data]: MinifiedKeys.Data,
[IsolateKeys.Key]: MinifiedKeys.Key,
[IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,
[IsolateKeys.Status]: MinifiedKeys.Status,
};

// This const is an object that looks like this:
Expand Down
9 changes: 9 additions & 0 deletions packages/vestjs-runtime/src/Isolate/IsolateMutator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Nullable, invariant, isNullish } from 'vest-utils';

import { TIsolate } from 'Isolate';
import { IsolateStatus } from 'IsolateStatus';

export class IsolateMutator {
static setParent(isolate: TIsolate, parent: Nullable<TIsolate>): TIsolate {
Expand Down Expand Up @@ -50,4 +51,12 @@ export class IsolateMutator {
static setData(isolate: TIsolate, data: any): void {
isolate.data = data;
}

static setPending(isolate: TIsolate): void {
isolate.status = IsolateStatus.PENDING;
}

static setDone(isolate: TIsolate): void {
isolate.status = IsolateStatus.DONE;
}
}
5 changes: 5 additions & 0 deletions packages/vestjs-runtime/src/Isolate/IsolateStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum IsolateStatus {
PENDING = 'PENDING',
DONE = 'DONE',
INITIAL = 'INITIAL',
}
20 changes: 20 additions & 0 deletions packages/vestjs-runtime/src/Isolate/__tests__/Isolate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ describe('Isolate', () => {
expect(child.parent).toBe(parent);
});
});

test('Isolate status is INITIAL before running', () => {
const control = jest.fn();
withRunTime(() => {
return Isolate.create(IsolateType.Isolate, () => {
expect(useAvailableRoot().status).toBe('INITIAL');
control();
});
});

expect(control).toHaveBeenCalled();
});

test('Isolate status is DONE after running', () => {
const isolate = withRunTime(() => {
return Isolate.create(IsolateType.Isolate, () => {});
});

expect(isolate.status).toBe('DONE');
});
});

function withRunTime<T>(fn: CB<T>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports[`AsyncIsolate It should resolve async isolate into the parent 2`] = `
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "DONE",
},
{
"$type": "UGrandChild_2",
Expand All @@ -28,6 +29,7 @@ exports[`AsyncIsolate It should resolve async isolate into the parent 2`] = `
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "DONE",
},
{
"$type": "UGrandChild_3",
Expand All @@ -38,19 +40,36 @@ exports[`AsyncIsolate It should resolve async isolate into the parent 2`] = `
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "DONE",
},
],
"data": {},
"key": null,
"keys": null,
"output": undefined,
"parent": [Circular],
"status": "DONE",
},
],
"data": {},
"key": null,
"keys": null,
"output": Promise {},
"parent": null,
"status": "DONE",
}
`;

exports[`AsyncIsolate It should set the isolate state to pending 1`] = `
{
"$type": "URoot",
"allowReorder": undefined,
"children": null,
"data": {},
"key": null,
"keys": null,
"output": Promise {},
"parent": null,
"status": "PENDING",
}
`;
29 changes: 27 additions & 2 deletions packages/vestjs-runtime/src/Isolate/__tests__/asyncIsolate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ describe('AsyncIsolate', () => {
test('It should resolve async isolate into the parent', () => {
return new Promise<void>(async done => {
let root = {} as TIsolate;
const control = jest.fn();
withRunTime(() => {
// Create root isolate from which all others will be created
root = Isolate.create('URoot', genChildren);
});
expect(control).not.toHaveBeenCalled();
expect(root).toMatchInlineSnapshot(`
{
"$type": "URoot",
Expand All @@ -24,6 +22,7 @@ describe('AsyncIsolate', () => {
"keys": null,
"output": Promise {},
"parent": null,
"status": "PENDING",
}
`);
await wait(10);
Expand All @@ -46,6 +45,32 @@ describe('AsyncIsolate', () => {
done();
});
});

test('It should set the isolate state to pending', () => {
return new Promise<void>(done => {
let root = {} as TIsolate;
withRunTime(() => {
// Create root isolate from which all others will be created
root = Isolate.create('URoot', genChildren);
});
expect(root).toMatchSnapshot();
expect(root?.status).toBe('PENDING');
done();
});
});

it('should set the isolate state to done when complete', () => {
return new Promise<void>(async done => {
let root = {} as TIsolate;
withRunTime(() => {
// Create root isolate from which all others will be created
root = Isolate.create('URoot', genChildren);
});
await wait(10);
expect(root?.status).toBe('DONE');
done();
});
});
});

function withRunTime<T>(fn: CB<T>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@ describe('IsolateSerializer', () => {
"some_data": true,
},
"parent": [Circular],
"status": "DONE",
},
{
"$type": "UChild_2",
"data": {},
"parent": [Circular],
"status": "DONE",
},
{
"$type": "UChild_3",
"data": {},
"parent": [Circular],
"status": "DONE",
},
],
"data": {
"some_data": true,
},
"status": "DONE",
}
`);
});
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`] = `"{"children":[{"$":"UChild_1","D":{"some_data":true},"S":"DONE"},{"$":"UChild_2","D":{},"S":"DONE"},{"$":"UChild_3","D":{},"S":"DONE"}],"$":"URoot","D":{"some_data":true},"S":"DONE"}"`;
2 changes: 2 additions & 0 deletions packages/vestjs-runtime/src/exports/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TIsolate } from 'Isolate';
import { IsolateKeys } from 'IsolateKeys';
import { IsolateStatus } from 'IsolateStatus';

export function genTestIsolate(data: Record<string, any> = {}): TIsolate {
return {
Expand All @@ -9,6 +10,7 @@ export function genTestIsolate(data: Record<string, any> = {}): TIsolate {
keys: {},
output: null,
parent: null,
status: IsolateStatus.INITIAL,
[IsolateKeys.Type]: 'UnitTest',
};
}
1 change: 1 addition & 0 deletions packages/vestjs-runtime/src/vestjs-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { IsolateKey, TIsolate, Isolate } from 'Isolate';
export { IsolateStatus } from 'IsolateStatus';
export { Reconciler, IRecociler } from 'Reconciler';
export * as Walker from 'IsolateWalker';
export { RuntimeApi as VestRuntime } from 'VestRuntime';
Expand Down
1 change: 1 addition & 0 deletions packages/vestjs-runtime/tsconfig.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 comments on commit 7ca4a56

@vercel
Copy link

@vercel vercel bot commented on 7ca4a56 Nov 7, 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 7ca4a56 Nov 7, 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.