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 | |
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')
-rw-r--r-- | integration/snippets/_auth.js | 1 | ||||
-rw-r--r-- | integration/snippets/_bacon.js | 1 | ||||
-rw-r--r-- | integration/snippets/_login.js | 3 | ||||
-rw-r--r-- | integration/snippets/bundled-entry-point.js | 7 | ||||
-rw-r--r-- | integration/snippets/cjs-transform-shouldnt-have-static-imports-in-cjs-function.js | 15 | ||||
-rw-r--r-- | integration/snippets/export.js | 29 | ||||
-rw-r--r-- | integration/snippets/package.json | 10 | ||||
-rw-r--r-- | integration/snippets/public/index.html | 51 | ||||
-rw-r--r-- | integration/snippets/type-only-imports.ts | 12 |
9 files changed, 129 insertions, 0 deletions
diff --git a/integration/snippets/_auth.js b/integration/snippets/_auth.js new file mode 100644 index 000000000..407090812 --- /dev/null +++ b/integration/snippets/_auth.js @@ -0,0 +1 @@ +export default "hi"; diff --git a/integration/snippets/_bacon.js b/integration/snippets/_bacon.js new file mode 100644 index 000000000..c07ffb9be --- /dev/null +++ b/integration/snippets/_bacon.js @@ -0,0 +1 @@ +export let hello = true; diff --git a/integration/snippets/_login.js b/integration/snippets/_login.js new file mode 100644 index 000000000..b2fc2ef65 --- /dev/null +++ b/integration/snippets/_login.js @@ -0,0 +1,3 @@ +export default function () { + return true; +} diff --git a/integration/snippets/bundled-entry-point.js b/integration/snippets/bundled-entry-point.js new file mode 100644 index 000000000..a996f8632 --- /dev/null +++ b/integration/snippets/bundled-entry-point.js @@ -0,0 +1,7 @@ +import "react"; + +var hello = 123 ? null ?? "world" : "ok"; + +export function test() { + return testDone(import.meta.url); +} diff --git a/integration/snippets/cjs-transform-shouldnt-have-static-imports-in-cjs-function.js b/integration/snippets/cjs-transform-shouldnt-have-static-imports-in-cjs-function.js new file mode 100644 index 000000000..4191b7116 --- /dev/null +++ b/integration/snippets/cjs-transform-shouldnt-have-static-imports-in-cjs-function.js @@ -0,0 +1,15 @@ +import _login from "./_login"; +import _auth from "./_auth"; +import * as _loginReally from "./_login"; +import * as _authReally from "./_auth"; + +module.exports.iAmCommonJs = true; +exports.YouAreCommonJS = true; +require("./_login"); +export { _login as login }; + +export function test() { + return testDone(import.meta.url); +} + +export let foo, bar; diff --git a/integration/snippets/export.js b/integration/snippets/export.js new file mode 100644 index 000000000..fe0abfa53 --- /dev/null +++ b/integration/snippets/export.js @@ -0,0 +1,29 @@ +import what from "./_auth"; +export { default as auth } from "./_auth"; +export { default as login } from "./_login"; +export * from "./_bacon"; +export let yoyoyo = "yoyoyo"; +export default function hey() { + return true; +} +export const foo = () => {}; +export var bar = 100; +export let powerLevel = Symbol("9001"); +export { what }; +export { what as when, what as whence }; +export {} from "./_bacon"; +export * as where from "./_auth"; +export { bar as booop }; + +export function test() { + hey(); + foo(); + if (where.default !== "hi") { + throw new Error(`_auth import is incorrect.`); + } + console.assert( + powerLevel.description === "9001", + "Symbol is not exported correctly" + ); + return testDone(import.meta.url); +} diff --git a/integration/snippets/package.json b/integration/snippets/package.json new file mode 100644 index 000000000..8edbd79a1 --- /dev/null +++ b/integration/snippets/package.json @@ -0,0 +1,10 @@ +{ + "name": "snippets", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "dependencies": { + "react": "^17.0.2", + "redux": "^4.1.1" + } +} 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> diff --git a/integration/snippets/type-only-imports.ts b/integration/snippets/type-only-imports.ts new file mode 100644 index 000000000..447f86793 --- /dev/null +++ b/integration/snippets/type-only-imports.ts @@ -0,0 +1,12 @@ +import type Bacon from "tree"; +import type { SilentSymbolCollisionsAreOkayInTypeScript } from "./app"; + +export const baconator: Bacon = true; +export const SilentSymbolCollisionsAreOkayInTypeScript: SilentSymbolCollisionsAreOkayInTypeScript = + true; + +export function test() { + console.assert(SilentSymbolCollisionsAreOkayInTypeScript); + console.assert(baconator); + return testDone(import.meta.url); +} |