@@ -22,6 +22,7 @@ import denoConfig from "./deno.json" with { type: "json" };
22
22
import { MINUTE } from "@std/datetime/constants" ;
23
23
import { getAvailablePort } from "@std/net/get-available-port" ;
24
24
import { concat } from "@std/bytes/concat" ;
25
+ import { lessThan , parse as parseSemver } from "@std/semver" ;
25
26
26
27
const moduleDir = dirname ( fromFileUrl ( import . meta. url ) ) ;
27
28
const testdataDir = resolve ( moduleDir , "testdata" ) ;
@@ -32,6 +33,11 @@ const serveDirOptions: ServeDirOptions = {
32
33
showDotfiles : true ,
33
34
enableCors : true ,
34
35
} ;
36
+ const denoVersion = parseSemver ( Deno . version . deno ) ;
37
+ const isCanary = denoVersion . build ? denoVersion . build . length > 0 : false ;
38
+ // FileInfo.mode is not available on Windows before Deno 2.1.0
39
+ const fsModeUnavailable = Deno . build . os === "windows" &&
40
+ lessThan ( denoVersion , parseSemver ( "2.1.0" ) ) && ! isCanary ;
35
41
36
42
const TEST_FILE_PATH = join ( testdataDir , "test_file.txt" ) ;
37
43
const TEST_FILE_STAT = await Deno . stat ( TEST_FILE_PATH ) ;
@@ -188,10 +194,7 @@ Deno.test("serveDir() serves directory index", async () => {
188
194
assertStringIncludes ( page , '<a href="/hello.html">hello.html</a>' ) ;
189
195
assertStringIncludes ( page , '<a href="/tls/">tls/</a>' ) ;
190
196
assertStringIncludes ( page , "%2525A.txt" ) ;
191
- // `Deno.FileInfo` is not completely compatible with Windows yet
192
- // TODO(bartlomieju): `mode` should work correctly in the future.
193
- // Correct this test case accordingly.
194
- if ( Deno . build . os === "windows" ) {
197
+ if ( fsModeUnavailable ) {
195
198
assertMatch ( page , / < t d c l a s s = " m o d e " > ( \s ) * \( u n k n o w n m o d e \) ( \s ) * < \/ t d > / ) ;
196
199
} else {
197
200
assertMatch ( page , / < t d c l a s s = " m o d e " > ( \s ) * [ a - z A - Z - ] { 14 } ( \s ) * < \/ t d > / ) ;
@@ -212,10 +215,7 @@ Deno.test("serveDir() serves directory index with file containing space in the f
212
215
assertStringIncludes ( page , '<a href="/hello.html">hello.html</a>' ) ;
213
216
assertStringIncludes ( page , '<a href="/tls/">tls/</a>' ) ;
214
217
assertStringIncludes ( page , "test%20file.txt" ) ;
215
- // `Deno.FileInfo` is not completely compatible with Windows yet
216
- // TODO(bartlomieju): `mode` should work correctly in the future.
217
- // Correct this test case accordingly.
218
- if ( Deno . build . os === "windows" ) {
218
+ if ( fsModeUnavailable ) {
219
219
assertMatch ( page , / < t d c l a s s = " m o d e " > ( \s ) * \( u n k n o w n m o d e \) ( \s ) * < \/ t d > / ) ;
220
220
} else {
221
221
assertMatch ( page , / < t d c l a s s = " m o d e " > ( \s ) * [ a - z A - Z - ] { 14 } ( \s ) * < \/ t d > / ) ;
0 commit comments