-
-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test failing #1150
test failing #1150
Conversation
WalkthroughThe changes enhance the testing framework for the Changes
Sequence Diagram(s)sequenceDiagram
participant T as Test Suite
participant R as Runtime State
participant TE as Timer Engine
T->>TE: useFakeTimers()
T->>R: Initialize rundown with events
T->>TE: runAllTimers()
T->>R: Execute scheduled tasks
T->>TE: useRealTimers()
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- apps/server/src/stores/tests/runtimeState.test.ts (1 hunks)
Additional comments not posted (2)
apps/server/src/stores/__tests__/runtimeState.test.ts (2)
162-166
: LGTM! The setup and teardown for fake timers are correctly implemented.The use of
vi.useFakeTimers()
,vi.runAllTimers()
, andvi.useRealTimers()
ensures controlled time manipulation during the tests and reverts back to real timers afterward, maintaining test isolation.
167-167
: LGTM! Theruntime offset
test case has been correctly updated to handle asynchronous operations.The use of
async
ensures that any asynchronous operations within the test are properly awaited, improving test accuracy.
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.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (2)
packages/utils/src/test/withFlushTimers.test.ts (2)
1-1
: Consider adding a docstring or comment to explain the function.Adding a comment or docstring to describe the purpose and usage of the
withFlushTimers
function would improve readability and maintainability./** * Executes a function with fake timers and then reverts to real timers. * @param fn - The function to execute. * @param args - The arguments to pass to the function. * @returns The return value of the executed function. */
3-3
: Consider renamingret
to a more descriptive variable name.Using a more descriptive variable name instead of
ret
would improve code readability.const result = fn(...args);
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
packages/utils/index.ts
is excluded by none and included by none
Files selected for processing (2)
- apps/server/src/stores/tests/runtimeState.test.ts (2 hunks)
- packages/utils/src/test/withFlushTimers.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- apps/server/src/stores/tests/runtimeState.test.ts
Additional comments not posted (3)
packages/utils/src/test/withFlushTimers.test.ts (3)
4-4
: Ensurevi.runAllTimers()
is always called.To ensure that
vi.runAllTimers()
is always called, even iffn
throws an error, it should be placed inside afinally
block.
5-5
: Ensurevi.useRealTimers()
is always called.To ensure that
vi.useRealTimers()
is always called, even iffn
throws an error, it should be placed inside afinally
block.
6-6
: Return the result of the executed function.The return statement is correct, but ensure that the result is returned after reverting to real timers.
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.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (1)
packages/utils/src/test/withFlushTimers.ts (1)
1-1
: Ensure type safety for theargs
parameter.The
args
parameter is typed asArray<any>
, which can lead to potential type safety issues. Consider using a more specific type if possible.export function withFlushTimers<T extends any[], U>(fn: (...args: T) => U, args: T) {
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
packages/utils/index.ts
is excluded by none and included by none
Files selected for processing (1)
- packages/utils/src/test/withFlushTimers.ts (1 hunks)
@@ -159,7 +159,8 @@ describe('mutation on runtimeState', () => { | |||
const event1 = { ...mockEvent, id: 'event1', timeStart: 0, timeEnd: 1000, duration: 1000 }; | |||
const event2 = { ...mockEvent, id: 'event2', timeStart: 1000, timeEnd: 1500, duration: 500 }; | |||
// force update | |||
initRundown([event1, event2], {}); | |||
withFlushTimers(initRundown, [[event1, event2], {}]); |
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.
question: dont we need to await the init rundown?
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.
yeah you might be right, initRundown is async...
I will try and see if I can adapt the function
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.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
packages/utils/index.ts
is excluded by none and included by none
Files selected for processing (2)
- apps/server/src/stores/tests/runtimeState.test.ts (3 hunks)
- packages/utils/src/test/withFlushTimers.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- apps/server/src/stores/tests/runtimeState.test.ts
Additional comments not posted (1)
packages/utils/src/test/withFlushTimers.ts (1)
1-7
: Ensure fake timers are properly restored in case of errors.If
fn
throws an error,vi.useRealTimers()
may not be called. Consider using atry...finally
block to ensure timers are always restored.vi.useFakeTimers(); let ret: U; try { ret = fn(...args); vi.runAllTimers(); } finally { vi.useRealTimers(); } return ret;
5e42b73
to
57a34f2
Compare
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- apps/server/src/stores/tests/runtimeState.test.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- apps/server/src/stores/tests/runtimeState.test.ts
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.
Good work
test failing in github actions