mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
wip
This commit is contained in:
parent
697a539adf
commit
d9397a1cf6
5 changed files with 46 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { before, describe, it } from 'node:test';
|
import { after, before, describe, it } from 'node:test';
|
||||||
import { experimental_AstroContainer } from '../dist/container/index.js';
|
import { experimental_AstroContainer } from '../dist/container/index.js';
|
||||||
import {
|
import {
|
||||||
Fragment,
|
Fragment,
|
||||||
|
@ -233,7 +233,29 @@ describe('Container', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Container with renderers', () => {
|
describe('Container with renderers, DEV', () => {
|
||||||
|
let fixture;
|
||||||
|
let devServer;
|
||||||
|
before(async () => {
|
||||||
|
fixture = await loadFixture({
|
||||||
|
root: new URL('./fixtures/container-custom-renderers/', import.meta.url),
|
||||||
|
});
|
||||||
|
devServer = await fixture.startDevServer();
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
await devServer.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('the endpoint should return the HTML of the React component', async () => {
|
||||||
|
const response = await fixture.fetch('/button-directive');
|
||||||
|
const html = await response.text();
|
||||||
|
|
||||||
|
assert.match(html, /I am a react button/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe.skip('Container with renderers, SSR', () => {
|
||||||
let fixture;
|
let fixture;
|
||||||
let app;
|
let app;
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
@ -262,7 +284,7 @@ describe('Container with renderers', () => {
|
||||||
assert.match(html, /I am a vue button/);
|
assert.match(html, /I am a vue button/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should render a component with directives', async () => {
|
it.skip('Should render a component with directives', async () => {
|
||||||
const request = new Request('https://example.com/button-directive');
|
const request = new Request('https://example.com/button-directive');
|
||||||
const response = await app.render(request);
|
const response = await app.render(request);
|
||||||
const html = await response.text();
|
const html = await response.text();
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"devDependencies": {
|
||||||
"@astrojs/react": "workspace:*",
|
"@astrojs/react": "workspace:*",
|
||||||
"@astrojs/vue": "workspace:*",
|
"@astrojs/vue": "workspace:*",
|
||||||
"astro": "workspace:*",
|
"astro": "workspace:*"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"vue": "^3.4.31"
|
"vue": "^3.4.31"
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
import Button from "./button.jsx"
|
import Button from "./button.jsx"
|
||||||
---
|
---
|
||||||
|
|
||||||
<Button client:idle />
|
<Button/>
|
||||||
|
|
|
@ -1,12 +1,22 @@
|
||||||
import type { APIRoute, SSRLoadedRenderer } from 'astro';
|
import type { APIRoute, SSRLoadedRenderer } from 'astro';
|
||||||
import { experimental_AstroContainer } from 'astro/container';
|
import { experimental_AstroContainer } from 'astro/container';
|
||||||
import renderer from '@astrojs/react/server.js';
|
import { loadRenderers } from 'astro:container';
|
||||||
|
import { getContainerRenderer as r } from '@astrojs/react';
|
||||||
|
import { getContainerRenderer as v } from '@astrojs/vue';
|
||||||
import Component from '../components/buttonDirective.astro';
|
import Component from '../components/buttonDirective.astro';
|
||||||
|
|
||||||
export const GET: APIRoute = async (ctx) => {
|
export const GET: APIRoute = async (ctx) => {
|
||||||
const container = await experimental_AstroContainer.create();
|
try {
|
||||||
container.addServerRenderer({ renderer });
|
const renderers = await loadRenderers([v(), r()]);
|
||||||
return await container.renderToResponse(Component, {
|
} catch (e) {
|
||||||
skipClientDirectives: true,
|
console.log(e);
|
||||||
|
}
|
||||||
|
return new Response(null, {
|
||||||
|
status: 200,
|
||||||
});
|
});
|
||||||
|
// const container = await experimental_AstroContainer.create({
|
||||||
|
// renderers,
|
||||||
|
// });
|
||||||
|
// container.addServerRenderer({ renderer });
|
||||||
|
// return await container.renderToResponse(Component);
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
"./client.js": "./client.js",
|
"./client.js": "./client.js",
|
||||||
"./client-v17.js": "./client-v17.js",
|
"./client-v17.js": "./client-v17.js",
|
||||||
"./server.js": {
|
"./server.js": {
|
||||||
"default": "./server.js",
|
"import": "./server.js",
|
||||||
"types": "./server.d.ts"
|
"types": "./server.d.ts"
|
||||||
},
|
},
|
||||||
"./server-v17.js": {
|
"./server-v17.js": {
|
||||||
|
|
Loading…
Reference in a new issue