-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(vestjs-runtime): Isolate Base Behavior
- Loading branch information
Showing
8 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/vest/src/core/test/testLevelFlowControl/verifyTestRun.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/vestjs-runtime/src/Isolate/__tests__/Isolate.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
b427da2
There was a problem hiding this comment.
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
b427da2
There was a problem hiding this comment.
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