From 03dffde3adb3bc2c7ab67c9aadd594e2f27cfb57 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 13 Nov 2024 19:16:17 +0900 Subject: [PATCH] chore: update FileInfo fixture (#6181) --- http/etag_test.ts | 3 ++- http/file_server_test.ts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/http/etag_test.ts b/http/etag_test.ts index fef8096b7546..deb19eb448ef 100644 --- a/http/etag_test.ts +++ b/http/etag_test.ts @@ -42,13 +42,14 @@ Deno.test({ Deno.test({ name: "eTag() handles Deno.FileInfo", async fn() { - const fixture: Deno.FileInfo = { + const fixture = { isFile: true, isDirectory: false, isSymlink: false, size: 1024, mtime: new Date(Date.UTC(96, 1, 2, 3, 4, 5, 6)), atime: null, + ctime: null, birthtime: null, dev: 0, ino: null, diff --git a/http/file_server_test.ts b/http/file_server_test.ts index 55f5d564ee7a..27fa7ec40f69 100644 --- a/http/file_server_test.ts +++ b/http/file_server_test.ts @@ -22,6 +22,7 @@ import denoConfig from "./deno.json" with { type: "json" }; import { MINUTE } from "@std/datetime/constants"; import { getAvailablePort } from "@std/net/get-available-port"; import { concat } from "@std/bytes/concat"; +import { lessThan, parse as parseSemver } from "@std/semver"; const moduleDir = dirname(fromFileUrl(import.meta.url)); const testdataDir = resolve(moduleDir, "testdata"); @@ -32,6 +33,11 @@ const serveDirOptions: ServeDirOptions = { showDotfiles: true, enableCors: true, }; +const denoVersion = parseSemver(Deno.version.deno); +const isCanary = denoVersion.build ? denoVersion.build.length > 0 : false; +// FileInfo.mode is not available on Windows before Deno 2.1.0 +const fsModeUnavailable = Deno.build.os === "windows" && + lessThan(denoVersion, parseSemver("2.1.0")) && !isCanary; const TEST_FILE_PATH = join(testdataDir, "test_file.txt"); const TEST_FILE_STAT = await Deno.stat(TEST_FILE_PATH); @@ -188,10 +194,7 @@ Deno.test("serveDir() serves directory index", async () => { assertStringIncludes(page, 'hello.html'); assertStringIncludes(page, 'tls/'); assertStringIncludes(page, "%2525A.txt"); - // `Deno.FileInfo` is not completely compatible with Windows yet - // TODO(bartlomieju): `mode` should work correctly in the future. - // Correct this test case accordingly. - if (Deno.build.os === "windows") { + if (fsModeUnavailable) { assertMatch(page, /(\s)*\(unknown mode\)(\s)*<\/td>/); } else { assertMatch(page, /(\s)*[a-zA-Z- ]{14}(\s)*<\/td>/); @@ -212,10 +215,7 @@ Deno.test("serveDir() serves directory index with file containing space in the f assertStringIncludes(page, 'hello.html'); assertStringIncludes(page, 'tls/'); assertStringIncludes(page, "test%20file.txt"); - // `Deno.FileInfo` is not completely compatible with Windows yet - // TODO(bartlomieju): `mode` should work correctly in the future. - // Correct this test case accordingly. - if (Deno.build.os === "windows") { + if (fsModeUnavailable) { assertMatch(page, /(\s)*\(unknown mode\)(\s)*<\/td>/); } else { assertMatch(page, /(\s)*[a-zA-Z- ]{14}(\s)*<\/td>/);