Add project files
This commit is contained in:
24
e2e-tests/helpers/codegen.js
Normal file
24
e2e-tests/helpers/codegen.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* From: https://github.com/microsoft/playwright/issues/5181#issuecomment-2769098576
|
||||
*
|
||||
* Usage:
|
||||
* cd e2e-tests/helpers && node codegen.js
|
||||
*/
|
||||
|
||||
const { _electron: electron } = require("playwright");
|
||||
|
||||
(async () => {
|
||||
const browser = await electron.launch({
|
||||
args: [
|
||||
"../../out/dyad-darwin-arm64/dyad.app/Contents/Resources/app.asar/.vite/build/main.js",
|
||||
"--enable-logging",
|
||||
"--user-data-dir=/tmp/dyad-e2e-tests",
|
||||
],
|
||||
executablePath: "../../out/dyad-darwin-arm64/dyad.app/Contents/MacOS/dyad",
|
||||
});
|
||||
const context = await browser.context();
|
||||
await context.route("**/*", (route) => route.continue());
|
||||
|
||||
await require("node:timers/promises").setTimeout(3000); // wait for the window to load
|
||||
await browser.windows()[0].pause(); // .pause() opens the Playwright-Inspector for manual recording
|
||||
})();
|
||||
135
e2e-tests/helpers/generateAppFilesSnapshotData.ts
Normal file
135
e2e-tests/helpers/generateAppFilesSnapshotData.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
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 = [
|
||||
".DS_Store",
|
||||
".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>";
|
||||
for (const key in packageJson.dependencies) {
|
||||
if (key.startsWith("@capacitor/")) {
|
||||
packageJson.dependencies[key] = "<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;
|
||||
}
|
||||
1165
e2e-tests/helpers/test_helper.ts
Normal file
1165
e2e-tests/helpers/test_helper.ts
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user