@@ -48,7 +48,7 @@ test("callstack", ()=>{
4848} )
4949
5050test ( "callstack async" , async ( ) => {
51- const amountOfParallels = 2
51+ const amountOfParallels = 10
5252 //const log = jest.fn((...args:any[])=>console.log("async",...args))
5353 const log = jest . fn ( )
5454 const track = createTrack ( log )
@@ -88,6 +88,7 @@ function delay(ms:number){return new Promise(r=>setTimeout(r,ms))}
8888
8989test ( "callstack recursive sync" , ( ) => {
9090 //const log = jest.fn((...args:any[])=>console.log(...args))
91+ const depth = 100
9192 const log = jest . fn ( )
9293 const track = createTrack ( log )
9394
@@ -96,78 +97,11 @@ test("callstack recursive sync", ()=>{
9697 return 1 + myRecFunc ( n - 1 )
9798 } ) )
9899
99- const actRes = myRecFunc ( 3 )
100- const expRes = 1 + 1 + 1
100+ const actRes = myRecFunc ( depth )
101+ const expRes = depth
101102 expect ( actRes ) . toBe ( expRes )
102- expect ( myRecFunc ) . toHaveBeenCalledTimes ( 3 )
103- expect ( log ) . toHaveBeenCalledTimes ( ( 3 ) * 2 )
103+ expect ( myRecFunc ) . toHaveBeenCalledTimes ( depth )
104+ expect ( log ) . toHaveBeenCalledTimes ( ( depth ) * 2 )
104105 expect ( log ) . toHaveBeenNthCalledWith ( 1 , "onTry" , "myRecFunc" )
105106 expect ( log ) . toHaveBeenNthCalledWith ( 2 , "onTry" , "myRecFunc/myRecFunc" )
106107} )
107-
108- // test.skip('async hooks',async ()=>{
109- // const callStack = new AsyncLocalStorage<{name:string}[]>()
110- // callStack.enterWith([{name:"parent"}])
111- // await delay(100)
112- // expect(callStack.getStore()).toEqual([{name:"parent"}])
113- // callStack.enterWith([{name:"parent"}, {name:'child'}])
114- // await delay(100)
115- // expect(callStack.getStore()).toEqual([{name:"parent"},{name:"child"}])
116- // await delay(100)
117-
118-
119- // async function myAsyncFunc(){
120- // await delay(500)
121- // expect(callStack.getStore()).toEqual([{name:"parent"},{name:"child"}])
122- // callStack.enterWith([...callStack.getStore()!, {name:"myAsyncFunc"}])
123- // await delay(1000)
124- // expect(callStack.getStore()).toEqual([{name:"parent"},{name:"child"}, {name:"myAsyncFunc"}])
125- // }
126-
127- // async function myAsyncFunc2(){
128- // await delay(1000)
129- // expect(callStack.getStore()).toEqual([{name:"parent"},{name:"child"}])
130- // callStack.enterWith([...callStack.getStore()!, {name:"myAsyncFunc2"}])
131- // await delay(1000)
132- // expect(callStack.getStore()).toEqual([{name:"parent"},{name:"child"}, {name:"myAsyncFunc2"}])
133- // }
134-
135-
136- // await Promise.allSettled([myAsyncFunc(), myAsyncFunc2()])
137-
138- // expect(callStack.getStore()).toEqual([{name:"parent"},{name:"child"}])
139-
140-
141- // })
142-
143- // test.skip('async hooks array',async ()=>{
144- // const callStack = new AsyncLocalStorage<string[]>()
145- // callStack.enterWith(["parent"])
146- // await delay(100)
147- // expect(callStack.getStore()).toEqual(["parent"])
148- // await delay(100)
149-
150-
151- // async function myAsyncFunc(n: number){
152- // const actionName = "myAsyncFunc"+n
153- // //await delay(0)
154- // const storeBeforeAwait = callStack.getStore()!
155- // //expect(storeBeforeAwait).toEqual(["parent"])
156- // callStack.enterWith([...storeBeforeAwait, actionName])
157-
158- // await delay(Math.random()*1000)
159-
160- // const storeAfterAwait = callStack.getStore()!
161- // expect(storeAfterAwait).toEqual([...storeBeforeAwait,actionName])
162- // const newStack = [...storeAfterAwait]
163- // newStack.pop()
164- // callStack.enterWith(newStack)
165- // }
166-
167-
168- // await Promise.all(new Array(2).fill(0).map((_,i)=>myAsyncFunc(i)))
169-
170- // expect(callStack.getStore()).toEqual(["parent"])
171-
172-
173- // })
0 commit comments