oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.71k stars 2.72k forks source link

`new File()` inconsistent behavior with NodeJS #13137

Open jasongitmail opened 2 months ago

jasongitmail commented 2 months ago

What version of Bun is running?

1.1.21+70ca2b76c

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

Start a node repl and a bun repl, and then:

const file = new File([], "empty.txt", { type: "text/plain" })
file.name
file.size
file.type

Results:

file

What is the expected behavior?

Expected to match NodeJS's behavior:

const file = new File([], "empty.txt", { type: "text/plain" })
file.name // "empty.txt"
file.size // 0 
file.type // text/plain

What do you see instead?

Actual output with Bun:

const file = new File([], "empty.txt", { type: "text/plain" })
file.name // undefined
file.size // 0 
file.type // text/plain;charset=utf-8

Additional information

Despite Bun's repl warning, this is not repl related.

I encountered this in my unit tests using bun:test. Then reproduced it in the repl to demonstrate it.

It's small, but "if it doesn't match Node it's a bug", so I wanted to report it.

Electroid commented 2 months ago

Can you try with bun upgrade --canary, pretty sure we fixed this bug recently but haven't released it yet.

jasongitmail commented 2 months ago

I upgraded to canary and received the same result in the repl. Still has the reported issue with name and type.

bun
huseeiin commented 2 months ago

this only happens with [] (empty) files

jasongitmail commented 2 months ago

yep, my other tests for non-empty files pass consistently between and node