diff options
author | 2021-11-01 20:05:38 -0700 | |
---|---|---|
committer | 2021-11-01 20:05:38 -0700 | |
commit | 92b174b3156f317ae942f0be4ca89f05df99a4c6 (patch) | |
tree | 42f1db372a0ffa3c2fcebb04baad090c728e767e | |
parent | 0ba9784be2fd56700652e85c563f931c6a2bb112 (diff) | |
download | bun-92b174b3156f317ae942f0be4ca89f05df99a4c6.tar.gz bun-92b174b3156f317ae942f0be4ca89f05df99a4c6.tar.zst bun-92b174b3156f317ae942f0be4ca89f05df99a4c6.zip |
Add Bun.js integration tests, but don't run them yet.
16 files changed, 366 insertions, 192 deletions
diff --git a/integration/scripts/bun.js b/integration/scripts/bun.js new file mode 100644 index 000000000..d22785787 --- /dev/null +++ b/integration/scripts/bun.js @@ -0,0 +1,85 @@ +import snippets from "./snippets.json"; + +globalThis.console.assert = (condition, ...content) => { + if (!condition) { + throw new Error(content.join(" ")); + } +}; +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) => { + testSuccess = false; + 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(", ")} ` + ); + } + + if (globalThis.BUN_DEBUG_MODE) { + try { + await testFunction(); + if (!testSuccess) { + throw new Error("Test failed"); + } + } catch (exception) { + console.error(exception); + debugger; + throw exception; + } + } else { + await testFunction(); + if (!testSuccess) { + throw new Error("Test failed"); + } + } +}; + +var testSuccess = false; +globalThis.testDone = () => { + testSuccess = true; +}; + +let fail = 0; +for (let snippet of snippets) { + try { + await runTest("../snippets/" + snippet.substring(1)); + console.log("✅", snippet); + } catch (exception) { + console.error(`❌ ${snippet}`); + console.error(exception); + + fail++; + } +} + +if (fail) throw new Error(`❌ browser test failed (${fail})`); + +console.log(`✅ bun.js test passed`); diff --git a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.debug.js b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.debug.js index 53bb66b5e..783769a85 100644 --- a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.debug.js +++ b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.debug.js @@ -1,38 +1,12 @@ -import { -__require as require -} from "http://localhost:8080/__runtime.js"; -import { -__cJS2eSM -} from "http://localhost:8080/__runtime.js"; -import * as _login_b977_0 from "http://localhost:8080/_login.js"; -import * as _login_b977_1 from "http://localhost:8080/_login.js"; import _login from "http://localhost:8080/_login.js"; import _auth from "http://localhost:8080/_auth.js"; import * as _loginReally from "http://localhost:8080/_login.js"; import * as _loginReally2 from "http://localhost:8080/_login.js"; import * as _authReally from "http://localhost:8080/_auth.js"; -export default __cJS2eSM(function(module, exports) { - ; - - ; - ; - ; - ; - module.exports.iAmCommonJs = true; - exports.YouAreCommonJS = true; - require(_login_b977_0); - require(_login_b977_1); - Object.defineProperty(module.exports,"login",{get: () => _login, enumerable: true, configurable: true}); - function test() { - return testDone(import.meta.url); - }; -var test = test; - Object.defineProperty(module.exports,"test",{get: () => test, enumerable: true, configurable: true}); - let foo, bar; - Object.defineProperties(module.exports,{'foo': {get: () => foo, set: ($_newValue) => {foo = $_newValue;}, enumerable: true, configurable: true}, -'bar': {get: () => bar, set: ($_newValue) => {bar = $_newValue;}, enumerable: true, configurable: true}}); -}, "cjs-transform-shouldnt-have-static-imports-in-cjs-function.js"); - - +export {_login as login}; +export function test() { + return testDone(import.meta.url); +} +export let foo, bar; diff --git a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.debug.js b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.debug.js index fa25e2df8..2ca15542e 100644 --- a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.debug.js +++ b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.debug.js @@ -1,38 +1,40 @@ import { -__require as require +__HMRModule as HMR } from "http://localhost:8080/__runtime.js"; import { -__cJS2eSM +__HMRClient as Bun } from "http://localhost:8080/__runtime.js"; -import * as _login_b977_0 from "http://localhost:8080/_login.js"; -import * as _login_b977_1 from "http://localhost:8080/_login.js"; import _login from "http://localhost:8080/_login.js"; import _auth from "http://localhost:8080/_auth.js"; import * as _loginReally from "http://localhost:8080/_login.js"; import * as _loginReally2 from "http://localhost:8080/_login.js"; import * as _authReally from "http://localhost:8080/_auth.js"; +Bun.activate(true); -export default __cJS2eSM(function(module, exports) { - ; - - ; - ; - ; - ; - module.exports.iAmCommonJs = true; - exports.YouAreCommonJS = true; - require(_login_b977_0); - require(_login_b977_1); - Object.defineProperty(module.exports,"login",{get: () => _login, enumerable: true, configurable: true}); +var hmr = new HMR(3878252498, "cjs-transform-shouldnt-have-static-imports-in-cjs-function.js"), exports = hmr.exports; +(hmr._load = function() { function test() { return testDone(import.meta.url); - }; -var test = test; - Object.defineProperty(module.exports,"test",{get: () => test, enumerable: true, configurable: true}); + } var foo, bar; - Object.defineProperties(module.exports,{'foo': {get: () => foo, set: ($_newValue) => {foo = $_newValue;}, enumerable: true, configurable: true}, -'bar': {get: () => bar, set: ($_newValue) => {bar = $_newValue;}, enumerable: true, configurable: true}}); -}, "cjs-transform-shouldnt-have-static-imports-in-cjs-function.js"); - - + hmr.exportAll({ + login: () => _login, + test: () => test, + foo: () => foo, + bar: () => bar + }); +})(); +var $$hmr_login = hmr.exports.login, $$hmr_test = hmr.exports.test, $$hmr_foo = hmr.exports.foo, $$hmr_bar = hmr.exports.bar; +hmr._update = function(exports) { + $$hmr_login = exports.login; + $$hmr_test = exports.test; + $$hmr_foo = exports.foo; + $$hmr_bar = exports.bar; +}; +export { + $$hmr_login as login, + $$hmr_test as test, + $$hmr_foo as foo, + $$hmr_bar as bar +}; diff --git a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.js b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.js index fa25e2df8..ef0bd004e 100644 --- a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.js +++ b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.js @@ -1,38 +1,40 @@ import { -__require as require +__HMRModule as HMR } from "http://localhost:8080/__runtime.js"; import { -__cJS2eSM +__HMRClient as Bun } from "http://localhost:8080/__runtime.js"; -import * as _login_b977_0 from "http://localhost:8080/_login.js"; -import * as _login_b977_1 from "http://localhost:8080/_login.js"; import _login from "http://localhost:8080/_login.js"; import _auth from "http://localhost:8080/_auth.js"; import * as _loginReally from "http://localhost:8080/_login.js"; import * as _loginReally2 from "http://localhost:8080/_login.js"; import * as _authReally from "http://localhost:8080/_auth.js"; +Bun.activate(false); -export default __cJS2eSM(function(module, exports) { - ; - - ; - ; - ; - ; - module.exports.iAmCommonJs = true; - exports.YouAreCommonJS = true; - require(_login_b977_0); - require(_login_b977_1); - Object.defineProperty(module.exports,"login",{get: () => _login, enumerable: true, configurable: true}); +var hmr = new HMR(3878252498, "cjs-transform-shouldnt-have-static-imports-in-cjs-function.js"), exports = hmr.exports; +(hmr._load = function() { function test() { return testDone(import.meta.url); - }; -var test = test; - Object.defineProperty(module.exports,"test",{get: () => test, enumerable: true, configurable: true}); + } var foo, bar; - Object.defineProperties(module.exports,{'foo': {get: () => foo, set: ($_newValue) => {foo = $_newValue;}, enumerable: true, configurable: true}, -'bar': {get: () => bar, set: ($_newValue) => {bar = $_newValue;}, enumerable: true, configurable: true}}); -}, "cjs-transform-shouldnt-have-static-imports-in-cjs-function.js"); - - + hmr.exportAll({ + login: () => _login, + test: () => test, + foo: () => foo, + bar: () => bar + }); +})(); +var $$hmr_login = hmr.exports.login, $$hmr_test = hmr.exports.test, $$hmr_foo = hmr.exports.foo, $$hmr_bar = hmr.exports.bar; +hmr._update = function(exports) { + $$hmr_login = exports.login; + $$hmr_test = exports.test; + $$hmr_foo = exports.foo; + $$hmr_bar = exports.bar; +}; +export { + $$hmr_login as login, + $$hmr_test as test, + $$hmr_foo as foo, + $$hmr_bar as bar +}; diff --git a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.js b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.js index 53bb66b5e..783769a85 100644 --- a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.js +++ b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.js @@ -1,38 +1,12 @@ -import { -__require as require -} from "http://localhost:8080/__runtime.js"; -import { -__cJS2eSM -} from "http://localhost:8080/__runtime.js"; -import * as _login_b977_0 from "http://localhost:8080/_login.js"; -import * as _login_b977_1 from "http://localhost:8080/_login.js"; import _login from "http://localhost:8080/_login.js"; import _auth from "http://localhost:8080/_auth.js"; import * as _loginReally from "http://localhost:8080/_login.js"; import * as _loginReally2 from "http://localhost:8080/_login.js"; import * as _authReally from "http://localhost:8080/_auth.js"; -export default __cJS2eSM(function(module, exports) { - ; - - ; - ; - ; - ; - module.exports.iAmCommonJs = true; - exports.YouAreCommonJS = true; - require(_login_b977_0); - require(_login_b977_1); - Object.defineProperty(module.exports,"login",{get: () => _login, enumerable: true, configurable: true}); - function test() { - return testDone(import.meta.url); - }; -var test = test; - Object.defineProperty(module.exports,"test",{get: () => test, enumerable: true, configurable: true}); - let foo, bar; - Object.defineProperties(module.exports,{'foo': {get: () => foo, set: ($_newValue) => {foo = $_newValue;}, enumerable: true, configurable: true}, -'bar': {get: () => bar, set: ($_newValue) => {bar = $_newValue;}, enumerable: true, configurable: true}}); -}, "cjs-transform-shouldnt-have-static-imports-in-cjs-function.js"); - - +export {_login as login}; +export function test() { + return testDone(import.meta.url); +} +export let foo, bar; diff --git a/integration/snapshots/string-escapes.debug.js b/integration/snapshots/string-escapes.debug.js index 890d8355d..4a5c82b05 100644 --- a/integration/snapshots/string-escapes.debug.js +++ b/integration/snapshots/string-escapes.debug.js @@ -18,6 +18,7 @@ var obj = { "\v": "\v", "\u2028": "\u2028", "\u2029": "\u2029", + "\0": "\0\xA0null byte", "😊": "😊", "😃": "😃", "🕵🏽♂️": "🕵🏽♂️", @@ -121,6 +122,35 @@ const correctEncodedObj = [ 34, 44, 34, + 92, + 117, + 48, + 48, + 48, + 48, + 34, + 58, + 34, + 92, + 117, + 48, + 48, + 48, + 48, + 194, + 160, + 110, + 117, + 108, + 108, + 32, + 98, + 121, + 116, + 101, + 34, + 44, + 34, 240, 159, 152, diff --git a/integration/snapshots/string-escapes.hmr.debug.js b/integration/snapshots/string-escapes.hmr.debug.js index 979c5da7e..7a2d88ad1 100644 --- a/integration/snapshots/string-escapes.hmr.debug.js +++ b/integration/snapshots/string-escapes.hmr.debug.js @@ -27,6 +27,7 @@ var hmr = new HMR(2482749838, "string-escapes.js"), exports = hmr.exports; "\v": "\v", "\u2028": "\u2028", "\u2029": "\u2029", + "\0": "\0\xA0null byte", "😊": "😊", "😃": "😃", "🕵🏽♂️": "🕵🏽♂️", @@ -130,6 +131,35 @@ var hmr = new HMR(2482749838, "string-escapes.js"), exports = hmr.exports; 34, 44, 34, + 92, + 117, + 48, + 48, + 48, + 48, + 34, + 58, + 34, + 92, + 117, + 48, + 48, + 48, + 48, + 194, + 160, + 110, + 117, + 108, + 108, + 32, + 98, + 121, + 116, + 101, + 34, + 44, + 34, 240, 159, 152, diff --git a/integration/snapshots/string-escapes.hmr.js b/integration/snapshots/string-escapes.hmr.js index ef03d89e1..53f3ba24a 100644 --- a/integration/snapshots/string-escapes.hmr.js +++ b/integration/snapshots/string-escapes.hmr.js @@ -27,6 +27,7 @@ var hmr = new HMR(2482749838, "string-escapes.js"), exports = hmr.exports; "\v": "\v", "\u2028": "\u2028", "\u2029": "\u2029", + "\0": "\0\xA0null byte", "😊": "😊", "😃": "😃", "🕵🏽♂️": "🕵🏽♂️", @@ -130,6 +131,35 @@ var hmr = new HMR(2482749838, "string-escapes.js"), exports = hmr.exports; 34, 44, 34, + 92, + 117, + 48, + 48, + 48, + 48, + 34, + 58, + 34, + 92, + 117, + 48, + 48, + 48, + 48, + 194, + 160, + 110, + 117, + 108, + 108, + 32, + 98, + 121, + 116, + 101, + 34, + 44, + 34, 240, 159, 152, diff --git a/integration/snapshots/string-escapes.js b/integration/snapshots/string-escapes.js index 890d8355d..4a5c82b05 100644 --- a/integration/snapshots/string-escapes.js +++ b/integration/snapshots/string-escapes.js @@ -18,6 +18,7 @@ var obj = { "\v": "\v", "\u2028": "\u2028", "\u2029": "\u2029", + "\0": "\0\xA0null byte", "😊": "😊", "😃": "😃", "🕵🏽♂️": "🕵🏽♂️", @@ -121,6 +122,35 @@ const correctEncodedObj = [ 34, 44, 34, + 92, + 117, + 48, + 48, + 48, + 48, + 34, + 58, + 34, + 92, + 117, + 48, + 48, + 48, + 48, + 194, + 160, + 110, + 117, + 108, + 108, + 32, + 98, + 121, + 116, + 101, + 34, + 44, + 34, 240, 159, 152, diff --git a/integration/snapshots/styledcomponents-output.debug.js b/integration/snapshots/styledcomponents-output.debug.js index 0f81a0ba7..b99d434da 100644 --- a/integration/snapshots/styledcomponents-output.debug.js +++ b/integration/snapshots/styledcomponents-output.debug.js @@ -40,18 +40,21 @@ const ErrorScreenRoot = styled.div` `; export function test() { - const reactEl = document.createElement("div"); - document.body.appendChild(reactEl); - ReactDOM.render(jsx(ErrorScreenRoot, { - id: "error-el", - children: "The react child should have this text" - }, undefined, false, undefined, this), reactEl); - const style = document.querySelector("style[data-styled]"); - console.assert(style, "style tag should exist"); - console.assert(style.textContent.split("").every((a) => a.codePointAt(0) < 128), "style tag should not contain invalid unicode codepoints"); - console.assert(document.querySelector("#error-el").textContent === "The react child should have this text"); - ReactDOM.unmountComponentAtNode(reactEl); - reactEl.remove(); - style.remove(); - testDone(import.meta.url); + if (typeof window !== "undefined") { + const reactEl = document.createElement("div"); + document.body.appendChild(reactEl); + ReactDOM.render(jsx(ErrorScreenRoot, { + id: "error-el", + children: "The react child should have this text" + }, undefined, false, undefined, this), reactEl); + const style = document.querySelector("style[data-styled]"); + console.assert(style, "style tag should exist"); + console.assert(style.textContent.split("").every((a) => a.codePointAt(0) < 128), "style tag should not contain invalid unicode codepoints"); + console.assert(document.querySelector("#error-el").textContent === "The react child should have this text"); + ReactDOM.unmountComponentAtNode(reactEl); + reactEl.remove(); + style.remove(); + return testDone(import.meta.url); + } + return testDone(import.meta.url); } diff --git a/integration/snapshots/styledcomponents-output.hmr.debug.js b/integration/snapshots/styledcomponents-output.hmr.debug.js index c10d1c492..dc9e2de7d 100644 --- a/integration/snapshots/styledcomponents-output.hmr.debug.js +++ b/integration/snapshots/styledcomponents-output.hmr.debug.js @@ -49,20 +49,23 @@ var hmr = new HMR(1290604342, "styledcomponents-output.js"), exports = hmr.expor } `; function test() { - const reactEl = document.createElement("div"); - document.body.appendChild(reactEl); - ReactDOM.render(jsx(ErrorScreenRoot, { - id: "error-el", - children: "The react child should have this text" - }, undefined, false, undefined, this), reactEl); - const style = document.querySelector("style[data-styled]"); - console.assert(style, "style tag should exist"); - console.assert(style.textContent.split("").every((a) => a.codePointAt(0) < 128), "style tag should not contain invalid unicode codepoints"); - console.assert(document.querySelector("#error-el").textContent === "The react child should have this text"); - ReactDOM.unmountComponentAtNode(reactEl); - reactEl.remove(); - style.remove(); - testDone(import.meta.url); + if (typeof window !== "undefined") { + const reactEl = document.createElement("div"); + document.body.appendChild(reactEl); + ReactDOM.render(jsx(ErrorScreenRoot, { + id: "error-el", + children: "The react child should have this text" + }, undefined, false, undefined, this), reactEl); + const style = document.querySelector("style[data-styled]"); + console.assert(style, "style tag should exist"); + console.assert(style.textContent.split("").every((a) => a.codePointAt(0) < 128), "style tag should not contain invalid unicode codepoints"); + console.assert(document.querySelector("#error-el").textContent === "The react child should have this text"); + ReactDOM.unmountComponentAtNode(reactEl); + reactEl.remove(); + style.remove(); + return testDone(import.meta.url); + } + return testDone(import.meta.url); } hmr.exportAll({ test: () => test diff --git a/integration/snapshots/styledcomponents-output.hmr.js b/integration/snapshots/styledcomponents-output.hmr.js index e451ae202..5f0d525a4 100644 --- a/integration/snapshots/styledcomponents-output.hmr.js +++ b/integration/snapshots/styledcomponents-output.hmr.js @@ -49,20 +49,23 @@ var hmr = new HMR(1290604342, "styledcomponents-output.js"), exports = hmr.expor } `; function test() { - const reactEl = document.createElement("div"); - document.body.appendChild(reactEl); - ReactDOM.render(jsx(ErrorScreenRoot, { - id: "error-el", - children: "The react child should have this text" - }, undefined, false, undefined, this), reactEl); - const style = document.querySelector("style[data-styled]"); - console.assert(style, "style tag should exist"); - console.assert(style.textContent.split("").every((a) => a.codePointAt(0) < 128), "style tag should not contain invalid unicode codepoints"); - console.assert(document.querySelector("#error-el").textContent === "The react child should have this text"); - ReactDOM.unmountComponentAtNode(reactEl); - reactEl.remove(); - style.remove(); - testDone(import.meta.url); + if (typeof window !== "undefined") { + const reactEl = document.createElement("div"); + document.body.appendChild(reactEl); + ReactDOM.render(jsx(ErrorScreenRoot, { + id: "error-el", + children: "The react child should have this text" + }, undefined, false, undefined, this), reactEl); + const style = document.querySelector("style[data-styled]"); + console.assert(style, "style tag should exist"); + console.assert(style.textContent.split("").every((a) => a.codePointAt(0) < 128), "style tag should not contain invalid unicode codepoints"); + console.assert(document.querySelector("#error-el").textContent === "The react child should have this text"); + ReactDOM.unmountComponentAtNode(reactEl); + reactEl.remove(); + style.remove(); + return testDone(import.meta.url); + } + return testDone(import.meta.url); } hmr.exportAll({ test: () => test diff --git a/integration/snapshots/styledcomponents-output.js b/integration/snapshots/styledcomponents-output.js index 0f81a0ba7..b99d434da 100644 --- a/integration/snapshots/styledcomponents-output.js +++ b/integration/snapshots/styledcomponents-output.js @@ -40,18 +40,21 @@ const ErrorScreenRoot = styled.div` `; export function test() { - const reactEl = document.createElement("div"); - document.body.appendChild(reactEl); - ReactDOM.render(jsx(ErrorScreenRoot, { - id: "error-el", - children: "The react child should have this text" - }, undefined, false, undefined, this), reactEl); - const style = document.querySelector("style[data-styled]"); - console.assert(style, "style tag should exist"); - console.assert(style.textContent.split("").every((a) => a.codePointAt(0) < 128), "style tag should not contain invalid unicode codepoints"); - console.assert(document.querySelector("#error-el").textContent === "The react child should have this text"); - ReactDOM.unmountComponentAtNode(reactEl); - reactEl.remove(); - style.remove(); - testDone(import.meta.url); + if (typeof window !== "undefined") { + const reactEl = document.createElement("div"); + document.body.appendChild(reactEl); + ReactDOM.render(jsx(ErrorScreenRoot, { + id: "error-el", + children: "The react child should have this text" + }, undefined, false, undefined, this), reactEl); + const style = document.querySelector("style[data-styled]"); + console.assert(style, "style tag should exist"); + console.assert(style.textContent.split("").every((a) => a.codePointAt(0) < 128), "style tag should not contain invalid unicode codepoints"); + console.assert(document.querySelector("#error-el").textContent === "The react child should have this text"); + ReactDOM.unmountComponentAtNode(reactEl); + reactEl.remove(); + style.remove(); + return testDone(import.meta.url); + } + 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 index 370b1abec..1ba6c059d 100644 --- 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 @@ -4,10 +4,10 @@ import * as _loginReally from "./_login"; import * as _loginReally2 from "./_login"; import * as _authReally from "./_auth"; -module.exports.iAmCommonJs = true; -exports.YouAreCommonJS = true; -require("./_login"); -require("./_login"); +// module.exports.iAmCommonJs = true; +// exports.YouAreCommonJS = true; +// require("./_login"); +// require("./_login"); export { _login as login }; export function test() { diff --git a/integration/snippets/styledcomponents-output.js b/integration/snippets/styledcomponents-output.js index 16ac1ed6b..a79b5e24d 100644 --- a/integration/snippets/styledcomponents-output.js +++ b/integration/snippets/styledcomponents-output.js @@ -32,28 +32,32 @@ const ErrorScreenRoot = styled.div` `; export function test() { - const reactEl = document.createElement("div"); - document.body.appendChild(reactEl); - ReactDOM.render( - <ErrorScreenRoot id="error-el"> - The react child should have this text - </ErrorScreenRoot>, - reactEl - ); + if (typeof window !== "undefined") { + const reactEl = document.createElement("div"); + document.body.appendChild(reactEl); + ReactDOM.render( + <ErrorScreenRoot id="error-el"> + The react child should have this text + </ErrorScreenRoot>, + reactEl + ); - const style = document.querySelector("style[data-styled]"); - console.assert(style, "style tag should exist"); - console.assert( - style.textContent.split("").every((a) => a.codePointAt(0) < 128), - "style tag should not contain invalid unicode codepoints" - ); - console.assert( - document.querySelector("#error-el").textContent === - "The react child should have this text" - ); + const style = document.querySelector("style[data-styled]"); + console.assert(style, "style tag should exist"); + console.assert( + style.textContent.split("").every((a) => a.codePointAt(0) < 128), + "style tag should not contain invalid unicode codepoints" + ); + console.assert( + document.querySelector("#error-el").textContent === + "The react child should have this text" + ); - ReactDOM.unmountComponentAtNode(reactEl); - reactEl.remove(); - style.remove(); - testDone(import.meta.url); + ReactDOM.unmountComponentAtNode(reactEl); + reactEl.remove(); + style.remove(); + return testDone(import.meta.url); + } + + return testDone(import.meta.url); } diff --git a/integration/snippets/zero.js b/integration/snippets/zero.js new file mode 100644 index 000000000..38f521ff1 --- /dev/null +++ b/integration/snippets/zero.js @@ -0,0 +1 @@ +export const zero = "\0"; |