1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 08:39:09 -05:00

fix(std): use fromFileUrl (#5005)

This commit is contained in:
Ali Hasani 2020-04-30 15:17:53 +04:30 committed by GitHub
parent 4bc9c18fe9
commit c569d958aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 16 deletions

View file

@ -5,6 +5,7 @@ import {
WebSocket, WebSocket,
isWebSocketCloseEvent, isWebSocketCloseEvent,
} from "../../ws/mod.ts"; } from "../../ws/mod.ts";
import { fromFileUrl } from "../../path/mod.ts";
const clients = new Map<number, WebSocket>(); const clients = new Map<number, WebSocket>();
let clientId = 0; let clientId = 0;
@ -47,7 +48,7 @@ listenAndServe({ port: 8080 }, async (req) => {
}); });
} else { } else {
// server launched by deno run ./server.ts // server launched by deno run ./server.ts
const file = await Deno.open(u.pathname); const file = await Deno.open(fromFileUrl(u));
req.respond({ req.respond({
status: 200, status: 200,
headers: new Headers({ headers: new Headers({

View file

@ -5,7 +5,7 @@ import { BufReader } from "../../io/bufio.ts";
import { connectWebSocket, WebSocket } from "../../ws/mod.ts"; import { connectWebSocket, WebSocket } from "../../ws/mod.ts";
import { delay } from "../../util/async.ts"; import { delay } from "../../util/async.ts";
const { test, build } = Deno; const { test } = Deno;
async function startServer(): Promise<Deno.Process> { async function startServer(): Promise<Deno.Process> {
const server = Deno.run({ const server = Deno.run({
@ -26,12 +26,8 @@ async function startServer(): Promise<Deno.Process> {
return server; return server;
} }
// TODO: https://github.com/denoland/deno/issues/4108
const ignore = build.os == "windows";
test({ test({
ignore, name: "[examples/chat] GET / should serve html",
name: "GET / should serve html",
async fn() { async fn() {
const server = await startServer(); const server = await startServer();
try { try {
@ -49,8 +45,7 @@ test({
}); });
test({ test({
ignore, name: "[examples/chat] GET /ws should upgrade conn to ws",
name: "GET /ws should upgrade conn to ws",
async fn() { async fn() {
const server = await startServer(); const server = await startServer();
let ws: WebSocket | undefined; let ws: WebSocket | undefined;

View file

@ -2,11 +2,11 @@ const { cwd, execPath, run } = Deno;
import { decode } from "../encoding/utf8.ts"; import { decode } from "../encoding/utf8.ts";
import { assert, assertEquals, assertStrContains } from "../testing/asserts.ts"; import { assert, assertEquals, assertStrContains } from "../testing/asserts.ts";
import { import {
isWindows,
join, join,
joinGlobs, joinGlobs,
normalize, normalize,
relative, relative,
fromFileUrl,
} from "../path/mod.ts"; } from "../path/mod.ts";
import { import {
ExpandGlobOptions, ExpandGlobOptions,
@ -39,13 +39,8 @@ async function expandGlobArray(
return relativePaths; return relativePaths;
} }
function urlToFilePath(url: URL): string {
// Since `new URL('file:///C:/a').pathname` is `/C:/a`, remove leading slash.
return url.pathname.slice(url.protocol == "file:" && isWindows ? 1 : 0);
}
const EG_OPTIONS: ExpandGlobOptions = { const EG_OPTIONS: ExpandGlobOptions = {
root: urlToFilePath(new URL(join("testdata", "glob"), import.meta.url)), root: fromFileUrl(new URL(join("testdata", "glob"), import.meta.url)),
includeDirs: true, includeDirs: true,
extended: false, extended: false,
globstar: false, globstar: false,