Files
crawler_js/test-generator.js
2026-03-30 01:32:43 +01:00

88 lines
1.6 KiB
JavaScript

// test-generator.js
//@5
/*
Reads from : flows.json
Writes to : tests/
Short friendly labels enabled
*/
console.log("Loading: test-generator.js");
import fs from "fs";
const data = JSON.parse(fs.readFileSync("./flows.json", "utf8"));
const flows = data.flows || [];
if (!fs.existsSync("tests")) fs.mkdirSync("tests");
let counter = 1;
for (const flow of flows) {
const testName = `test-${counter}.spec.js`;
const steps = flow
.map((url, i) => {
return ` await page.goto("${url}", { waitUntil: "networkidle" });`;
})
.join("\n");
const content = `
import { test } from "@playwright/test";
test("Flow ${counter}", async ({ page }) => {
${steps}
});
`.trimStart();
fs.writeFileSync(`tests/${testName}`, content);
counter++;
}
console.log("Generated tests/");
// test-generator.js
//@5
/*
Reads from : flows.json
Writes to : tests/
console.log("Loading: test-generator.js");
import fs from "fs";
const data = JSON.parse(fs.readFileSync("./flows.json", "utf8"));
const flows = data.flows || [];
if (!fs.existsSync("tests")) fs.mkdirSync("tests");
let counter = 1;
for (const flow of flows) {
const testName = `test-${counter}.spec.js`;
const steps = flow
.map((url, i) => {
if (i === 0) {
return ` await page.goto("${url}", { waitUntil: "networkidle" });`;
}
return ` await page.goto("${url}", { waitUntil: "networkidle" });`;
})
.join("\n");
const content = `
import { test } from "@playwright/test";
test("Flow ${counter}", async ({ page }) => {
${steps}
});
`.trimStart();
fs.writeFileSync(`tests/${testName}`, content);
counter++;
}
console.log("Generated tests/");
*/