Skip to content
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

bun test should drop-in replace vi.useFakeTimers + vi.setSystemTime + vi.useRealTimers using vitest like it does with jest globals #5548

Closed
4 tasks done
NateRadebaugh opened this issue Apr 15, 2024 · 1 comment

Comments

@NateRadebaugh
Copy link

Clear and concise description of the problem

Test file in formatDate.test.ts

import { afterAll, beforeAll, describe, vi } from "vitest";

describe("formatDate", () => {
  beforeAll(() => {
    vi.useFakeTimers();
    vi.setSystemTime(new Date("2021-01-01T18:00:00Z"));
  });

  afterAll(() => {
    vi.useRealTimers();
  });
});

Run:

bun test formatDate

Error:

XXX> bun test formatDate        
bun test v1.1.3 (2615dc74)

XXX\formatDate.test.ts:
2 | import { formatDate } from "XXX/format";
3 | import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
4 |
5 | describe("formatDate", () => {
6 |   beforeAll(() => {
7 |     vi.useFakeTimers();
        ^
TypeError: vi.useFakeTimers is not a function. (In 'vi.useFakeTimers()', 'vi.useFakeTimers' is undefined)
      at XXX\formatDate.test.ts:7:5
      at XXX\formatDate.test.ts:5:1

 0 pass
 0 fail
Ran 0 tests across 1 files. [107.00ms]

Suggested solution

There's already some magic that occurs within bun test when using jest methods via @jest/globals but it'd be great if the same logic could be extended to include vitest helper methods from vi so we don't need to change our test code in order to run with bun test.

Alternative

No response

Additional context

No response

Validations

@NateRadebaugh
Copy link
Author

NateRadebaugh commented Apr 15, 2024

Sorry I meant to open this in the bun repo.

oven-sh/bun#10275

@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant