Skip to content

Commit

Permalink
Move testings
Browse files Browse the repository at this point in the history
  • Loading branch information
ije committed Sep 2, 2024
1 parent c9e5e55 commit 04557f7
Show file tree
Hide file tree
Showing 90 changed files with 42 additions and 68 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.DS_Store
.idea/
.vscode/
*.log
config.json
esmd
.esmd/
node_modules/
dist/
*.log
config.json
!test/config.json
esmd
12 changes: 5 additions & 7 deletions test/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function startServer(onStart: () => Promise<void>, verbose: boolean) {
Deno.exit(code);
}
const p = new Deno.Command("./esmd", {
args: ["--debug"],
args: ["--config", "test/config.json", "--debug"],
stdout: verbose ? "inherit" : "null",
stderr: "inherit",
}).spawn();
Expand Down Expand Up @@ -85,18 +85,16 @@ async function existsFile(path: string): Promise<boolean> {
}

if (import.meta.main) {
const rootDir = new URL(import.meta.url).pathname.split("/").slice(0, -2)
.join("/");
Deno.chdir(rootDir);
Deno.chdir(new URL("../", import.meta.url).pathname);
const tests = Deno.args.filter((arg) => !arg.startsWith("-"));
const clean = Deno.args.includes("--clean");
if (clean) {
try {
console.log("Cleaning up...");
await Promise.all([
Deno.remove("./.esmd/log", { recursive: true }),
Deno.remove("./.esmd/storage", { recursive: true }),
Deno.remove("./.esmd/esm.db"),
Deno.remove(".esmd/log", { recursive: true }),
Deno.remove(".esmd/storage", { recursive: true }),
Deno.remove(".esmd/esm.db"),
]);
} catch (_) {
// ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, assertEquals } from "jsr:@std/assert";

Deno.test("package css", async () => {
Deno.test("?css", async () => {
const res = await fetch("http://localhost:8080/[email protected]?css&target=es2022", { redirect: "manual" });
assertEquals(res.status, 301);
assertEquals(res.headers.get("location"), "http://localhost:8080/[email protected]/es2022/monaco-editor.css");
Expand Down
28 changes: 16 additions & 12 deletions test/build-args/external.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
import { assertEquals, assertStringIncludes } from "jsr:@std/assert";

function fetchModule(path: string) {
return fetch(`http://localhost:8080/${path}`);
}

Deno.test("`?external` query", async () => {
const res1 = await fetch("http://localhost:8080/[email protected]?external=react");
const res1 = await fetchModule("[email protected]?external=react");
const code1 = await res1.text();
assertStringIncludes(code1, '"/[email protected]/X-ZXJlYWN0/denonext/react-dom.mjs"');

const res2 = await fetch("http://localhost:8080/*[email protected]/jsx-runtime");
const res2 = await fetchModule("*[email protected]/jsx-runtime");
const code2 = await res2.text();
assertStringIncludes(code2, '"/[email protected]/X-Kg/denonext/jsx-runtime.js"');

const res3 = await fetch("http://localhost:8080/[email protected]/hooks?external=preact");
const res3 = await fetchModule("[email protected]/hooks?external=preact");
const code3 = await res3.text();
assertStringIncludes(code3, '"/[email protected]/X-ZXByZWFjdA/denonext/hooks.js"');
});

Deno.test("drop invalid `?external`", async () => {
const res1 = await fetch("http://localhost:8080/[email protected]?target=es2022&external=foo,bar,react");
const res1 = await fetchModule("[email protected]?target=es2022&external=foo,bar,react");
const code1 = await res1.text();
assertStringIncludes(code1, '"/[email protected]/X-ZXJlYWN0/es2022/react-dom.mjs"');

const res2 = await fetch("http://localhost:8080/[email protected]?target=es2022&external=foo,bar,preact");
const res2 = await fetchModule("[email protected]?target=es2022&external=foo,bar,preact");
const code2 = await res2.text();
assertStringIncludes(code2, '"/[email protected]/es2022/react-dom.mjs"');

const res3 = await fetch("http://localhost:8080/[email protected]?external=react-dom");
const res3 = await fetchModule("[email protected]?external=react-dom");
const code3 = await res3.text();
assertStringIncludes(code3, '"/[email protected]/denonext/react-dom.mjs"');
});

Deno.test("types with `?external`", async () => {
const res = await fetch("http://localhost:8080/[email protected]/X-ZXJlYWN0/dist/use-swr.d.ts");
const res = await fetchModule("[email protected]/X-ZXJlYWN0/dist/use-swr.d.ts");
assertEquals(res.status, 200);
assertEquals(res.headers.get("Content-type"), "application/typescript; charset=utf-8");
const ts = await res.text();
Expand All @@ -38,21 +42,21 @@ Deno.test("types with `?external`", async () => {
});

Deno.test("external nodejs internal modules", async () => {
const res = await fetch("http://localhost:8080/[email protected]/es2022/cheerio.mjs");
const res = await fetchModule("[email protected]/es2022/cheerio.mjs");
assertEquals(res.status, 200);
assertStringIncludes(await res.text(), ` from "/node/buffer.js"`);

const res2 = await fetch("http://localhost:8080/[email protected]?target=es2022&external=node:buffer");
const res2 = await fetchModule("[email protected]?target=es2022&external=node:buffer");
res2.body?.cancel();
assertEquals(res2.status, 200);
const res3 = await fetch("http://localhost:8080/" + res2.headers.get("x-esm-path"));
const res3 = await fetchModule("" + res2.headers.get("x-esm-path"));
assertEquals(res3.status, 200);
assertStringIncludes(await res3.text(), ` from "node:buffer"`);

const res4 = await fetch("http://localhost:8080/*[email protected]?target=es2022");
const res4 = await fetchModule("*[email protected]?target=es2022");
res4.body?.cancel();
assertEquals(res4.status, 200);
const res5 = await fetch("http://localhost:8080/" + res4.headers.get("x-esm-path"));
const res5 = await fetchModule("" + res4.headers.get("x-esm-path"));
assertEquals(res5.status, 200);
assertStringIncludes(await res5.text(), ` from "node:buffer"`);
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions test/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"buildTimeout": 600,
"workDir": ".esmd"
}
8 changes: 0 additions & 8 deletions test/issue-420/deno.json

This file was deleted.

18 changes: 0 additions & 18 deletions test/issue-765/test.ts

This file was deleted.

5 changes: 0 additions & 5 deletions test/issue-847/deno.json

This file was deleted.

9 changes: 2 additions & 7 deletions test/issue-817/deno.json → test/issues/deno.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
{
"compilerOptions": {
"lib": [
"dom",
"deno.ns"
]
},
"imports": {
"esm.sh/": "http://localhost:8080/",
"react": "http://localhost:8080/[email protected]",
"react/": "http://localhost:8080/[email protected]/",
"react/jsx-runtime": "http://localhost:8080/[email protected]/jsx-runtime",
"react-dom": "http://localhost:8080/[email protected]"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions test/issues/issue-765.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { assertStringIncludes } from "jsr:@std/assert";

Deno.test("issue #765", async () => {
const dts = await fetch("http://localhost:8080/[email protected]/index.d.mts").then((res) => res.text());
assertStringIncludes(dts, "http://localhost:8080/[email protected]/resources/index.d.ts");

const dts2 = await fetch("http://localhost:8080/[email protected]/resources/index.d.ts").then((res) => res.text());
assertStringIncludes(dts2, "ImagesResponse");
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions test/types-versions/deno.json

This file was deleted.

2 changes: 1 addition & 1 deletion test/types-versions/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals, assertStringIncludes } from "assert";
import { assertEquals, assertStringIncludes } from "jsr:@std/assert";

Deno.test("typesVersions", async () => {
const res = await fetch("http://localhost:8080/[email protected]/index.d.ts");
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 04557f7

Please sign in to comment.