Skip to content

Commit

Permalink
feat: Generated routes for all test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
bfanger committed Nov 18, 2024
1 parent 653c2cf commit 7c5c5e2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference types="./global" />

export { default as hooks } from "./hooks.js";
export { default as reactify } from "./reactify.js";
export { default as sveltify } from "./sveltify.svelte.js";
Expand Down
14 changes: 14 additions & 0 deletions src/routes/fixtures/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script lang="ts">
function getFiles() {
const modules = import.meta.glob("../../tests/fixtures/*.svelte");
return Object.keys(modules).map(
(path) => path.match(/([^/]+)\.svelte$/)?.[1],
);
}
</script>

<ul>
{#each getFiles() as file}
<li><a href="/fixtures/{file}">{file}</a></li>
{/each}
</ul>
24 changes: 24 additions & 0 deletions src/routes/fixtures/[fixture]/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script lang="ts">
let { data } = $props();
</script>

<header>
<h1>{data.title}</h1>
</header>
<data.Fixture />

<style>
header {
background: #5c1eba;
color: white;
padding: 0.6em;
border-radius: 8px;
text-align: center;
margin-bottom: 2em;
}
h1 {
font: 24px/1.1 sans-serif;
margin: 0;
}
</style>
20 changes: 20 additions & 0 deletions src/routes/fixtures/[fixture]/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Component } from "svelte";

export async function load({ params }) {
return {
title: params.fixture,
Fixture: await getModule(params.fixture),
};
}

async function getModule(name: string) {
const modules = import.meta.glob("../../../tests/fixtures/*.svelte");
const loader = Object.entries(modules).find(
([path]) => path.match(/([^/]+)\.svelte$/)?.[1] === name,
);
if (!loader) {
throw new Error(`Fixture not found: ${name}`);
}
const module = await loader[1]();
return (module as { default: Component }).default;
}
11 changes: 0 additions & 11 deletions src/routes/listitem/+page.svelte

This file was deleted.

10 changes: 10 additions & 0 deletions src/tests/fixtures/RestProps.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script lang="ts">
import type React from "react";
const props: React.JSX.IntrinsicElements["div"] = {
style: { backgroundColor: "#4c80db" },
onClick: () => console.info("clicked"),
};
</script>

<react.div {...props}><span>Hi</span></react.div>

0 comments on commit 7c5c5e2

Please sign in to comment.