Fixes #12
This commit is contained in:
Will Chen
2025-06-05 22:26:17 -07:00
committed by GitHub
parent 97ed34cf08
commit d3fbb48472
18 changed files with 6386 additions and 65 deletions

View File

@@ -5,6 +5,7 @@ import fs from "fs";
import path from "path";
import os from "os";
import { execSync } from "child_process";
import { generateAppFilesSnapshotData } from "./generateAppFilesSnapshotData";
const showDebugLogs = process.env.DEBUG_LOGS === "true";
@@ -80,14 +81,7 @@ export class PageObject {
}
await expect(() => {
const filesData = generateAppFilesSnapshotData(appPath, appPath, [
".git",
"node_modules",
// Avoid snapshotting lock files because they are getting generated
// automatically and cause noise, and not super important anyways.
"package-lock.json",
"pnpm-lock.yaml",
]);
const filesData = generateAppFilesSnapshotData(appPath, appPath);
// Sort by relative path to ensure deterministic output
filesData.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
@@ -97,7 +91,7 @@ export class PageObject {
.join("\n\n");
if (name) {
expect(snapshotContent).toMatchSnapshot(name);
expect(snapshotContent).toMatchSnapshot(name + ".txt");
} else {
expect(snapshotContent).toMatchSnapshot();
}
@@ -378,6 +372,10 @@ export class PageObject {
await this.page.getByTestId(`app-list-item-${appName}`).click();
}
async clickOpenInChatButton() {
await this.page.getByRole("button", { name: "Open in Chat" }).click();
}
async clickAppDetailsRenameAppButton() {
await this.page.getByTestId("app-details-rename-app-button").click();
}
@@ -386,6 +384,10 @@ export class PageObject {
await this.page.getByTestId("app-details-more-options-button").click();
}
async clickAppDetailsCopyAppButton() {
await this.page.getByRole("button", { name: "Copy app" }).click();
}
async clickConnectSupabaseButton() {
await this.page.getByTestId("connect-supabase-button").click();
}
@@ -406,10 +408,13 @@ export class PageObject {
const settings = path.join(this.userDataDir, "user-settings.json");
const settingsContent = fs.readFileSync(settings, "utf-8");
// Sanitize the "telemetryUserId" since it's a UUID
const sanitizedSettingsContent = settingsContent.replace(
/"telemetryUserId": "[^"]*"/g,
'"telemetryUserId": "[UUID]"',
);
const sanitizedSettingsContent = settingsContent
.replace(/"telemetryUserId": "[^"]*"/g, '"telemetryUserId": "[UUID]"')
// Don't snapshot this otherwise it'll diff with every release.
.replace(
/"lastShownReleaseNotesVersion": "[^"]*"/g,
'"lastShownReleaseNotesVersion": "[scrubbed]"',
);
expect(sanitizedSettingsContent).toMatchSnapshot();
}
@@ -652,48 +657,3 @@ function prettifyDump(
})
.join("\n\n");
}
interface FileSnapshotData {
relativePath: string;
content: string;
}
function generateAppFilesSnapshotData(
currentPath: string,
basePath: string,
ignorePatterns: string[],
): FileSnapshotData[] {
const entries = fs.readdirSync(currentPath, { withFileTypes: true });
let files: FileSnapshotData[] = [];
// Sort entries for deterministic order
entries.sort((a, b) => a.name.localeCompare(b.name));
for (const entry of entries) {
const entryPath = path.join(currentPath, entry.name);
if (ignorePatterns.includes(entry.name)) {
continue;
}
if (entry.isDirectory()) {
files = files.concat(
generateAppFilesSnapshotData(entryPath, basePath, ignorePatterns),
);
} else if (entry.isFile()) {
const relativePath = path.relative(basePath, entryPath);
try {
const content = fs.readFileSync(entryPath, "utf-8");
files.push({ relativePath, content });
} catch (error) {
// Could be a binary file or permission issue, log and add a placeholder
const e = error as Error;
console.warn(`Could not read file ${entryPath}: ${e.message}`);
files.push({
relativePath,
content: `[Error reading file: ${e.message}]`,
});
}
}
}
return files;
}