mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(cli/tools): correct deno init --serve
template behavior (#25318)
This commit is contained in:
parent
f6eab6c4bd
commit
2533d68cab
2 changed files with 16 additions and 7 deletions
|
@ -37,7 +37,7 @@ const routes: Route[] = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: new URLPattern({ pathname: "/static/*" }),
|
pattern: new URLPattern({ pathname: "/static/*" }),
|
||||||
handler: (req) => serveDir(req, { urlRoot: "./" }),
|
handler: (req) => serveDir(req),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -52,7 +52,6 @@ export default {
|
||||||
return handler(req);
|
return handler(req);
|
||||||
},
|
},
|
||||||
} satisfies Deno.ServeDefaultExport;
|
} satisfies Deno.ServeDefaultExport;
|
||||||
|
|
||||||
"#,
|
"#,
|
||||||
)?;
|
)?;
|
||||||
create_file(
|
create_file(
|
||||||
|
@ -80,13 +79,23 @@ Deno.test(async function serverFetchUsers() {
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test(async function serverFetchStatic() {
|
Deno.test(async function serverFetchStatic() {
|
||||||
const req = new Request("https://deno.land/static/main.ts");
|
const req = new Request("https://deno.land/static/hello.js");
|
||||||
const res = await server.fetch(req);
|
const res = await server.fetch(req);
|
||||||
assertEquals(res.headers.get("content-type"), "text/plain;charset=UTF-8");
|
assertEquals(await res.text(), 'console.log("Hello, world!");\n');
|
||||||
|
assertEquals(res.headers.get("content-type"), "text/javascript; charset=UTF-8");
|
||||||
});
|
});
|
||||||
"#,
|
"#,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
let static_dir = dir.join("static");
|
||||||
|
std::fs::create_dir_all(&static_dir)?;
|
||||||
|
create_file(
|
||||||
|
&static_dir,
|
||||||
|
"hello.js",
|
||||||
|
r#"console.log("Hello, world!");
|
||||||
|
"#,
|
||||||
|
)?;
|
||||||
|
|
||||||
create_json_file(
|
create_json_file(
|
||||||
&dir,
|
&dir,
|
||||||
"deno.json",
|
"deno.json",
|
||||||
|
@ -203,7 +212,7 @@ Deno.test(function addTest() {
|
||||||
info!(" deno task dev");
|
info!(" deno task dev");
|
||||||
info!("");
|
info!("");
|
||||||
info!(" {}", colors::gray("# Run the tests"));
|
info!(" {}", colors::gray("# Run the tests"));
|
||||||
info!(" deno -R test");
|
info!(" deno test -R");
|
||||||
} else if init_flags.lib {
|
} else if init_flags.lib {
|
||||||
info!(" {}", colors::gray("# Run the tests"));
|
info!(" {}", colors::gray("# Run the tests"));
|
||||||
info!(" deno test");
|
info!(" deno test");
|
||||||
|
|
|
@ -188,7 +188,7 @@ async fn init_subcommand_serve() {
|
||||||
assert_contains!(stderr, "Project initialized");
|
assert_contains!(stderr, "Project initialized");
|
||||||
assert_contains!(stderr, "deno serve -R main.ts");
|
assert_contains!(stderr, "deno serve -R main.ts");
|
||||||
assert_contains!(stderr, "deno task dev");
|
assert_contains!(stderr, "deno task dev");
|
||||||
assert_contains!(stderr, "deno -R test");
|
assert_contains!(stderr, "deno test -R");
|
||||||
|
|
||||||
assert!(cwd.join("deno.json").exists());
|
assert!(cwd.join("deno.json").exists());
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ async fn init_subcommand_serve() {
|
||||||
let output = context
|
let output = context
|
||||||
.new_command()
|
.new_command()
|
||||||
.env("NO_COLOR", "1")
|
.env("NO_COLOR", "1")
|
||||||
.args("-R test")
|
.args("test -R")
|
||||||
.split_output()
|
.split_output()
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue