diff --git a/cli/tests/unit/file_test.ts b/cli/tests/unit/file_test.ts index 23583ac2ec..26ee110b68 100644 --- a/cli/tests/unit/file_test.ts +++ b/cli/tests/unit/file_test.ts @@ -99,3 +99,14 @@ Deno.test(function fileUsingNumberFileName() { Deno.test(function fileUsingEmptyStringFileName() { testSecondArgument("", ""); }); + +Deno.test(function inspectFile() { + assertEquals( + Deno.inspect(new File([], "file-name.txt")), + `File { name: "file-name.txt", size: 0, type: "" }`, + ); + assertEquals( + Deno.inspect(new File([], "file-name.txt", { type: "text/plain" })), + `File { name: "file-name.txt", size: 0, type: "text/plain" }`, + ); +}); diff --git a/ext/web/09_file.js b/ext/web/09_file.js index 94981a2f42..fd0451438d 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -535,6 +535,18 @@ class File extends Blob { webidl.assertBranded(this, FilePrototype); return this[_LastModified]; } + + [SymbolFor("Deno.customInspect")](inspect) { + return inspect(createFilteredInspectProxy({ + object: this, + evaluate: ObjectPrototypeIsPrototypeOf(FilePrototype, this), + keys: [ + "name", + "size", + "type", + ], + })); + } } webidl.configurePrototype(File);