Skip to content

Replace mockdate#507

Open
joaopedrodcf wants to merge 1 commit intoe18e:mainfrom
joaopedrodcf:joaopedrodcf/mockdate
Open

Replace mockdate#507
joaopedrodcf wants to merge 1 commit intoe18e:mainfrom
joaopedrodcf:joaopedrodcf/mockdate

Conversation

@joaopedrodcf
Copy link
Copy Markdown
Contributor

🔗 Linked issue

#487

📚 Description

AI was used an code was reviewed

"url": {"type": "node", "id": "api/module.html#modulebuiltinmodules"}
},
"bun:test": {
"id": "bun:test",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@43081j we don't have any example like this as far as I know, do you know how should we put this one into place has its part of native and same for node:test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joaopedrodcf I think this should be "type": "native" similar to what we have for node:* and Bun.* apis

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bun doesn't really have any version data anywhere. so we can't define which version introduced it.

for now this is fine but you need to put bun:test as the last replacement in the replacements array. otherwise it will be shown to non-bun users.

Roman is also right, it should be type: "native"

@gameroman
Copy link
Copy Markdown
Contributor

@joaopedrodcf could you also update the description to have Closes #487 instead of just #487 please. Thank you


# Replacements for `mockdate`

`mockdate` is mainly used in tests, and modern test runners already include built-in APIs for freezing time without pulling in an extra dependency.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`mockdate` is mainly used in tests, and modern test runners already include built-in APIs for freezing time without pulling in an extra dependency.
`mockdate` is mainly used in tests, and modern test runners already include built-in APIs for mocking time without pulling in an extra dependency.


## `vitest`

[`vitest`](https://vitest.dev/guide/mocking.html#mock-the-current-date) provides `vi.useFakeTimers()` and `vi.setSystemTime()` for freezing the current date during tests.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[`vitest`](https://vitest.dev/guide/mocking.html#mock-the-current-date) provides `vi.useFakeTimers()` and `vi.setSystemTime()` for freezing the current date during tests.
[`vitest`](https://vitest.dev/guide/mocking.html#mock-the-current-date) provides `vi.useFakeTimers()` and `vi.setSystemTime()` for mocking the current date during tests.


## `node:test`

[`node:test`](https://nodejs.org/en/learn/test-runner/mocking#time) supports freezing time via `mock.timers` since node 20.4.0 and later.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[`node:test`](https://nodejs.org/en/learn/test-runner/mocking#time) supports freezing time via `mock.timers` since node 20.4.0 and later.
[`node:test`](https://nodejs.org/en/learn/test-runner/mocking#time) supports mocking time via `mock.timers` since node 20.4.0 and later.


## `bun:test`

[`bun:test`](https://bun.com/docs/guides/test/mock-clock) provides `mock.timers.enable()` for freezing the clock in tests.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[`bun:test`](https://bun.com/docs/guides/test/mock-clock) provides `mock.timers.enable()` for freezing the clock in tests.
[`bun:test`](https://bun.com/docs/guides/test/mock-clock) provides `mock.timers.enable()` for mocking time in tests.

"url": {"type": "node", "id": "api/module.html#modulebuiltinmodules"}
},
"bun:test": {
"id": "bun:test",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bun doesn't really have any version data anywhere. so we can't define which version introduced it.

for now this is fine but you need to put bun:test as the last replacement in the replacements array. otherwise it will be shown to non-bun users.

Roman is also right, it should be type: "native"

"mockdate": {
"type": "module",
"moduleName": "mockdate",
"replacements": ["bun:test", "node:test", "vitest"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"replacements": ["bun:test", "node:test", "vitest"],
"replacements": ["node:test", "vitest", "bun:test"],

},
"node:test": {
"id": "node:test",
"type": "documented",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a native type

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and url should point to nodejs docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants