mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
minimal integration tests for macros
This commit is contained in:
4
integration/macro/assert.tsx
Normal file
4
integration/macro/assert.tsx
Normal file
@@ -0,0 +1,4 @@
|
||||
// This logs the result at build time
|
||||
export function unreachable(call) {
|
||||
throw new Error(call.arguments[0].toString() || "unreachable");
|
||||
}
|
||||
8
integration/macro/fetchSync.tsx
Normal file
8
integration/macro/fetchSync.tsx
Normal file
@@ -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 <string value={text} />;
|
||||
}
|
||||
5
integration/macro/hello-fetch-macro.tsx
Normal file
5
integration/macro/hello-fetch-macro.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { fetchSync } from "macro:./fetchSync.tsx";
|
||||
|
||||
const synchronousFetch = fetchSync(`https://example.com`);
|
||||
|
||||
console.log(synchronousFetch);
|
||||
30
integration/macro/loadMocks.tsx
Normal file
30
integration/macro/loadMocks.tsx
Normal file
@@ -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"],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user