129
e2e-tests/helpers/generateAppFilesSnapshotData.ts
Normal file
129
e2e-tests/helpers/generateAppFilesSnapshotData.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import crypto from "crypto";
|
||||
|
||||
export interface FileSnapshotData {
|
||||
relativePath: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
const binaryExtensions = new Set([
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".gif",
|
||||
".webp",
|
||||
".tiff",
|
||||
".psd",
|
||||
".raw",
|
||||
".bmp",
|
||||
".heif",
|
||||
".ico",
|
||||
".pdf",
|
||||
".eot",
|
||||
".otf",
|
||||
".ttf",
|
||||
".woff",
|
||||
".woff2",
|
||||
".zip",
|
||||
".tar",
|
||||
".gz",
|
||||
".7z",
|
||||
".rar",
|
||||
".mov",
|
||||
".mp4",
|
||||
".m4v",
|
||||
".mkv",
|
||||
".webm",
|
||||
".flv",
|
||||
".avi",
|
||||
".wmv",
|
||||
".mp3",
|
||||
".wav",
|
||||
".ogg",
|
||||
".flac",
|
||||
".exe",
|
||||
".dll",
|
||||
".so",
|
||||
".a",
|
||||
".lib",
|
||||
".o",
|
||||
".db",
|
||||
".sqlite3",
|
||||
".wasm",
|
||||
]);
|
||||
|
||||
function isBinaryFile(filePath: string): boolean {
|
||||
return binaryExtensions.has(path.extname(filePath).toLowerCase());
|
||||
}
|
||||
|
||||
export function generateAppFilesSnapshotData(
|
||||
currentPath: string,
|
||||
basePath: string,
|
||||
): FileSnapshotData[] {
|
||||
const ignorePatterns = [
|
||||
".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 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));
|
||||
} else if (entry.isFile()) {
|
||||
const relativePath = path
|
||||
.relative(basePath, entryPath)
|
||||
// Normalize path separators to always use /
|
||||
// to prevent diffs on Windows.
|
||||
.replace(/\\/g, "/");
|
||||
try {
|
||||
if (isBinaryFile(entryPath)) {
|
||||
const fileBuffer = fs.readFileSync(entryPath);
|
||||
const hash = crypto
|
||||
.createHash("sha256")
|
||||
.update(fileBuffer)
|
||||
.digest("hex");
|
||||
files.push({
|
||||
relativePath,
|
||||
content: `[binary hash="${hash}"]`,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
let content = fs
|
||||
.readFileSync(entryPath, "utf-8")
|
||||
// Normalize line endings to always use \n
|
||||
.replace(/\r\n/g, "\n");
|
||||
if (entry.name === "package.json") {
|
||||
const packageJson = JSON.parse(content);
|
||||
packageJson.packageManager = "<scrubbed>";
|
||||
content = JSON.stringify(packageJson, null, 2);
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user