-
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
transformOnly
option for build api
- Loading branch information
Showing
3 changed files
with
76 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,30 +6,6 @@ import { | |
import { build, esm } from "http://localhost:8080/build"; | ||
|
||
Deno.test("build api", async (t) => { | ||
let url = ""; | ||
let bundleUrl = ""; | ||
await t.step("build", async () => { | ||
const ret = await fetch("http://localhost:8080/build", { | ||
method: "POST", | ||
headers: { "Content-Type": "application/javascript" }, | ||
body: `export default "Hello world!";`, | ||
}).then((r) => r.json()); | ||
if (ret.error) { | ||
throw new Error(`<${ret.error.status}> ${ret.error.message}`); | ||
} | ||
url = ret.url; | ||
bundleUrl = ret.bundleUrl; | ||
assertStringIncludes(url, "/~"); | ||
assertStringIncludes(bundleUrl, "?bundle"); | ||
}); | ||
|
||
await t.step("import published module", async () => { | ||
const { default: message } = await import(url); | ||
assertEquals(message, "Hello world!"); | ||
}); | ||
}); | ||
|
||
Deno.test("build api (json)", async (t) => { | ||
let url = ""; | ||
let bundleUrl = ""; | ||
await t.step("build", async () => { | ||
|
@@ -42,6 +18,7 @@ Deno.test("build api (json)", async (t) => { | |
import { renderToString } from "npm:[email protected]"; | ||
export default () => renderToString(<h1>Hello world!</h1>); | ||
`, | ||
loader: "jsx", | ||
}), | ||
}).then((r) => r.json()); | ||
if (ret.error) { | ||
|
@@ -61,7 +38,7 @@ Deno.test("build api (json)", async (t) => { | |
}); | ||
}); | ||
|
||
Deno.test("build api (with types)", async (t) => { | ||
Deno.test("build api (with options)", async () => { | ||
const ret = await fetch("http://localhost:8080/build", { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
|
@@ -86,6 +63,23 @@ Deno.test("build api (with types)", async (t) => { | |
assertEquals(typeof mod.h, "function"); | ||
}); | ||
|
||
Deno.test("build api (transformOnly)", async () => { | ||
const ret = await fetch("http://localhost:8080/build", { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
code: ` | ||
const n:number = 42; | ||
`, | ||
transformOnly: true, | ||
}), | ||
}).then((r) => r.json()); | ||
if (ret.error) { | ||
throw new Error(`<${ret.error.status}> ${ret.error.message}`); | ||
} | ||
assertEquals(ret.code, "const n=42;\n"); | ||
}); | ||
|
||
Deno.test("build api (use sdk)", async (t) => { | ||
await t.step("use `build` function", async () => { | ||
const ret = await build(`export default "Hello world!";`); | ||
|