-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
72 additions
and
27 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
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
48 changes: 48 additions & 0 deletions
48
packages/vestjs-runtime/src/Isolate/__tests__/reconciliation.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,48 @@ | ||
import { CB } from 'vest-utils'; | ||
import { describe, it, expect, beforeEach, vi } from 'vitest'; | ||
|
||
import { TIsolate, Isolate } from 'Isolate'; | ||
import { StateRefType, useAvailableRoot } from 'VestRuntime'; | ||
import { IRecociler, IsolateMutator, VestRuntime } from 'vestjs-runtime'; | ||
|
||
describe('Reconciliation', () => { | ||
let stateRef: StateRefType; | ||
|
||
beforeEach(() => { | ||
stateRef = VestRuntime.createRef(testReconciler, () => null); | ||
}); | ||
|
||
it('Should return the current node if there is no history node', () => { | ||
let rootIsolate; | ||
const output = VestRuntime.Run(stateRef, () => { | ||
rootIsolate = Isolate.create(IsolateType.RunOne, () => {}); | ||
}); | ||
|
||
const [historyRoot] = stateRef.historyRoot(); | ||
|
||
expect(historyRoot).toBe(rootIsolate); | ||
}); | ||
|
||
it("should return the result of the reconciler's function when runs the second time", () => { | ||
const isolate1 = VestRuntime.Run(stateRef, () => { | ||
return Isolate.create(IsolateType.RunOne, () => ({ foo: 'bar' })); | ||
}); | ||
const isolate2 = VestRuntime.Run(stateRef, () => { | ||
return Isolate.create(IsolateType.RunTwo, () => ({ foo: 'baz' })); | ||
}); | ||
|
||
const [historyRoot] = stateRef.historyRoot(); | ||
|
||
expect(historyRoot).toBe(isolate2); | ||
}); | ||
}); | ||
|
||
enum IsolateType { | ||
RunOne = 'RunOne', | ||
RunTwo = 'RunTwo', | ||
} | ||
|
||
const testReconciler: IRecociler = ( | ||
currentNode: TIsolate, | ||
historyNode: TIsolate, | ||
): TIsolate => currentNode; |
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