diff options
author | 2021-09-17 03:14:23 -0700 | |
---|---|---|
committer | 2021-09-17 03:14:23 -0700 | |
commit | 1c7485e58c2fc02ceed4656752c5315178e9b9a9 (patch) | |
tree | 2633805273fb709ef1a20bc12d869033f74c810c /integration/snippets/public/index.html | |
parent | 872428de89c63e0034573c1419fa616f8d0648b1 (diff) | |
download | bun-1c7485e58c2fc02ceed4656752c5315178e9b9a9.tar.gz bun-1c7485e58c2fc02ceed4656752c5315178e9b9a9.tar.zst bun-1c7485e58c2fc02ceed4656752c5315178e9b9a9.zip |
Begin to add integration tests
Diffstat (limited to 'integration/snippets/public/index.html')
-rw-r--r-- | integration/snippets/public/index.html | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/integration/snippets/public/index.html b/integration/snippets/public/index.html new file mode 100644 index 000000000..74a744a7d --- /dev/null +++ b/integration/snippets/public/index.html @@ -0,0 +1,51 @@ +<html> + <head> + <meta charset="utf-8" /> + <meta http-equiv="X-UA-Compatible" content="IE=edge" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Bun Test</title> + </head> + <body> + <script type="module"> + globalThis.getModuleScriptSrc = async (name) => { + const response = await fetch(name, { + cache: "force-cache", + }); + + if (response.ok) { + return await response.text(); + } else { + throw new Error(`Failed to get module script ${name}`); + } + }; + + globalThis.runTest = async (name) => { + var Namespace = await import(name); + var testFunction = Namespace.test; + + if ( + !("test" in Namespace) && + "default" in Namespace && + typeof Namespace.default === "function" + ) { + Namespace = Namespace.default(); + testFunction = Namespace.test; + } + + if (!testFunction) { + throw new Error("No test function found in " + name); + } + + if (typeof testFunction !== "function") { + throw new Error( + `Expected (await import(\"${name}\"")) to have a test function.\nReceived: ${Object.keys( + Namespace + ).join(", ")} ` + ); + } + + return await testFunction(); + }; + </script> + </body> +</html> |