Skip to content
Snippets Groups Projects
Commit ed509db0 authored by Marcus Schiesser's avatar Marcus Schiesser
Browse files

feat[e2e]: add simple check for fastapi (folder exists)

parent 14413c06
No related branches found
No related tags found
No related merge requests found
/* eslint-disable turbo/no-undeclared-env-vars */
import { expect, test } from "@playwright/test";
import { ChildProcess } from "child_process";
import fs from "fs";
import path from "path";
import type {
TemplateEngine,
TemplateFramework,
......@@ -10,7 +12,11 @@ import type {
import { createTestDir, runApp, runCreateLlama, type AppType } from "./utils";
const templateTypes: TemplateType[] = ["streaming", "simple"];
const templateFrameworks: TemplateFramework[] = ["nextjs", "express"];
const templateFrameworks: TemplateFramework[] = [
"nextjs",
"express",
"fastapi",
];
const templateEngines: TemplateEngine[] = ["simple", "context"];
const templateUIs: TemplateUI[] = ["shadcn", "html"];
......@@ -32,12 +38,16 @@ for (const templateType of templateTypes) {
? "--no-frontend" // simple templates don't have frontends
: "--frontend"
: "";
if (appType === "--no-frontend" && templateUI !== "html") {
// if there's no frontend, don't iterate over UIs
continue;
}
test.describe(`try create-llama ${templateType} ${templateFramework} ${templateEngine} ${templateUI} ${appType}`, async () => {
let port: number;
let externalPort: number;
let cwd: string;
let name: string;
let cps: ChildProcess[];
let cps: ChildProcess[] = [];
test.beforeAll(async () => {
port = Math.floor(Math.random() * 10000) + 10000;
......@@ -54,11 +64,20 @@ for (const templateType of templateTypes) {
externalPort,
);
cps = await runApp(cwd, name, appType, port, externalPort);
if (templateFramework !== "fastapi") {
// don't run the app for fastapi for now (adds python dependency)
cps = await runApp(cwd, name, appType, port, externalPort);
}
});
test("App folder should exist", async () => {
const dirExists = fs.existsSync(path.join(cwd, name));
expect(dirExists).toBeTruthy();
});
test("Frontend should have a title", async ({ page }) => {
test.skip(appType === "--no-frontend");
test.skip(
appType === "--no-frontend" || templateFramework === "fastapi",
);
await page.goto(`http://localhost:${port}`);
await expect(page.getByText("Built by LlamaIndex")).toBeVisible();
});
......@@ -66,7 +85,9 @@ for (const templateType of templateTypes) {
test("Frontend should be able to submit a message and receive a response", async ({
page,
}) => {
test.skip(appType === "--no-frontend");
test.skip(
appType === "--no-frontend" || templateFramework === "fastapi",
);
await page.goto(`http://localhost:${port}`);
await page.fill("form input", "hello");
await page.click("form button[type=submit]");
......@@ -86,7 +107,9 @@ for (const templateType of templateTypes) {
test("Backend should response when calling API", async ({
request,
}) => {
test.skip(appType !== "--no-frontend");
test.skip(
appType !== "--no-frontend" || templateFramework === "fastapi",
);
const response = await request.post(
`http://localhost:${port}/api/chat`,
{
......
......@@ -24,7 +24,7 @@
"dev": "ncc build ./index.ts -w -o dist/",
"build": "npm run clean && ncc build ./index.ts -o ./dist/ && rm -fr dist/data dist/none dist/typescript dist/ui",
"lint": "eslint . --ignore-pattern dist",
"e2e": "playwright test --reporter=list",
"e2e": "playwright test",
"prepublishOnly": "cd ../../ && turbo run build"
},
"devDependencies": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment