From 1004e924ff2d53b14cb2e3a5c32ed0e4135fd89a Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 5 Jan 2022 04:54:37 -0800 Subject: [PATCH] minimal integration tests for macros --- integration/macro/assert.tsx | 4 ++++ integration/macro/fetchSync.tsx | 8 +++++++ integration/macro/hello-fetch-macro.tsx | 5 +++++ integration/macro/loadMocks.tsx | 30 +++++++++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 integration/macro/assert.tsx create mode 100644 integration/macro/fetchSync.tsx create mode 100644 integration/macro/hello-fetch-macro.tsx create mode 100644 integration/macro/loadMocks.tsx diff --git a/integration/macro/assert.tsx b/integration/macro/assert.tsx new file mode 100644 index 0000000000..8a6e4d8224 --- /dev/null +++ b/integration/macro/assert.tsx @@ -0,0 +1,4 @@ +// This logs the result at build time +export function unreachable(call) { + throw new Error(call.arguments[0].toString() || "unreachable"); +} diff --git a/integration/macro/fetchSync.tsx b/integration/macro/fetchSync.tsx new file mode 100644 index 0000000000..ebe1566e61 --- /dev/null +++ b/integration/macro/fetchSync.tsx @@ -0,0 +1,8 @@ +export async function fetchSync(ctx) { + const str = ctx.arguments[0].toString(); + + const response = await fetch(str); + const text = await response.text(); + + return ; +} diff --git a/integration/macro/hello-fetch-macro.tsx b/integration/macro/hello-fetch-macro.tsx new file mode 100644 index 0000000000..fa0de4a9d7 --- /dev/null +++ b/integration/macro/hello-fetch-macro.tsx @@ -0,0 +1,5 @@ +import { fetchSync } from "macro:./fetchSync.tsx"; + +const synchronousFetch = fetchSync(`https://example.com`); + +console.log(synchronousFetch); diff --git a/integration/macro/loadMocks.tsx b/integration/macro/loadMocks.tsx new file mode 100644 index 0000000000..4b7993c6d5 --- /dev/null +++ b/integration/macro/loadMocks.tsx @@ -0,0 +1,30 @@ +import { unreachable } from "macro:./assert"; + +if (process.env.NODE_ENV !== "test") + unreachable("This module should only be imported in tests"); + +export const mockData = { + Copilot: { + id: "Copilot", + name: "Copilot", + description: "Copilot", + icon: "https://s3.amazonaws.com/copilot-public/images/icons/Copilot.png", + color: "#00AEEF", + type: "service", + tags: ["copilot"], + categories: ["copilot"], + links: [ + { + id: "Copilot", + name: "Copilot", + url: "https://copilot.io", + description: "Copilot", + icon: "https://s3.amazonaws.com/copilot-public/images/icons/Copilot.png", + color: "#00AEEF", + type: "service", + tags: ["copilot"], + categories: ["copilot"], + }, + ], + }, +};