-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Move the CLI script endpoint to /cli"
- Loading branch information
Showing
7 changed files
with
113 additions
and
122 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
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 |
---|---|---|
|
@@ -20,7 +20,7 @@ async function startServer(onStart: () => Promise<void>, single: boolean) { | |
const status = await res.json(); | ||
if (status.ns === "READY") { | ||
console.log("esm.sh server started."); | ||
await onStart(); | ||
onStart(); | ||
break; | ||
} | ||
} catch (_) { | ||
|
@@ -62,68 +62,6 @@ async function runTest(name: string, retry?: boolean): Promise<number> { | |
return Date.now() - execBegin; | ||
} | ||
|
||
async function runCliTest() { | ||
console.log(`\n[test CLI]`); | ||
|
||
const cwd = await Deno.makeTempDir(); | ||
await Deno.writeTextFile( | ||
cwd + "/deno.json", | ||
`{"importMap": "import-map.json"}`, | ||
); | ||
|
||
const res = await fetch("http://localhost:8080/"); | ||
if (!res.headers.get("content-type")?.startsWith("application/typescript")) { | ||
throw new Error(`Invalid content type: ${res.headers.get("content-type")}`); | ||
} | ||
|
||
const p = new Deno.Command(Deno.execPath(), { | ||
args: [ | ||
"run", | ||
"-A", | ||
"-r", | ||
"--no-lock", | ||
"http://localhost:8080/v100/cli", | ||
"add", | ||
"[email protected]", | ||
"[email protected]", | ||
"react:[email protected]/compat", | ||
"[email protected]", | ||
], | ||
cwd, | ||
stdout: "inherit", | ||
stderr: "inherit", | ||
}).spawn(); | ||
const { code, success } = await p.status; | ||
if (!success) { | ||
Deno.exit(code); | ||
} | ||
|
||
const imRaw = await Deno.readTextFile(cwd + "/import-map.json"); | ||
const im = JSON.parse(imRaw); | ||
if ( | ||
JSON.stringify(im) !== JSON.stringify({ | ||
imports: { | ||
"preact-render-to-string": | ||
"http://localhost:8080/v100/*[email protected]", | ||
"preact-render-to-string/": | ||
"http://localhost:8080/v100/*[email protected]/", | ||
preact: "http://localhost:8080/v100/[email protected]", | ||
"preact/": "http://localhost:8080/v100/[email protected]/", | ||
react: "http://localhost:8080/v100/[email protected]/compat", | ||
swr: "http://localhost:8080/v100/*[email protected]", | ||
"swr/": "http://localhost:8080/v100/*[email protected]/", | ||
}, | ||
scopes: { | ||
"http://localhost:8080/v100/": { | ||
"pretty-format": "http://localhost:8080/v100/[email protected]", | ||
}, | ||
}, | ||
}) | ||
) { | ||
console.log(im); | ||
throw new Error("Invalid import maps generated"); | ||
} | ||
} | ||
|
||
function run(name: string, ...args: string[]) { | ||
const p = new Deno.Command(name, { | ||
|
@@ -168,7 +106,6 @@ if (import.meta.main) { | |
if (testDir) { | ||
timeUsed += await runTest(testDir, true); | ||
} else { | ||
await runCliTest(); | ||
for await (const entry of Deno.readDir("./test")) { | ||
if (entry.isDirectory && !entry.name.startsWith("_")) { | ||
timeUsed += await runTest(entry.name); | ||
|
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
assert, | ||
assertEquals, | ||
} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
|
||
Deno.test("CLI script", async () => { | ||
const cwd = await Deno.makeTempDir(); | ||
await Deno.writeTextFile( | ||
cwd + "/deno.json", | ||
`{"importMap": "import-map.json"}`, | ||
); | ||
|
||
const res = await fetch("http://localhost:8080/"); | ||
await res.body?.cancel(); | ||
assertEquals(res.status, 200); | ||
assertEquals(res.headers.get("content-type"), "application/typescript; charset=utf-8"); | ||
|
||
const p = new Deno.Command(Deno.execPath(), { | ||
args: [ | ||
"run", | ||
"-A", | ||
"-r", | ||
"--no-lock", | ||
"http://localhost:8080/v100", | ||
"add", | ||
"[email protected]", | ||
"[email protected]", | ||
"react:[email protected]/compat", | ||
"[email protected]", | ||
], | ||
cwd, | ||
stdout: "inherit", | ||
stderr: "inherit", | ||
}).spawn(); | ||
const { success } = await p.status; | ||
assert(success); | ||
|
||
const imRaw = await Deno.readTextFile(cwd + "/import-map.json"); | ||
const im = JSON.parse(imRaw); | ||
assertEquals(im, { | ||
imports: { | ||
"preact-render-to-string": | ||
"http://localhost:8080/v100/*[email protected]", | ||
"preact-render-to-string/": | ||
"http://localhost:8080/v100/*[email protected]/", | ||
preact: "http://localhost:8080/v100/[email protected]", | ||
"preact/": "http://localhost:8080/v100/[email protected]/", | ||
react: "http://localhost:8080/v100/[email protected]/compat", | ||
swr: "http://localhost:8080/v100/*[email protected]", | ||
"swr/": "http://localhost:8080/v100/*[email protected]/", | ||
}, | ||
scopes: { | ||
"http://localhost:8080/v100/": { | ||
"pretty-format": "http://localhost:8080/v100/[email protected]", | ||
}, | ||
}, | ||
}); | ||
}); |