-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a7e022
commit 9450da4
Showing
14 changed files
with
111 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
const { enthusiasm } = Astro.props; | ||
const punctuation = enthusiasm === 0 ? '.' : enthusiasm > 9 ? '!' : ''; | ||
--- | ||
<h1>Hello <slot>world</slot>{punctuation}</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { expect, test } from 'vitest' | ||
import { render } from 'astro/test' | ||
import Greeting from './Greeting.astro' | ||
|
||
test('Greeting', async () => { | ||
const { container } = await render(<Greeting />) | ||
expect(container).toBeDefined() | ||
expect(container.textContent).toBe('Hello world') | ||
}) | ||
|
||
test('Greeting with name', async () => { | ||
const { container } = await render(<Greeting>Test</Greeting>) | ||
expect(container).toBeDefined() | ||
expect(container.textContent).toBe('Hello Test') | ||
}) | ||
|
||
test('Greeting unenthusiastic', async () => { | ||
const { container } = await render(<Greeting enthusiasm={0} />) | ||
expect(container).toBeDefined() | ||
expect(container.textContent).toBe('Hello world.') | ||
}) | ||
|
||
test('Greeting enthusiastic', async () => { | ||
const { container } = await render(<Greeting enthusiasm={10} />) | ||
expect(container).toBeDefined() | ||
expect(container.textContent).toBe('Hello world!') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="astro/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import 'astro/test/setup'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { openConfig } from "../config.js"; | ||
import { nodeLogDestination } from "../logger/node.js"; | ||
import { createResult } from '../render/result.js'; | ||
import { AstroConfig } from "../../@types/astro.js"; | ||
import { renderJSX } from "../../runtime/server/jsx.js"; | ||
import { parseHTML } from 'linkedom'; | ||
|
||
const logging = { | ||
dest: nodeLogDestination, | ||
level: 'error', | ||
} as const; | ||
let config: AstroConfig; | ||
async function getResult() { | ||
if (!config) { | ||
const { astroConfig } = await openConfig({ cmd: 'dev', logging }); | ||
config = astroConfig; | ||
} | ||
const result = createResult({ | ||
adapterName: undefined, | ||
origin: '', | ||
ssr: false, | ||
streaming: false, | ||
logging, | ||
markdown: config.markdown, | ||
mode: 'development', | ||
params: {}, | ||
pathname: '/', | ||
props: {}, | ||
renderers: [], | ||
async resolve(s): Promise<string> { | ||
return s | ||
}, | ||
site: 'http://example.com', | ||
request: new Request('http://example.com'), | ||
status: 200, | ||
}) | ||
return result; | ||
} | ||
|
||
export async function render(vnode: any) { | ||
const result = await getResult(); | ||
const html = await renderJSX(result, vnode); | ||
const { document } = parseHTML(`<template id="container">${html}</template>`); | ||
|
||
const container = document.querySelector('#container'); | ||
return { container } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { polyfill } from "@astrojs/webapi"; | ||
|
||
polyfill(globalThis, { | ||
exclude: 'document window' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/// <reference path="./astro-jsx.d.ts" /> | ||
export function render(vnode: astroHTML.JSX.Element): Promise<{ container: HTMLTemplateElement }>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters