Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
2e978933
Commit
2e978933
authored
Nov 11, 2025
by
Janka Uryga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more tests for fast-set-immediate
parent
04f4f679
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
192 additions
and
1 deletion
+192
-1
fast-set-immediate.external.test.ts
...src/server/app-render/fast-set-immediate.external.test.ts
+192
-1
No files found.
packages/next/src/server/app-render/fast-set-immediate.external.test.ts
View file @
2e978933
import
{
AsyncLocalStorage
}
from
'node:async_hooks'
import
{
createPromiseWithResolvers
}
from
'../../shared/lib/promise-with-resolvers'
import
{
createPromiseWithResolvers
}
from
'../../shared/lib/promise-with-resolvers'
import
{
import
{
install
,
install
,
...
@@ -6,7 +7,7 @@ import {
...
@@ -6,7 +7,7 @@ import {
install
()
install
()
it
(
'runs immediates after each task'
,
async
()
=>
{
function
createLogger
()
{
const
logs
:
string
[]
=
[]
const
logs
:
string
[]
=
[]
const
log
=
(...
args
:
any
[])
=>
{
const
log
=
(...
args
:
any
[])
=>
{
...
@@ -21,7 +22,11 @@ it('runs immediates after each task', async () => {
...
@@ -21,7 +22,11 @@ it('runs immediates after each task', async () => {
logs
.
push
(
logLine
)
logs
.
push
(
logLine
)
process
.
stdout
.
write
(
logLine
+
'
\
n'
)
process
.
stdout
.
write
(
logLine
+
'
\
n'
)
}
}
return
{
logs
,
log
}
}
it
(
'runs immediates after each task'
,
async
()
=>
{
const
{
log
,
logs
}
=
createLogger
()
const
done
=
createPromiseWithResolvers
<
void
>
()
const
done
=
createPromiseWithResolvers
<
void
>
()
setTimeout
(()
=>
{
setTimeout
(()
=>
{
...
@@ -104,3 +109,189 @@ it('runs immediates after each task', async () => {
...
@@ -104,3 +109,189 @@ it('runs immediates after each task', async () => {
'timeout 3'
,
'timeout 3'
,
])
])
})
})
it
(
'only affects the task it is called in'
,
async
()
=>
{
const
{
log
,
logs
}
=
createLogger
()
const
done
=
createPromiseWithResolvers
<
void
>
()
setTimeout
(()
=>
{
runPendingImmediatesAfterCurrentTask
()
log
(
'timeout 1'
)
setImmediate
(()
=>
{
log
(
'timeout 1 -> immediate 1 (fast)'
)
setImmediate
(()
=>
{
log
(
'timeout 1 -> immediate 1 (fast) -> immediate 1 (fast)'
)
})
})
})
setTimeout
(()
=>
{
log
(
'timeout 2'
)
setImmediate
(()
=>
{
log
(
'timeout 2 -> immediate 1 (slow)'
)
done
.
resolve
()
})
})
setTimeout
(()
=>
{
log
(
'timeout 3'
)
})
await
done
.
promise
expect
(
logs
).
toEqual
([
// ===================================
'timeout 1'
,
// ======================
'timeout 1 -> immediate 1 (fast)'
,
// ======================
'timeout 1 -> immediate 1 (fast) -> immediate 1 (fast)'
,
// ===================================
'timeout 2'
,
// ===================================
'timeout 3'
,
// ======================
'timeout 2 -> immediate 1 (slow)'
,
])
})
it
(
'propagates AsyncLocalStorage'
,
async
()
=>
{
const
{
log
,
logs
}
=
createLogger
()
const
done
=
createPromiseWithResolvers
<
void
>
()
const
Ctx
=
new
AsyncLocalStorage
<
string
>
()
setTimeout
(()
=>
{
runPendingImmediatesAfterCurrentTask
()
Ctx
.
run
(
'hello'
,
()
=>
{
log
(
`timeout 1 ::
${
Ctx
.
getStore
()}
`
)
setImmediate
(()
=>
{
log
(
`timeout 1 -> immediate 1 ::
${
Ctx
.
getStore
()}
`
)
setImmediate
(()
=>
{
log
(
`timeout 1 -> immediate 1 -> immediate 1 ::
${
Ctx
.
getStore
()}
`
)
})
})
})
})
setTimeout
(()
=>
{
log
(
'timeout 2'
)
done
.
resolve
()
})
await
done
.
promise
expect
(
logs
).
toEqual
([
// ===================================
'timeout 1 :: hello'
,
// ======================
'timeout 1 -> immediate 1 :: hello'
,
// ======================
'timeout 1 -> immediate 1 -> immediate 1 :: hello'
,
// ===================================
'timeout 2'
,
])
})
describe
(
'allows cancelling immediates'
,
()
=>
{
it
(
'synchronously'
,
async
()
=>
{
const
{
log
,
logs
}
=
createLogger
()
const
done
=
createPromiseWithResolvers
<
void
>
()
setTimeout
(()
=>
{
runPendingImmediatesAfterCurrentTask
()
log
(
'timeout 1'
)
setImmediate
(()
=>
{
log
(
'timeout 1 -> immediate 1'
)
})
const
immediate2
=
setImmediate
(()
=>
{
log
(
'timeout 1 -> immediate 2'
)
})
clearImmediate
(
immediate2
)
})
setTimeout
(()
=>
{
log
(
'timeout 2'
)
done
.
resolve
()
})
await
done
.
promise
expect
(
logs
).
toEqual
([
// ===================================
'timeout 1'
,
// ======================
'timeout 1 -> immediate 1'
,
// ===================================
'timeout 2'
,
])
})
it
(
'from a nextTick'
,
async
()
=>
{
const
{
log
,
logs
}
=
createLogger
()
const
done
=
createPromiseWithResolvers
<
void
>
()
setTimeout
(()
=>
{
runPendingImmediatesAfterCurrentTask
()
log
(
'timeout 1'
)
setImmediate
(()
=>
{
log
(
'timeout 1 -> immediate 1'
)
})
const
immediate2
=
setImmediate
(()
=>
{
log
(
'timeout 1 -> immediate 2'
)
})
process
.
nextTick
(()
=>
{
clearImmediate
(
immediate2
)
})
})
setTimeout
(()
=>
{
log
(
'timeout 2'
)
done
.
resolve
()
})
await
done
.
promise
expect
(
logs
).
toEqual
([
// ===================================
'timeout 1'
,
// ======================
'timeout 1 -> immediate 1'
,
// ===================================
'timeout 2'
,
])
})
it
(
'from another immediate'
,
async
()
=>
{
const
{
log
,
logs
}
=
createLogger
()
const
done
=
createPromiseWithResolvers
<
void
>
()
setTimeout
(()
=>
{
runPendingImmediatesAfterCurrentTask
()
log
(
'timeout 1'
)
setImmediate
(()
=>
{
log
(
'timeout 1 -> immediate 1'
)
clearImmediate
(
immediate2
)
})
const
immediate2
=
setImmediate
(()
=>
{
log
(
'timeout 1 -> immediate 2'
)
})
})
setTimeout
(()
=>
{
log
(
'timeout 2'
)
done
.
resolve
()
})
await
done
.
promise
expect
(
logs
).
toEqual
([
// ===================================
'timeout 1'
,
// ======================
'timeout 1 -> immediate 1'
,
// ===================================
'timeout 2'
,
])
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment