bun-types 1.2.13-canary.20250508T140628 → 1.2.13-canary.20250510T141317
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/api/binary-data.md +12 -2
- package/docs/api/dns.md +8 -11
- package/docs/api/fetch.md +1 -1
- package/docs/api/file-io.md +1 -1
- package/docs/api/s3.md +5 -9
- package/docs/api/spawn.md +1 -1
- package/docs/api/streams.md +6 -4
- package/docs/api/udp.md +24 -26
- package/docs/bundler/index.md +1 -1
- package/docs/bundler/macros.md +10 -8
- package/docs/cli/add.md +3 -3
- package/docs/cli/link.md +1 -1
- package/docs/cli/patch-commit.md +1 -1
- package/docs/cli/publish.md +1 -1
- package/docs/cli/run.md +1 -1
- package/docs/cli/update.md +1 -1
- package/docs/ecosystem/stric.md +2 -1
- package/docs/guides/ecosystem/neon-drizzle.md +5 -5
- package/docs/guides/ecosystem/nuxt.md +1 -1
- package/docs/guides/ecosystem/pm2.md +1 -1
- package/docs/guides/ecosystem/sveltekit.md +6 -6
- package/docs/guides/install/add-peer.md +2 -3
- package/docs/guides/install/from-npm-install-to-bun-install.md +1 -1
- package/docs/guides/process/argv.md +0 -1
- package/docs/guides/runtime/set-env.md +1 -2
- package/docs/guides/test/run-tests.md +3 -3
- package/docs/guides/test/snapshot.md +3 -3
- package/docs/guides/test/testing-library.md +11 -6
- package/docs/guides/test/update-snapshots.md +1 -1
- package/docs/guides/util/version.md +1 -1
- package/docs/install/patch.md +1 -1
- package/docs/installation.md +4 -4
- package/docs/runtime/bunfig.md +0 -1
- package/docs/runtime/debugger.md +3 -3
- package/docs/runtime/hot.md +0 -1
- package/docs/test/dom.md +1 -1
- package/docs/test/mocks.md +22 -20
- package/docs/test/time.md +2 -2
- package/package.json +1 -1
- package/redis.d.ts +8 -1
package/docs/api/binary-data.md
CHANGED
|
@@ -557,6 +557,7 @@ Buffer.from(buf, 0, 10);
|
|
|
557
557
|
#### To `string`
|
|
558
558
|
|
|
559
559
|
As UTF-8:
|
|
560
|
+
|
|
560
561
|
```ts
|
|
561
562
|
new TextDecoder().decode(buf);
|
|
562
563
|
```
|
|
@@ -638,6 +639,7 @@ Buffer.from(arr);
|
|
|
638
639
|
#### To `string`
|
|
639
640
|
|
|
640
641
|
As UTF-8:
|
|
642
|
+
|
|
641
643
|
```ts
|
|
642
644
|
new TextDecoder().decode(arr);
|
|
643
645
|
```
|
|
@@ -716,6 +718,7 @@ Buffer.from(view.buffer, view.byteOffset, view.byteLength);
|
|
|
716
718
|
#### To `string`
|
|
717
719
|
|
|
718
720
|
As UTF-8:
|
|
721
|
+
|
|
719
722
|
```ts
|
|
720
723
|
new TextDecoder().decode(view);
|
|
721
724
|
```
|
|
@@ -788,16 +791,21 @@ new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
|
788
791
|
#### To `string`
|
|
789
792
|
|
|
790
793
|
As UTF-8:
|
|
794
|
+
|
|
791
795
|
```ts
|
|
792
796
|
buf.toString();
|
|
793
797
|
```
|
|
798
|
+
|
|
794
799
|
As base64:
|
|
800
|
+
|
|
795
801
|
```ts
|
|
796
|
-
buf.toString(
|
|
802
|
+
buf.toString("base64");
|
|
797
803
|
```
|
|
804
|
+
|
|
798
805
|
As hex:
|
|
806
|
+
|
|
799
807
|
```ts
|
|
800
|
-
buf.toString(
|
|
808
|
+
buf.toString("hex");
|
|
801
809
|
```
|
|
802
810
|
|
|
803
811
|
#### To `number[]`
|
|
@@ -876,6 +884,7 @@ Buffer.from(await blob.arrayBuffer());
|
|
|
876
884
|
#### To `string`
|
|
877
885
|
|
|
878
886
|
As UTF-8:
|
|
887
|
+
|
|
879
888
|
```ts
|
|
880
889
|
await blob.text();
|
|
881
890
|
```
|
|
@@ -962,6 +971,7 @@ Buffer.from(Bun.readableStreamToArrayBuffer(stream));
|
|
|
962
971
|
#### To `string`
|
|
963
972
|
|
|
964
973
|
As UTF-8:
|
|
974
|
+
|
|
965
975
|
```ts
|
|
966
976
|
// with Response
|
|
967
977
|
await new Response(stream).text();
|
package/docs/api/dns.md
CHANGED
|
@@ -10,7 +10,7 @@ console.log(addrs);
|
|
|
10
10
|
|
|
11
11
|
## DNS caching in Bun
|
|
12
12
|
|
|
13
|
-
In Bun v1.1.9, we added support for DNS caching. This cache makes repeated connections to the same hosts faster.
|
|
13
|
+
In Bun v1.1.9, we added support for DNS caching. This cache makes repeated connections to the same hosts faster.
|
|
14
14
|
|
|
15
15
|
At the time of writing, we cache up to 255 entries for a maximum of 30 seconds (each). If any connections to a host fail, we remove the entry from the cache. When multiple connections are made to the same host simultaneously, DNS lookups are deduplicated to avoid making multiple requests for the same host.
|
|
16
16
|
|
|
@@ -27,10 +27,10 @@ This cache is automatically used by:
|
|
|
27
27
|
|
|
28
28
|
Web browsers expose [`<link rel="dns-prefetch">`](https://developer.mozilla.org/en-US/docs/Web/Performance/dns-prefetch) to allow developers to prefetch DNS entries. This is useful when you know you'll need to connect to a host in the near future and want to avoid the initial DNS lookup.
|
|
29
29
|
|
|
30
|
-
In Bun, you can use the `dns.prefetch` API to achieve the same effect.
|
|
30
|
+
In Bun, you can use the `dns.prefetch` API to achieve the same effect.
|
|
31
31
|
|
|
32
32
|
```ts
|
|
33
|
-
import {dns} from "bun";
|
|
33
|
+
import { dns } from "bun";
|
|
34
34
|
|
|
35
35
|
dns.prefetch("my.database-host.com", 5432);
|
|
36
36
|
```
|
|
@@ -52,7 +52,7 @@ dns.prefetch(hostname: string, port: number): void;
|
|
|
52
52
|
Here's an example:
|
|
53
53
|
|
|
54
54
|
```ts
|
|
55
|
-
import {dns} from "bun";
|
|
55
|
+
import { dns } from "bun";
|
|
56
56
|
|
|
57
57
|
dns.prefetch("bun.sh", 443);
|
|
58
58
|
//
|
|
@@ -66,13 +66,13 @@ await fetch("https://bun.sh");
|
|
|
66
66
|
**🚧** — This API is experimental and may change in the future.
|
|
67
67
|
{% /callout %}
|
|
68
68
|
|
|
69
|
-
To get the current cache stats, you can use the `dns.getCacheStats` API.
|
|
69
|
+
To get the current cache stats, you can use the `dns.getCacheStats` API.
|
|
70
70
|
|
|
71
71
|
This API returns an object with the following properties:
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
74
|
{
|
|
75
|
-
// Cache hits
|
|
75
|
+
// Cache hits
|
|
76
76
|
cacheHitsCompleted: number;
|
|
77
77
|
cacheHitsInflight: number;
|
|
78
78
|
cacheMisses: number;
|
|
@@ -90,7 +90,7 @@ This API returns an object with the following properties:
|
|
|
90
90
|
Example:
|
|
91
91
|
|
|
92
92
|
```ts
|
|
93
|
-
import {dns} from "bun";
|
|
93
|
+
import { dns } from "bun";
|
|
94
94
|
|
|
95
95
|
const stats = dns.getCacheStats();
|
|
96
96
|
console.log(stats);
|
|
@@ -107,7 +107,4 @@ BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS=5 bun run my-script.ts
|
|
|
107
107
|
|
|
108
108
|
#### Why is 30 seconds the default?
|
|
109
109
|
|
|
110
|
-
Unfortunately, the system API underneath (`getaddrinfo`) does not provide a way to get the TTL of a DNS entry. This means we have to pick a number arbitrarily. We chose 30 seconds because it's long enough to see the benefits of caching, and short enough to be unlikely to cause issues if a DNS entry changes. [Amazon Web Services recommends 5 seconds](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/jvm-ttl-dns.html) for the Java Virtual Machine, however the JVM defaults to cache indefinitely.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
Unfortunately, the system API underneath (`getaddrinfo`) does not provide a way to get the TTL of a DNS entry. This means we have to pick a number arbitrarily. We chose 30 seconds because it's long enough to see the benefits of caching, and short enough to be unlikely to cause issues if a DNS entry changes. [Amazon Web Services recommends 5 seconds](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/jvm-ttl-dns.html) for the Java Virtual Machine, however the JVM defaults to cache indefinitely.
|
package/docs/api/fetch.md
CHANGED
|
@@ -337,7 +337,7 @@ This will print the request and response headers to your terminal:
|
|
|
337
337
|
```sh
|
|
338
338
|
[fetch] > HTTP/1.1 GET http://example.com/
|
|
339
339
|
[fetch] > Connection: keep-alive
|
|
340
|
-
[fetch] > User-Agent: Bun/1.2.13-canary.
|
|
340
|
+
[fetch] > User-Agent: Bun/1.2.13-canary.20250510T141317
|
|
341
341
|
[fetch] > Accept: */*
|
|
342
342
|
[fetch] > Host: example.com
|
|
343
343
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
package/docs/api/file-io.md
CHANGED
package/docs/api/s3.md
CHANGED
|
@@ -638,14 +638,10 @@ const credentials = {
|
|
|
638
638
|
await S3Client.write("my-file.txt", "Hello World");
|
|
639
639
|
|
|
640
640
|
// Write JSON with type
|
|
641
|
-
await S3Client.write(
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
...credentials,
|
|
646
|
-
type: "application/json",
|
|
647
|
-
}
|
|
648
|
-
);
|
|
641
|
+
await S3Client.write("data.json", JSON.stringify({ hello: "world" }), {
|
|
642
|
+
...credentials,
|
|
643
|
+
type: "application/json",
|
|
644
|
+
});
|
|
649
645
|
|
|
650
646
|
// Write from fetch
|
|
651
647
|
const res = await fetch("https://example.com/data");
|
|
@@ -655,7 +651,7 @@ await S3Client.write("data.bin", res, credentials);
|
|
|
655
651
|
await S3Client.write("public.html", html, {
|
|
656
652
|
...credentials,
|
|
657
653
|
acl: "public-read",
|
|
658
|
-
type: "text/html"
|
|
654
|
+
type: "text/html",
|
|
659
655
|
});
|
|
660
656
|
```
|
|
661
657
|
|
package/docs/api/spawn.md
CHANGED
|
@@ -120,7 +120,7 @@ You can read results from the subprocess via the `stdout` and `stderr` propertie
|
|
|
120
120
|
```ts
|
|
121
121
|
const proc = Bun.spawn(["bun", "--version"]);
|
|
122
122
|
const text = await new Response(proc.stdout).text();
|
|
123
|
-
console.log(text); // => "1.2.13-canary.
|
|
123
|
+
console.log(text); // => "1.2.13-canary.20250510T141317"
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
Configure the output stream by passing one of the following values to `stdout/stderr`:
|
package/docs/api/streams.md
CHANGED
|
@@ -61,10 +61,12 @@ When using a direct `ReadableStream`, all chunk queueing is handled by the desti
|
|
|
61
61
|
Bun also supports async generator functions as a source for `Response` and `Request`. This is an easy way to create a `ReadableStream` that fetches data from an asynchronous source.
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
|
-
const response = new Response(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
const response = new Response(
|
|
65
|
+
(async function* () {
|
|
66
|
+
yield "hello";
|
|
67
|
+
yield "world";
|
|
68
|
+
})(),
|
|
69
|
+
);
|
|
68
70
|
|
|
69
71
|
await response.text(); // "helloworld"
|
|
70
72
|
```
|
package/docs/api/udp.md
CHANGED
|
@@ -5,15 +5,16 @@ Use Bun's UDP API to implement services with advanced real-time requirements, su
|
|
|
5
5
|
To create a new (bound) UDP socket:
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
|
-
const socket = await Bun.udpSocket({})
|
|
8
|
+
const socket = await Bun.udpSocket({});
|
|
9
9
|
console.log(socket.port); // assigned by the operating system
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
Specify a port:
|
|
13
|
+
|
|
13
14
|
```ts
|
|
14
15
|
const socket = await Bun.udpSocket({
|
|
15
|
-
port: 41234
|
|
16
|
-
})
|
|
16
|
+
port: 41234,
|
|
17
|
+
});
|
|
17
18
|
console.log(socket.port); // 41234
|
|
18
19
|
```
|
|
19
20
|
|
|
@@ -28,7 +29,6 @@ socket.send("Hello, world!", 41234, "127.0.0.1");
|
|
|
28
29
|
Note that the address must be a valid IP address - `send` does not perform
|
|
29
30
|
DNS resolution, as it is intended for low-latency operations.
|
|
30
31
|
|
|
31
|
-
|
|
32
32
|
### Receive datagrams
|
|
33
33
|
|
|
34
34
|
When creating your socket, add a callback to specify what should be done when packets are received:
|
|
@@ -37,11 +37,11 @@ When creating your socket, add a callback to specify what should be done when pa
|
|
|
37
37
|
const server = await Bun.udpSocket({
|
|
38
38
|
socket: {
|
|
39
39
|
data(socket, buf, port, addr) {
|
|
40
|
-
console.log(`message from ${addr}:${port}:`)
|
|
40
|
+
console.log(`message from ${addr}:${port}:`);
|
|
41
41
|
console.log(buf.toString());
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
})
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
45
|
|
|
46
46
|
const client = await Bun.udpSocket({});
|
|
47
47
|
client.send("Hello!", server.port, "127.0.0.1");
|
|
@@ -54,29 +54,26 @@ In such cases it can be beneficial to connect the socket to that peer, which spe
|
|
|
54
54
|
and restricts incoming packets to that peer only.
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
|
-
|
|
58
57
|
const server = await Bun.udpSocket({
|
|
59
58
|
socket: {
|
|
60
59
|
data(socket, buf, port, addr) {
|
|
61
|
-
console.log(`message from ${addr}:${port}:`)
|
|
60
|
+
console.log(`message from ${addr}:${port}:`);
|
|
62
61
|
console.log(buf.toString());
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
})
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
66
65
|
const client = await Bun.udpSocket({
|
|
67
66
|
connect: {
|
|
68
67
|
port: server.port,
|
|
69
|
-
hostname:
|
|
70
|
-
}
|
|
68
|
+
hostname: "127.0.0.1",
|
|
69
|
+
},
|
|
71
70
|
});
|
|
72
71
|
|
|
73
72
|
client.send("Hello");
|
|
74
|
-
|
|
75
73
|
```
|
|
76
74
|
|
|
77
75
|
Because connections are implemented on the operating system level, you can potentially observe performance benefits, too.
|
|
78
76
|
|
|
79
|
-
|
|
80
77
|
### Send many packets at once using `sendMany()`
|
|
81
78
|
|
|
82
79
|
If you want to send a large volume of packets at once, it can make sense to batch them all together to avoid the overhead
|
|
@@ -86,9 +83,9 @@ For an unconnected socket, `sendMany` takes an array as its only argument. Each
|
|
|
86
83
|
The first item is the data to be sent, the second is the target port, and the last is the target address.
|
|
87
84
|
|
|
88
85
|
```ts
|
|
89
|
-
const socket = await Bun.udpSocket({})
|
|
86
|
+
const socket = await Bun.udpSocket({});
|
|
90
87
|
// sends 'Hello' to 127.0.0.1:41234, and 'foo' to 1.1.1.1:53 in a single operation
|
|
91
|
-
socket.sendMany([
|
|
88
|
+
socket.sendMany(["Hello", 41234, "127.0.0.1", "foo", 53, "1.1.1.1"]);
|
|
92
89
|
```
|
|
93
90
|
|
|
94
91
|
With a connected socket, `sendMany` simply takes an array, where each element represents the data to be sent to the peer.
|
|
@@ -97,10 +94,10 @@ With a connected socket, `sendMany` simply takes an array, where each element re
|
|
|
97
94
|
const socket = await Bun.udpSocket({
|
|
98
95
|
connect: {
|
|
99
96
|
port: 41234,
|
|
100
|
-
hostname:
|
|
101
|
-
}
|
|
97
|
+
hostname: "localhost",
|
|
98
|
+
},
|
|
102
99
|
});
|
|
103
|
-
socket.sendMany([
|
|
100
|
+
socket.sendMany(["foo", "bar", "baz"]);
|
|
104
101
|
```
|
|
105
102
|
|
|
106
103
|
`sendMany` returns the number of packets that were successfully sent. As with `send`, `sendMany` only takes valid IP addresses
|
|
@@ -110,16 +107,17 @@ as destinations, as it does not perform DNS resolution.
|
|
|
110
107
|
|
|
111
108
|
It may happen that a packet that you're sending does not fit into the operating system's packet buffer. You can detect that this
|
|
112
109
|
has happened when:
|
|
113
|
-
|
|
110
|
+
|
|
111
|
+
- `send` returns `false`
|
|
114
112
|
- `sendMany` returns a number smaller than the number of packets you specified
|
|
115
|
-
In this case, the `drain` socket handler will be called once the socket becomes writable again:
|
|
113
|
+
In this case, the `drain` socket handler will be called once the socket becomes writable again:
|
|
116
114
|
|
|
117
115
|
```ts
|
|
118
116
|
const socket = await Bun.udpSocket({
|
|
119
117
|
socket: {
|
|
120
118
|
drain(socket) {
|
|
121
119
|
// continue sending data
|
|
122
|
-
}
|
|
123
|
-
}
|
|
120
|
+
},
|
|
121
|
+
},
|
|
124
122
|
});
|
|
125
123
|
```
|
package/docs/bundler/index.md
CHANGED
package/docs/bundler/macros.md
CHANGED
|
@@ -71,7 +71,7 @@ node_modules/evil/index.js:3:1 50
|
|
|
71
71
|
Your application code can still import macros from `node_modules` and invoke them.
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
|
-
import {macro} from "some-package" with { type: "macro" };
|
|
74
|
+
import { macro } from "some-package" with { type: "macro" };
|
|
75
75
|
|
|
76
76
|
macro();
|
|
77
77
|
```
|
|
@@ -95,8 +95,8 @@ When shipping a library containing a macro to `npm` or another package registry,
|
|
|
95
95
|
With this configuration, users can consume your package at runtime or at bundle-time using the same import specifier:
|
|
96
96
|
|
|
97
97
|
```ts
|
|
98
|
-
import pkg from "my-package";
|
|
99
|
-
import {macro} from "my-package" with { type: "macro" }; // macro import
|
|
98
|
+
import pkg from "my-package"; // runtime import
|
|
99
|
+
import { macro } from "my-package" with { type: "macro" }; // macro import
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
The first import will resolve to `./node_modules/my-package/index.js`, while the second will be resolved by Bun's bundler to `./node_modules/my-package/index.macro.js`.
|
|
@@ -122,7 +122,7 @@ export function returnFalse() {
|
|
|
122
122
|
...then bundling the following file will produce an empty bundle, provided that the minify syntax option is enabled.
|
|
123
123
|
|
|
124
124
|
```ts
|
|
125
|
-
import {returnFalse} from
|
|
125
|
+
import { returnFalse } from "./returnFalse.ts" with { type: "macro" };
|
|
126
126
|
|
|
127
127
|
if (returnFalse()) {
|
|
128
128
|
console.log("This code is eliminated");
|
|
@@ -179,7 +179,7 @@ export function getText(url: string) {
|
|
|
179
179
|
Macros can accept inputs, but only in limited cases. The value must be statically known. For example, the following is not allowed:
|
|
180
180
|
|
|
181
181
|
```ts
|
|
182
|
-
import {getText} from
|
|
182
|
+
import { getText } from "./getText.ts" with { type: "macro" };
|
|
183
183
|
|
|
184
184
|
export function howLong() {
|
|
185
185
|
// the value of `foo` cannot be statically known
|
|
@@ -193,8 +193,8 @@ export function howLong() {
|
|
|
193
193
|
However, if the value of `foo` is known at bundle-time (say, if it's a constant or the result of another macro) then it's allowed:
|
|
194
194
|
|
|
195
195
|
```ts
|
|
196
|
-
import {getText} from
|
|
197
|
-
import {getFoo} from
|
|
196
|
+
import { getText } from "./getText.ts" with { type: "macro" };
|
|
197
|
+
import { getFoo } from "./getFoo.ts" with { type: "macro" };
|
|
198
198
|
|
|
199
199
|
export function howLong() {
|
|
200
200
|
// this works because getFoo() is statically known
|
|
@@ -271,7 +271,9 @@ export async function extractMetaTags(url: string) {
|
|
|
271
271
|
.on("meta", {
|
|
272
272
|
element(element) {
|
|
273
273
|
const name =
|
|
274
|
-
element.getAttribute("name") ||
|
|
274
|
+
element.getAttribute("name") ||
|
|
275
|
+
element.getAttribute("property") ||
|
|
276
|
+
element.getAttribute("itemprop");
|
|
275
277
|
|
|
276
278
|
if (name) meta[name] = element.getAttribute("content");
|
|
277
279
|
},
|
package/docs/cli/add.md
CHANGED
|
@@ -63,8 +63,8 @@ This will add the following to your `package.json`:
|
|
|
63
63
|
"react": "^18.2.0", // this matches >= 18.2.0 < 19.0.0
|
|
64
64
|
|
|
65
65
|
// with --exact
|
|
66
|
-
"react": "18.2.0" // this matches only 18.2.0 exactly
|
|
67
|
-
}
|
|
66
|
+
"react": "18.2.0", // this matches only 18.2.0 exactly
|
|
67
|
+
},
|
|
68
68
|
}
|
|
69
69
|
```
|
|
70
70
|
|
|
@@ -170,4 +170,4 @@ This will add the following line to your `package.json`:
|
|
|
170
170
|
}
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
-
{% bunCLIUsage command="add" /%}
|
|
173
|
+
{% bunCLIUsage command="add" /%}
|
package/docs/cli/link.md
CHANGED
package/docs/cli/patch-commit.md
CHANGED
package/docs/cli/publish.md
CHANGED
package/docs/cli/run.md
CHANGED
|
@@ -206,4 +206,4 @@ When there is a package.json script and a file with the same name, `bun run` pri
|
|
|
206
206
|
3. Binaries from project packages, eg `bun add eslint && bun run eslint`
|
|
207
207
|
4. (`bun run` only) System commands, eg `bun run ls`
|
|
208
208
|
|
|
209
|
-
{% bunCLIUsage command="run" /%}
|
|
209
|
+
{% bunCLIUsage command="run" /%}
|
package/docs/cli/update.md
CHANGED
|
@@ -33,4 +33,4 @@ For example, with the following `package.json`:
|
|
|
33
33
|
- `bun update` would update to a version that matches `17.x`.
|
|
34
34
|
- `bun update --latest` would update to a version that matches `18.x` or later.
|
|
35
35
|
|
|
36
|
-
{% bunCLIUsage command="update" /%}
|
|
36
|
+
{% bunCLIUsage command="update" /%}
|
package/docs/ecosystem/stric.md
CHANGED
|
@@ -9,7 +9,7 @@ export default new Router()
|
|
|
9
9
|
.get('/', () => new Response('Hi'));
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
Stric provides support for [ArrowJS](https://www.arrow-js.com), a library for building reactive interfaces.
|
|
12
|
+
Stric provides support for [ArrowJS](https://www.arrow-js.com), a library for building reactive interfaces.
|
|
13
13
|
|
|
14
14
|
{% codetabs %}
|
|
15
15
|
|
|
@@ -25,6 +25,7 @@ export function render() {
|
|
|
25
25
|
// Set the path to handle
|
|
26
26
|
export const path = '/';
|
|
27
27
|
```
|
|
28
|
+
|
|
28
29
|
```ts#index.ts
|
|
29
30
|
import { PageRouter } from '@stricjs/arrow';
|
|
30
31
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
name: Use Neon Postgres through Drizzle ORM
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
[Neon](https://neon.tech/) is a fully managed serverless Postgres, separating compute and storage to offer features like autoscaling, branching and bottomless storage. Neon can be used from Bun directly using the `@neondatabase/serverless` driver or through an ORM like `Drizzle`.
|
|
5
|
+
[Neon](https://neon.tech/) is a fully managed serverless Postgres, separating compute and storage to offer features like autoscaling, branching and bottomless storage. Neon can be used from Bun directly using the `@neondatabase/serverless` driver or through an ORM like `Drizzle`.
|
|
6
6
|
|
|
7
|
-
Drizzle ORM supports both a SQL-like "query builder" API and an ORM-like [Queries API](https://orm.drizzle.team/docs/rqb). Get started by creating a project directory, initializing the directory using `bun init`, and installing Drizzle and the [Neon serverless driver](https://github.com/neondatabase/serverless/).
|
|
7
|
+
Drizzle ORM supports both a SQL-like "query builder" API and an ORM-like [Queries API](https://orm.drizzle.team/docs/rqb). Get started by creating a project directory, initializing the directory using `bun init`, and installing Drizzle and the [Neon serverless driver](https://github.com/neondatabase/serverless/).
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
10
|
$ mkdir bun-drizzle-neon
|
|
@@ -52,7 +52,7 @@ console.log(result.rows);
|
|
|
52
52
|
|
|
53
53
|
---
|
|
54
54
|
|
|
55
|
-
Then run `index.ts` with Bun.
|
|
55
|
+
Then run `index.ts` with Bun.
|
|
56
56
|
|
|
57
57
|
```sh
|
|
58
58
|
$ bun run index.ts
|
|
@@ -65,7 +65,7 @@ $ bun run index.ts
|
|
|
65
65
|
|
|
66
66
|
---
|
|
67
67
|
|
|
68
|
-
We can define a schema for our database using Drizzle ORM primitives. Create a `schema.ts` file and add this code.
|
|
68
|
+
We can define a schema for our database using Drizzle ORM primitives. Create a `schema.ts` file and add this code.
|
|
69
69
|
|
|
70
70
|
```ts#schema.ts
|
|
71
71
|
import { pgTable, integer, serial, text, timestamp } from "drizzle-orm/pg-core";
|
|
@@ -215,6 +215,6 @@ $ bun run index.ts
|
|
|
215
215
|
|
|
216
216
|
---
|
|
217
217
|
|
|
218
|
-
This example used the Neon serverless driver's SQL-over-HTTP functionality. Neon's serverless driver also exposes `Client` and `Pool` constructors to enable sessions, interactive transactions, and node-postgres compatibility. Refer to [Neon's documentation](https://neon.tech/docs/serverless/serverless-driver) for a complete overview.
|
|
218
|
+
This example used the Neon serverless driver's SQL-over-HTTP functionality. Neon's serverless driver also exposes `Client` and `Pool` constructors to enable sessions, interactive transactions, and node-postgres compatibility. Refer to [Neon's documentation](https://neon.tech/docs/serverless/serverless-driver) for a complete overview.
|
|
219
219
|
|
|
220
220
|
Refer to the [Drizzle website](https://orm.drizzle.team/docs/overview) for more documentation on using the Drizzle ORM.
|
|
@@ -9,7 +9,7 @@ $ bunx nuxi init my-nuxt-app
|
|
|
9
9
|
✔ Which package manager would you like to use?
|
|
10
10
|
bun
|
|
11
11
|
◐ Installing dependencies...
|
|
12
|
-
bun install v1.2.13-canary.
|
|
12
|
+
bun install v1.2.13-canary.20250510T141317 (16b4bf34)
|
|
13
13
|
+ @nuxt/devtools@0.8.2
|
|
14
14
|
+ nuxt@3.7.0
|
|
15
15
|
785 packages installed [2.67s]
|
|
@@ -52,9 +52,9 @@ $ cd my-app
|
|
|
52
52
|
$ bun --bun run dev
|
|
53
53
|
$ vite dev
|
|
54
54
|
Forced re-optimization of dependencies
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
VITE v5.4.10 ready in 424 ms
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
➜ Local: http://localhost:5173/
|
|
59
59
|
➜ Network: use --host to expose
|
|
60
60
|
➜ press h + enter to show help
|
|
@@ -88,7 +88,7 @@ Now, make the following changes to your `svelte.config.js`.
|
|
|
88
88
|
// Consult https://svelte.dev/docs/kit/integrations#preprocessors
|
|
89
89
|
// for more information about preprocessors
|
|
90
90
|
preprocess: vitePreprocess(),
|
|
91
|
-
|
|
91
|
+
|
|
92
92
|
kit: {
|
|
93
93
|
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
|
|
94
94
|
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
|
|
@@ -96,7 +96,7 @@ Now, make the following changes to your `svelte.config.js`.
|
|
|
96
96
|
adapter: adapter()
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
export default config;
|
|
101
101
|
```
|
|
102
102
|
|
|
@@ -116,9 +116,9 @@ $ bun --bun run build
|
|
|
116
116
|
✓ built in 231ms
|
|
117
117
|
...
|
|
118
118
|
✓ built in 899ms
|
|
119
|
-
|
|
119
|
+
|
|
120
120
|
Run npm run preview to preview your production build locally.
|
|
121
|
-
|
|
121
|
+
|
|
122
122
|
> Using svelte-adapter-bun
|
|
123
123
|
✔ Start server with: bun ./build/index.js
|
|
124
124
|
✔ done
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
name: Add a peer dependency
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
To add an npm package as a peer dependency, use the `--peer` flag.
|
|
7
6
|
|
|
8
7
|
```sh
|
|
@@ -16,7 +15,7 @@ This will add the package to `peerDependencies` in `package.json`.
|
|
|
16
15
|
```json-diff
|
|
17
16
|
{
|
|
18
17
|
"peerDependencies": {
|
|
19
|
-
+ "@types/bun": "^1.2.13-canary.
|
|
18
|
+
+ "@types/bun": "^1.2.13-canary.20250510T141317"
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
```
|
|
@@ -28,7 +27,7 @@ Running `bun install` will install peer dependencies by default, unless marked o
|
|
|
28
27
|
```json-diff
|
|
29
28
|
{
|
|
30
29
|
"peerDependencies": {
|
|
31
|
-
"@types/bun": "^1.2.13-canary.
|
|
30
|
+
"@types/bun": "^1.2.13-canary.20250510T141317"
|
|
32
31
|
},
|
|
33
32
|
"peerDependenciesMeta": {
|
|
34
33
|
+ "@types/bun": {
|
|
@@ -97,7 +97,7 @@ $ bun update
|
|
|
97
97
|
$ bun update @types/bun --latest
|
|
98
98
|
|
|
99
99
|
# Update a dependency to a specific version
|
|
100
|
-
$ bun update @types/bun@1.2.13-canary.
|
|
100
|
+
$ bun update @types/bun@1.2.13-canary.20250510T141317
|
|
101
101
|
|
|
102
102
|
# Update all dependencies to the latest versions
|
|
103
103
|
$ bun update --latest
|
|
@@ -42,7 +42,6 @@ $ set FOO=helloworld && bun run dev
|
|
|
42
42
|
$ $env:FOO="helloworld"; bun run dev
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
{% /codetabs %}
|
|
46
|
-
---
|
|
45
|
+
## {% /codetabs %}
|
|
47
46
|
|
|
48
47
|
See [Docs > Runtime > Environment variables](https://bun.sh/docs/runtime/env) for more information on using environment variables with Bun.
|
|
@@ -21,7 +21,7 @@ Here's what the output of a typical test run looks like. In this case, there are
|
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
23
|
$ bun test
|
|
24
|
-
bun test v1.2.13-canary.
|
|
24
|
+
bun test v1.2.13-canary.20250510T141317 (9c68abdb)
|
|
25
25
|
|
|
26
26
|
test.test.js:
|
|
27
27
|
✓ add [0.87ms]
|
|
@@ -47,7 +47,7 @@ To only run certain test files, pass a positional argument to `bun test`. The ru
|
|
|
47
47
|
|
|
48
48
|
```sh
|
|
49
49
|
$ bun test test3
|
|
50
|
-
bun test v1.2.13-canary.
|
|
50
|
+
bun test v1.2.13-canary.20250510T141317 (9c68abdb)
|
|
51
51
|
|
|
52
52
|
test3.test.js:
|
|
53
53
|
✓ add [1.40ms]
|
|
@@ -85,7 +85,7 @@ Adding `-t add` will only run tests with "add" in the name. This works with test
|
|
|
85
85
|
|
|
86
86
|
```sh
|
|
87
87
|
$ bun test -t add
|
|
88
|
-
bun test v1.2.13-canary.
|
|
88
|
+
bun test v1.2.13-canary.20250510T141317 (9c68abdb)
|
|
89
89
|
|
|
90
90
|
test.test.js:
|
|
91
91
|
✓ add [1.79ms]
|
|
@@ -18,7 +18,7 @@ The first time this test is executed, Bun will evaluate the value passed into `e
|
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
20
|
$ bun test test/snap
|
|
21
|
-
bun test v1.2.13-canary.
|
|
21
|
+
bun test v1.2.13-canary.20250510T141317 (9c68abdb)
|
|
22
22
|
|
|
23
23
|
test/snap.test.ts:
|
|
24
24
|
✓ snapshot [1.48ms]
|
|
@@ -61,7 +61,7 @@ Later, when this test file is executed again, Bun will read the snapshot file an
|
|
|
61
61
|
|
|
62
62
|
```sh
|
|
63
63
|
$ bun test
|
|
64
|
-
bun test v1.2.13-canary.
|
|
64
|
+
bun test v1.2.13-canary.20250510T141317 (9c68abdb)
|
|
65
65
|
|
|
66
66
|
test/snap.test.ts:
|
|
67
67
|
✓ snapshot [1.05ms]
|
|
@@ -78,7 +78,7 @@ To update snapshots, use the `--update-snapshots` flag.
|
|
|
78
78
|
|
|
79
79
|
```sh
|
|
80
80
|
$ bun test --update-snapshots
|
|
81
|
-
bun test v1.2.13-canary.
|
|
81
|
+
bun test v1.2.13-canary.20250510T141317 (9c68abdb)
|
|
82
82
|
|
|
83
83
|
test/snap.test.ts:
|
|
84
84
|
✓ snapshot [0.86ms]
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: Using Testing Library with Bun
|
|
3
3
|
---
|
|
4
|
+
|
|
4
5
|
You can use [Testing Library](https://testing-library.com/) with Bun's test runner.
|
|
5
6
|
|
|
6
7
|
---
|
|
8
|
+
|
|
7
9
|
As a prerequisite to using Testing Library you will need to install [Happy Dom](https://github.com/capricorn86/happy-dom). ([see Bun's Happy DOM guide for more information](https://bun.sh/guides/test/happy-dom)).
|
|
8
10
|
|
|
9
11
|
```sh
|
|
@@ -17,6 +19,7 @@ Next you should install the Testing Library packages you are planning on using.
|
|
|
17
19
|
```sh
|
|
18
20
|
bun add -D @testing-library/react @testing-library/dom @testing-library/jest-dom
|
|
19
21
|
```
|
|
22
|
+
|
|
20
23
|
---
|
|
21
24
|
|
|
22
25
|
Next you will need to create a preload script for Happy DOM and for Testing Library. For more details about the Happy DOM setup script see [Bun's Happy DOM guide](https://bun.sh/guides/test/happy-dom).
|
|
@@ -26,6 +29,7 @@ import { GlobalRegistrator } from '@happy-dom/global-registrator';
|
|
|
26
29
|
|
|
27
30
|
GlobalRegistrator.register();
|
|
28
31
|
```
|
|
32
|
+
|
|
29
33
|
---
|
|
30
34
|
|
|
31
35
|
For Testing Library, you will want to extend Bun's `expect` function with Testing Library's matchers. Optionally, to better match the behavior of test-runners like Jest, you may want to run cleanup after each test.
|
|
@@ -51,6 +55,7 @@ Next, add these preload scripts to your `bunfig.toml` (you can also have everyth
|
|
|
51
55
|
[test]
|
|
52
56
|
preload = ["./happydom.ts", "./testing-library.ts"]
|
|
53
57
|
```
|
|
58
|
+
|
|
54
59
|
---
|
|
55
60
|
|
|
56
61
|
If you are using TypeScript you will also need to make use of declaration merging in order to get the new matcher types to show up in your editor. To do this, create a type declaration file that extends `Matchers` like this.
|
|
@@ -71,15 +76,15 @@ declare module 'bun:test' {
|
|
|
71
76
|
You should now be able to use Testing Library in your tests
|
|
72
77
|
|
|
73
78
|
```ts
|
|
74
|
-
import { test, expect } from
|
|
75
|
-
import { screen, render } from
|
|
76
|
-
import { MyComponent } from
|
|
79
|
+
import { test, expect } from "bun:test";
|
|
80
|
+
import { screen, render } from "@testing-library/react";
|
|
81
|
+
import { MyComponent } from "./myComponent";
|
|
77
82
|
|
|
78
|
-
test(
|
|
83
|
+
test("Can use Testing Library", () => {
|
|
79
84
|
render(MyComponent);
|
|
80
|
-
const myComponent = screen.getByTestId(
|
|
85
|
+
const myComponent = screen.getByTestId("my-component");
|
|
81
86
|
expect(myComponent).toBeInTheDocument();
|
|
82
|
-
})
|
|
87
|
+
});
|
|
83
88
|
```
|
|
84
89
|
|
|
85
90
|
---
|
|
@@ -29,7 +29,7 @@ To regenerate snapshots, use the `--update-snapshots` flag.
|
|
|
29
29
|
|
|
30
30
|
```sh
|
|
31
31
|
$ bun test --update-snapshots
|
|
32
|
-
bun test v1.2.13-canary.
|
|
32
|
+
bun test v1.2.13-canary.20250510T141317 (9c68abdb)
|
|
33
33
|
|
|
34
34
|
test/snap.test.ts:
|
|
35
35
|
✓ snapshot [0.86ms]
|
package/docs/install/patch.md
CHANGED
package/docs/installation.md
CHANGED
|
@@ -14,7 +14,7 @@ Kernel version 5.6 or higher is strongly recommended, but the minimum is 5.1. Us
|
|
|
14
14
|
```bash#macOS/Linux_(curl)
|
|
15
15
|
$ curl -fsSL https://bun.sh/install | bash # for macOS, Linux, and WSL
|
|
16
16
|
# to install a specific version
|
|
17
|
-
$ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.13-canary.
|
|
17
|
+
$ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.13-canary.20250510T141317"
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
```bash#npm
|
|
@@ -189,10 +189,10 @@ Since Bun is a single binary, you can install older versions of Bun by re-runnin
|
|
|
189
189
|
|
|
190
190
|
### Installing a specific version of Bun on Linux/Mac
|
|
191
191
|
|
|
192
|
-
To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.13-canary.
|
|
192
|
+
To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.13-canary.20250510T141317`.
|
|
193
193
|
|
|
194
194
|
```sh
|
|
195
|
-
$ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.13-canary.
|
|
195
|
+
$ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.13-canary.20250510T141317"
|
|
196
196
|
```
|
|
197
197
|
|
|
198
198
|
### Installing a specific version of Bun on Windows
|
|
@@ -201,7 +201,7 @@ On Windows, you can install a specific version of Bun by passing the version num
|
|
|
201
201
|
|
|
202
202
|
```sh
|
|
203
203
|
# PowerShell:
|
|
204
|
-
$ iex "& {$(irm https://bun.sh/install.ps1)} -Version 1.2.13-canary.
|
|
204
|
+
$ iex "& {$(irm https://bun.sh/install.ps1)} -Version 1.2.13-canary.20250510T141317"
|
|
205
205
|
```
|
|
206
206
|
|
|
207
207
|
## Downloading Bun binaries directly
|
package/docs/runtime/bunfig.md
CHANGED
|
@@ -198,7 +198,6 @@ Set path where coverage reports will be saved. Please notice, that it works only
|
|
|
198
198
|
coverageDir = "path/to/somewhere" # default "coverage"
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
-
|
|
202
201
|
## Package manager
|
|
203
202
|
|
|
204
203
|
Package management is a complex issue; to support a range of use cases, the behavior of `bun install` can be configured under the `[install]` section.
|
package/docs/runtime/debugger.md
CHANGED
|
@@ -124,11 +124,11 @@ await fetch("https://example.com", {
|
|
|
124
124
|
This prints the `fetch` request as a single-line `curl` command to let you copy-paste into your terminal to replicate the request.
|
|
125
125
|
|
|
126
126
|
```sh
|
|
127
|
-
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.13-canary.
|
|
127
|
+
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.13-canary.20250510T141317" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
|
|
128
128
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
129
129
|
[fetch] > content-type: application/json
|
|
130
130
|
[fetch] > Connection: keep-alive
|
|
131
|
-
[fetch] > User-Agent: Bun/1.2.13-canary.
|
|
131
|
+
[fetch] > User-Agent: Bun/1.2.13-canary.20250510T141317
|
|
132
132
|
[fetch] > Accept: */*
|
|
133
133
|
[fetch] > Host: example.com
|
|
134
134
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
|
@@ -170,7 +170,7 @@ This prints the following to the console:
|
|
|
170
170
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
171
171
|
[fetch] > content-type: application/json
|
|
172
172
|
[fetch] > Connection: keep-alive
|
|
173
|
-
[fetch] > User-Agent: Bun/1.2.13-canary.
|
|
173
|
+
[fetch] > User-Agent: Bun/1.2.13-canary.20250510T141317
|
|
174
174
|
[fetch] > Accept: */*
|
|
175
175
|
[fetch] > Host: example.com
|
|
176
176
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
package/docs/runtime/hot.md
CHANGED
|
@@ -69,7 +69,6 @@ The **`--no-clear-screen`** flag is useful in scenarios where you don’t want t
|
|
|
69
69
|
|
|
70
70
|
{% /callout %}
|
|
71
71
|
|
|
72
|
-
|
|
73
72
|
## `--hot` mode
|
|
74
73
|
|
|
75
74
|
Use `bun --hot` to enable hot reloading when executing code with Bun. This is distinct from `--watch` mode in that Bun does not hard-restart the entire process. Instead, it detects code changes and updates its internal module cache with the new code.
|
package/docs/test/dom.md
CHANGED
package/docs/test/mocks.md
CHANGED
|
@@ -206,11 +206,13 @@ Understanding how `mock.module()` works helps you use it more effectively:
|
|
|
206
206
|
2. **Lazy Evaluation**: The mock factory callback is only evaluated when the module is actually imported or required.
|
|
207
207
|
|
|
208
208
|
3. **Path Resolution**: Bun automatically resolves the module specifier as though you were doing an import, supporting:
|
|
209
|
+
|
|
209
210
|
- Relative paths (`'./module'`)
|
|
210
211
|
- Absolute paths (`'/path/to/module'`)
|
|
211
212
|
- Package names (`'lodash'`)
|
|
212
213
|
|
|
213
|
-
4. **Import Timing Effects**:
|
|
214
|
+
4. **Import Timing Effects**:
|
|
215
|
+
|
|
214
216
|
- When mocking before first import: No side effects from the original module occur
|
|
215
217
|
- When mocking after import: The original module's side effects have already happened
|
|
216
218
|
- For this reason, using `--preload` is recommended for mocks that need to prevent side effects
|
|
@@ -232,15 +234,15 @@ const random2 = mock(() => Math.random());
|
|
|
232
234
|
test("clearing all mocks", () => {
|
|
233
235
|
random1();
|
|
234
236
|
random2();
|
|
235
|
-
|
|
237
|
+
|
|
236
238
|
expect(random1).toHaveBeenCalledTimes(1);
|
|
237
239
|
expect(random2).toHaveBeenCalledTimes(1);
|
|
238
|
-
|
|
240
|
+
|
|
239
241
|
mock.clearAllMocks();
|
|
240
|
-
|
|
242
|
+
|
|
241
243
|
expect(random1).toHaveBeenCalledTimes(0);
|
|
242
244
|
expect(random2).toHaveBeenCalledTimes(0);
|
|
243
|
-
|
|
245
|
+
|
|
244
246
|
// Note: implementations are preserved
|
|
245
247
|
expect(typeof random1()).toBe("number");
|
|
246
248
|
expect(typeof random2()).toBe("number");
|
|
@@ -258,18 +260,18 @@ Using `mock.restore()` can reduce the amount of code in your tests by adding it
|
|
|
258
260
|
```ts
|
|
259
261
|
import { expect, mock, spyOn, test } from "bun:test";
|
|
260
262
|
|
|
261
|
-
import * as fooModule from
|
|
262
|
-
import * as barModule from
|
|
263
|
-
import * as bazModule from
|
|
263
|
+
import * as fooModule from "./foo.ts";
|
|
264
|
+
import * as barModule from "./bar.ts";
|
|
265
|
+
import * as bazModule from "./baz.ts";
|
|
264
266
|
|
|
265
|
-
test(
|
|
266
|
-
const fooSpy = spyOn(fooModule,
|
|
267
|
-
const barSpy = spyOn(barModule,
|
|
268
|
-
const bazSpy = spyOn(bazModule,
|
|
267
|
+
test("foo, bar, baz", () => {
|
|
268
|
+
const fooSpy = spyOn(fooModule, "foo");
|
|
269
|
+
const barSpy = spyOn(barModule, "bar");
|
|
270
|
+
const bazSpy = spyOn(bazModule, "baz");
|
|
269
271
|
|
|
270
|
-
expect(fooSpy).toBe(
|
|
271
|
-
expect(barSpy).toBe(
|
|
272
|
-
expect(bazSpy).toBe(
|
|
272
|
+
expect(fooSpy).toBe("foo");
|
|
273
|
+
expect(barSpy).toBe("bar");
|
|
274
|
+
expect(bazSpy).toBe("baz");
|
|
273
275
|
|
|
274
276
|
fooSpy.mockImplementation(() => 42);
|
|
275
277
|
barSpy.mockImplementation(() => 43);
|
|
@@ -281,9 +283,9 @@ test('foo, bar, baz', () => {
|
|
|
281
283
|
|
|
282
284
|
mock.restore();
|
|
283
285
|
|
|
284
|
-
expect(fooSpy).toBe(
|
|
285
|
-
expect(barSpy).toBe(
|
|
286
|
-
expect(bazSpy).toBe(
|
|
286
|
+
expect(fooSpy).toBe("foo");
|
|
287
|
+
expect(barSpy).toBe("bar");
|
|
288
|
+
expect(bazSpy).toBe("baz");
|
|
287
289
|
});
|
|
288
290
|
```
|
|
289
291
|
|
|
@@ -297,10 +299,10 @@ import { test, expect } from "bun:test";
|
|
|
297
299
|
// Using the 'vi' alias similar to Vitest
|
|
298
300
|
test("vitest compatibility", () => {
|
|
299
301
|
const mockFn = vi.fn(() => 42);
|
|
300
|
-
|
|
302
|
+
|
|
301
303
|
mockFn();
|
|
302
304
|
expect(mockFn).toHaveBeenCalled();
|
|
303
|
-
|
|
305
|
+
|
|
304
306
|
// The following functions are available on the vi object:
|
|
305
307
|
// vi.fn
|
|
306
308
|
// vi.spyOn
|
package/docs/test/time.md
CHANGED
|
@@ -84,10 +84,10 @@ import { test, expect, jest } from "bun:test";
|
|
|
84
84
|
test("get the current mocked time", () => {
|
|
85
85
|
jest.useFakeTimers();
|
|
86
86
|
jest.setSystemTime(new Date("2020-01-01T00:00:00.000Z"));
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
expect(Date.now()).toBe(1577836800000); // Jan 1, 2020 timestamp
|
|
89
89
|
expect(jest.now()).toBe(1577836800000); // Same value
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
jest.useRealTimers();
|
|
92
92
|
});
|
|
93
93
|
```
|
package/package.json
CHANGED
package/redis.d.ts
CHANGED
|
@@ -110,10 +110,17 @@ declare module "bun" {
|
|
|
110
110
|
/**
|
|
111
111
|
* Get the value of a key
|
|
112
112
|
* @param key The key to get
|
|
113
|
-
* @returns Promise that resolves with the key's value, or null if the key doesn't exist
|
|
113
|
+
* @returns Promise that resolves with the key's value as a string, or null if the key doesn't exist
|
|
114
114
|
*/
|
|
115
115
|
get(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Get the value of a key as a Uint8Array
|
|
119
|
+
* @param key The key to get
|
|
120
|
+
* @returns Promise that resolves with the key's value as a Uint8Array, or null if the key doesn't exist
|
|
121
|
+
*/
|
|
122
|
+
getBuffer(key: string | ArrayBufferView | Blob): Promise<Uint8Array<ArrayBuffer> | null>;
|
|
123
|
+
|
|
117
124
|
/**
|
|
118
125
|
* Set key to hold the string value
|
|
119
126
|
* @param key The key to set
|