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

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

parent 18055f68
No related branches found
No related tags found
No related merge requests found
/* eslint-disable turbo/no-undeclared-env-vars */ /* eslint-disable turbo/no-undeclared-env-vars */
import { expect, test } from "@playwright/test"; import { expect, test } from "@playwright/test";
import { ChildProcess } from "child_process"; import { ChildProcess } from "child_process";
import fs from "fs";
import path from "path";
import type { import type {
TemplateEngine, TemplateEngine,
TemplateFramework, TemplateFramework,
...@@ -10,7 +12,11 @@ import type { ...@@ -10,7 +12,11 @@ import type {
import { createTestDir, runApp, runCreateLlama, type AppType } from "./utils"; import { createTestDir, runApp, runCreateLlama, type AppType } from "./utils";
const templateTypes: TemplateType[] = ["streaming", "simple"]; const templateTypes: TemplateType[] = ["streaming", "simple"];
const templateFrameworks: TemplateFramework[] = ["nextjs", "express"]; const templateFrameworks: TemplateFramework[] = [
"nextjs",
"express",
"fastapi",
];
const templateEngines: TemplateEngine[] = ["simple", "context"]; const templateEngines: TemplateEngine[] = ["simple", "context"];
const templateUIs: TemplateUI[] = ["shadcn", "html"]; const templateUIs: TemplateUI[] = ["shadcn", "html"];
...@@ -32,12 +38,16 @@ for (const templateType of templateTypes) { ...@@ -32,12 +38,16 @@ for (const templateType of templateTypes) {
? "--no-frontend" // simple templates don't have frontends ? "--no-frontend" // simple templates don't have frontends
: "--frontend" : "--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 () => { test.describe(`try create-llama ${templateType} ${templateFramework} ${templateEngine} ${templateUI} ${appType}`, async () => {
let port: number; let port: number;
let externalPort: number; let externalPort: number;
let cwd: string; let cwd: string;
let name: string; let name: string;
let cps: ChildProcess[]; let cps: ChildProcess[] = [];
test.beforeAll(async () => { test.beforeAll(async () => {
port = Math.floor(Math.random() * 10000) + 10000; port = Math.floor(Math.random() * 10000) + 10000;
...@@ -54,11 +64,20 @@ for (const templateType of templateTypes) { ...@@ -54,11 +64,20 @@ for (const templateType of templateTypes) {
externalPort, 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("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 page.goto(`http://localhost:${port}`);
await expect(page.getByText("Built by LlamaIndex")).toBeVisible(); await expect(page.getByText("Built by LlamaIndex")).toBeVisible();
}); });
...@@ -66,7 +85,9 @@ for (const templateType of templateTypes) { ...@@ -66,7 +85,9 @@ for (const templateType of templateTypes) {
test("Frontend should be able to submit a message and receive a response", async ({ test("Frontend should be able to submit a message and receive a response", async ({
page, page,
}) => { }) => {
test.skip(appType === "--no-frontend"); test.skip(
appType === "--no-frontend" || templateFramework === "fastapi",
);
await page.goto(`http://localhost:${port}`); await page.goto(`http://localhost:${port}`);
await page.fill("form input", "hello"); await page.fill("form input", "hello");
await page.click("form button[type=submit]"); await page.click("form button[type=submit]");
...@@ -86,7 +107,9 @@ for (const templateType of templateTypes) { ...@@ -86,7 +107,9 @@ for (const templateType of templateTypes) {
test("Backend should response when calling API", async ({ test("Backend should response when calling API", async ({
request, request,
}) => { }) => {
test.skip(appType !== "--no-frontend"); test.skip(
appType !== "--no-frontend" || templateFramework === "fastapi",
);
const response = await request.post( const response = await request.post(
`http://localhost:${port}/api/chat`, `http://localhost:${port}/api/chat`,
{ {
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
"dev": "ncc build ./index.ts -w -o dist/", "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", "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", "lint": "eslint . --ignore-pattern dist",
"e2e": "playwright test --reporter=list", "e2e": "playwright test",
"prepublishOnly": "cd ../../ && turbo run build" "prepublishOnly": "cd ../../ && turbo run build"
}, },
"devDependencies": { "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