Skip to content

Commit

Permalink
test(vestjs-runtime): Isolate Base Behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jun 3, 2023
1 parent 0a4c295 commit b427da2
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/n4s/src/exports/schema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { enforce } from 'n4s';
import { optional } from 'optional';


import { EnforceCustomMatcher } from 'enforceUtilityTypes';
import { isArrayOf } from 'isArrayOf';
import { loose } from 'loose';
import { optional } from 'optional';
import { shape } from 'shape';

export { partial } from 'partial';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useIsOptionalFiedApplied } from 'optional';

import { IsolateTest } from 'IsolateTest';
import { useIsExcluded } from 'exclusive';
import { useShouldSkipBasedOnMode } from 'mode';
import { useWithinActiveOmitWhen } from 'omitWhen';
import { useIsOptionalFiedApplied } from 'optional';
import { useIsExcludedIndividually } from 'skipWhen';

export function useVerifyTestRun(
Expand Down
2 changes: 1 addition & 1 deletion packages/vest/src/suite/getTypedMethods.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// import { optional, skipWhen, omitWhen, IsolateTest, group } from 'vest';
import { optional } from 'optional';
import { CB } from 'vest-utils';
import { Isolate, IsolateKey } from 'vestjs-runtime';

Expand All @@ -10,7 +11,6 @@ import { FieldExclusion, GroupExclusion, only, skip } from 'exclusive';
import { group } from 'group';
import { include } from 'include';
import { omitWhen } from 'omitWhen';
import { optional } from 'optional';
import { skipWhen } from 'skipWhen';
import { test } from 'test';
import { TestMemo } from 'test.memo';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useIsOptionalFiedApplied } from 'optional';
import { VestRuntime } from 'vestjs-runtime';

import type { IsolateSuite } from 'IsolateSuite';
Expand All @@ -12,7 +13,6 @@ import {
} from 'hasFailuresByTestObjects';
import { nonMatchingFieldName } from 'matchingFieldName';
import { nonMatchingGroupName } from 'matchingGroupName';
import { useIsOptionalFiedApplied } from 'optional';

export function useShouldAddValidProperty(fieldName?: TFieldName): boolean {
// Is the field optional, and the optional condition is applied
Expand Down
2 changes: 1 addition & 1 deletion packages/vestjs-runtime/src/Isolate/Isolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Isolate<_D = any> {
children: Isolate[] | null = [];
keys: Record<string, Isolate> = {};
parent: Isolate | null = null;
output?: any;
output: any;
key: IsolateKey = null;
allowReorder = false;
type = Symbol('Isolate');
Expand Down
92 changes: 92 additions & 0 deletions packages/vestjs-runtime/src/Isolate/__tests__/Isolate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Isolate } from 'Isolate';
import { StateRefType, useAvailableRoot } from 'VestRuntime';
import { VestRuntime } from 'vestjs-runtime';

describe('Isolate', () => {
let stateRef: StateRefType;

beforeEach(() => {
stateRef = VestRuntime.createRef({});
});

describe('Isolate.create', () => {
it('should return an instance of Isolate', () => {
const isolate = withRunTime(() => {
return Isolate.create(() => {});
});
expect(isolate).toBeInstanceOf(Isolate);
});

it('Should run the passed callback', () => {
const spy = jest.fn();
withRunTime(() => {
Isolate.create(spy);
});
expect(spy).toHaveBeenCalled();
});

it('Should store the callback result in the output property', () => {
const isolate = withRunTime(() => {
return Isolate.create(() => {
return 'foo';
});
});
expect(isolate.output).toBe('foo');
});

describe('When there is no parent', () => {
it('Parent should be null', () => {
const isolate = withRunTime(() => {
return Isolate.create(() => {});
});
expect(isolate.parent).toBeNull();
});

it('Should set the history root to the current isolate', () => {
const isolate = withRunTime(() => {
const isolate = Isolate.create(() => {});

expect(useAvailableRoot()).toBe(isolate);

return isolate;
});
// Just verifying that we did not throw and catch inside the runtime
expect(isolate).toBeDefined();
});
});

describe('When there is a parent', () => {
it('Should add the isolate to the parent children', () => {
const [parent, children] = withRunTime(() => {
const children = [] as Isolate[];
const parent = Isolate.create(() => {
children.push(Isolate.create(() => {}));
children.push(Isolate.create(() => {}));
children.push(Isolate.create(() => {}));
children.push(Isolate.create(() => {}));
});
return [parent, children];
});
expect(parent.children).toEqual(children);
});

it('Should set the parent property', () => {
const [parent, child] = withRunTime(() => {
let child = {} as Isolate;
const parent = Isolate.create(() => {
child = Isolate.create(() => {});
});

return [parent, child];
});
expect(child.parent).toBe(parent);
});
});
});

function withRunTime<T>(fn: () => T) {
return VestRuntime.Run(stateRef, () => {
return fn();
});
}
});
2 changes: 1 addition & 1 deletion packages/vestjs-runtime/src/VestRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type CTXType = StateRefType & {
stateRef: StateRefType;
};

type StateRefType = {
export type StateRefType = {
historyRoot: TinyState<Isolate | null>;
Bus: BusType;
appData: Record<string, any>;
Expand Down
3 changes: 2 additions & 1 deletion 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 b427da2

@vercel
Copy link

@vercel vercel bot commented on b427da2 Jun 3, 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
vestjs.dev
vest-git-latest-ealush.vercel.app
www.vestjs.dev
vest.vercel.app

@vercel
Copy link

@vercel vercel bot commented on b427da2 Jun 3, 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

Please sign in to comment.