Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

read fixtures path from env var

Abi Rajace82fc87c471
diff --git a/frontend/.gitignore b/frontend/.gitignore
index 250cd485..a0d37028 100644
--- a/frontend/.gitignore
+++ b/frontend/.gitignore
@@ -26,5 +26,5 @@ dist-ssr
# Env files
.env*
-# QA files
-qa/**/*
+# Test files
+src/tests/results/
diff --git a/frontend/src/tests/fixtures/simple_button.png b/frontend/src/tests/fixtures/simple_button.png
new file mode 100644
index 00000000..e4f776bd
Binary files /dev/null and b/frontend/src/tests/fixtures/simple_button.png differ
diff --git a/frontend/src/tests/fixtures/simple_ui_with_image.png b/frontend/src/tests/fixtures/simple_ui_with_image.png
new file mode 100644
index 00000000..7533f850
Binary files /dev/null and b/frontend/src/tests/fixtures/simple_ui_with_image.png differ
diff --git a/frontend/src/tests/qa.test.ts b/frontend/src/tests/qa.test.ts
index 8fa99729..c05423d5 100644
--- a/frontend/src/tests/qa.test.ts
+++ b/frontend/src/tests/qa.test.ts
@@ -2,11 +2,11 @@ import puppeteer, { Browser, Page, ElementHandle } from "puppeteer";
import { Stack } from "../lib/stacks";
import { CodeGenerationModel } from "../lib/models";
-const REPO_PATH = "/Users/abi/Documents/GitHub/screenshot-to-code/frontend";
-const DOWNLOAD_PATH = `${REPO_PATH}/qa`;
-const SCREENSHOTS_PATH = `${REPO_PATH}/qa/results`;
-const IMAGE_PATH = DOWNLOAD_PATH + "/simple_button.png";
-const SCREENSHOT_WITH_IMAGES = `${DOWNLOAD_PATH}/simple_ui_with_image.png`;
+const TESTS_ROOT_PATH = process.env.TEST_ROOT_PATH;
+const RESULTS_DIR = `${TESTS_ROOT_PATH}/results`;
+const FIXTURES_PATH = `${TESTS_ROOT_PATH}/fixtures`;
+const SIMPLE_SCREENSHOT = FIXTURES_PATH + "/simple_button.png";
+const SCREENSHOT_WITH_IMAGES = `${FIXTURES_PATH}/simple_ui_with_image.png`;
describe("e2e tests", () => {
let browser: Browser;
@@ -30,13 +30,12 @@ describe("e2e tests", () => {
await page.setViewport({ width: 1080, height: 1024 });
// TODO: Does this need to be moved?
- const client = await page.createCDPSession();
-
+ // const client = await page.createCDPSession();
// Set download behavior path
- await client.send("Page.setDownloadBehavior", {
- behavior: "allow",
- downloadPath: DOWNLOAD_PATH,
- });
+ // await client.send("Page.setDownloadBehavior", {
+ // behavior: "allow",
+ // downloadPath: DOWNLOAD_PATH,
+ // });
});
afterAll(async () => {
@@ -83,14 +82,14 @@ describe("e2e tests", () => {
// Update tests - for every model (doesn’t need to be repeated for each stack - fix to HTML Tailwind only)
models.forEach((model) => {
["html_tailwind"].forEach((stack) => {
- it(
+ it.only(
`Update for : ${model}`,
async () => {
const app = new App(page, stack, model, `update_${model}_${stack}`);
await app.init();
// Generate from screenshot
- await app.uploadImage(IMAGE_PATH);
+ await app.uploadImage(SIMPLE_SCREENSHOT);
// Regenerate works for v1
await app.regenerate();
// Make an update
@@ -116,7 +115,7 @@ describe("e2e tests", () => {
await app.init();
// Generate from screenshot
- await app.uploadImage(IMAGE_PATH);
+ await app.uploadImage(SIMPLE_SCREENSHOT);
// Regenerate works for v1
await app.regenerate();
// Make an update
@@ -147,7 +146,7 @@ class App {
this.page = page;
this.stack = stack;
this.model = model;
- this.screenshotPathPrefix = `${SCREENSHOTS_PATH}/${testId}`;
+ this.screenshotPathPrefix = `${RESULTS_DIR}/${testId}`;
}
async init() {