-
-
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.
minor(vestjs-utils): Support async isolate behavior (#1102)
- Loading branch information
Showing
3 changed files
with
142 additions
and
2 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
56 changes: 56 additions & 0 deletions
56
packages/vestjs-runtime/src/Isolate/__tests__/__snapshots__/asyncIsolate.test.ts.snap
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,56 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`AsyncIsolate It should resolve async isolate into the parent 2`] = ` | ||
{ | ||
"$type": "URoot", | ||
"allowReorder": undefined, | ||
"children": [ | ||
{ | ||
"$type": "UChild_1", | ||
"allowReorder": undefined, | ||
"children": [ | ||
{ | ||
"$type": "UGrandChild_1", | ||
"allowReorder": undefined, | ||
"children": null, | ||
"data": {}, | ||
"key": null, | ||
"keys": null, | ||
"output": undefined, | ||
"parent": [Circular], | ||
}, | ||
{ | ||
"$type": "UGrandChild_2", | ||
"allowReorder": undefined, | ||
"children": null, | ||
"data": {}, | ||
"key": null, | ||
"keys": null, | ||
"output": undefined, | ||
"parent": [Circular], | ||
}, | ||
{ | ||
"$type": "UGrandChild_3", | ||
"allowReorder": undefined, | ||
"children": null, | ||
"data": {}, | ||
"key": null, | ||
"keys": null, | ||
"output": undefined, | ||
"parent": [Circular], | ||
}, | ||
], | ||
"data": {}, | ||
"key": null, | ||
"keys": null, | ||
"output": undefined, | ||
"parent": [Circular], | ||
}, | ||
], | ||
"data": {}, | ||
"key": null, | ||
"keys": null, | ||
"output": Promise {}, | ||
"parent": null, | ||
} | ||
`; |
68 changes: 68 additions & 0 deletions
68
packages/vestjs-runtime/src/Isolate/__tests__/asyncIsolate.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,68 @@ | ||
import { CB } from 'vest-utils'; | ||
import wait from 'wait'; | ||
|
||
import { Isolate, TIsolate } from 'Isolate'; | ||
import { VestRuntime } from 'vestjs-runtime'; | ||
|
||
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", | ||
"allowReorder": undefined, | ||
"children": null, | ||
"data": {}, | ||
"key": null, | ||
"keys": null, | ||
"output": Promise {}, | ||
"parent": null, | ||
} | ||
`); | ||
await wait(10); | ||
expect(root?.children?.[0]?.$type).toBe('UChild_1'); | ||
expect(root?.children?.[0].parent).toBe(root); | ||
expect(root?.children?.[0]?.children?.[0]?.$type).toBe('UGrandChild_1'); | ||
expect(root?.children?.[0]?.children?.[0].parent).toBe( | ||
root?.children?.[0] | ||
); | ||
expect(root?.children?.[0]?.children?.[1]?.$type).toBe('UGrandChild_2'); | ||
expect(root?.children?.[0]?.children?.[1].parent).toBe( | ||
root?.children?.[0] | ||
); | ||
expect(root?.children?.[0]?.children?.[2]?.$type).toBe('UGrandChild_3'); | ||
expect(root?.children?.[0]?.children?.[2].parent).toBe( | ||
root?.children?.[0] | ||
); | ||
expect(root).toMatchSnapshot(); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
function withRunTime<T>(fn: CB<T>) { | ||
return VestRuntime.Run(VestRuntime.createRef({}), () => { | ||
return fn(); | ||
}); | ||
} | ||
|
||
async function genChildren() { | ||
await wait(10); | ||
// Create first child isolate | ||
return withRunTime(() => | ||
Isolate.create('UChild_1', () => { | ||
// Create three grandchildren | ||
Isolate.create('UGrandChild_1', () => {}); | ||
Isolate.create('UGrandChild_2', () => {}); | ||
Isolate.create('UGrandChild_3', () => {}); | ||
}) | ||
); | ||
} |
289acc4
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-next-ealush.vercel.app
vest-website.vercel.app
vest-next.vercel.app
vest-next-git-latest-ealush.vercel.app