copy
Some checks failed
Test Environment Setup / setup-test-environment (push) Has been cancelled

This commit is contained in:
Lio 2025-06-26 13:38:01 +02:00
parent 26375a13b1
commit 2ea8c6d791
8 changed files with 15 additions and 43 deletions

View file

@ -16,8 +16,6 @@
"**/.env*": true, "**/.env*": true,
"**/.next": true, "**/.next": true,
"**/.pnpm-store": true, "**/.pnpm-store": true,
"**/.vscode": true,
"**/*.config*": true,
"**/biome.jsonc": true, "**/biome.jsonc": true,
"**/next-env.d.ts": true, "**/next-env.d.ts": true,
"**/node_modules": true, "**/node_modules": true,

View file

@ -19,7 +19,7 @@ export async function GET() {
duration: number; duration: number;
success?: boolean; success?: boolean;
pending: boolean; pending: boolean;
created_at: Date; created_at: Date;
}>(`select * from test_runs;`) }>(`select * from test_runs;`)
.then((r) => r.rows); .then((r) => r.rows);
@ -31,7 +31,6 @@ export async function GET() {
(n, child) => n + Number(child.duration), (n, child) => n + Number(child.duration),
0 0
); );
return { return {
run_id: run.id, run_id: run.id,
run_name: run.name, run_name: run.name,
@ -45,6 +44,5 @@ export async function GET() {
})), })),
}; };
}); });
return NextResponse.json(formatted); return NextResponse.json(formatted);
} }

View file

@ -4,44 +4,26 @@ import pool from "@/utils/db";
export async function POST(request: Request) { export async function POST(request: Request) {
let runId; let runId;
try { try {
let { let {runName, testId, testName, path,duration, success, runId: passedRunId} = await request.json();
runName,
testId,
testName,
path,
duration,
success,
runId: passedRunId,
} = await request.json();
if (!passedRunId) { if (!passedRunId) {
const res = await pool const res = await pool
.query( .query(
`WITH new_run AS ( `WITH new_run AS ( INSERT INTO runs (name) VALUES ($1) RETURNING id)
INSERT INTO runs (name) SELECT id FROM new_run;`,
VALUES ($1)
RETURNING id
)
SELECT id FROM new_run;`,
[runName], [runName],
) )
.then((r) => r.rows[0].id); .then((r) => r.rows[0].id);
return NextResponse.json({ runId: res }); return NextResponse.json({ runId: res });
} }
if (!testId) { if (!testId) {
const res = await pool.query( const res = await pool.query(`INSERT INTO test_runs (run_id, test_name, path)
`INSERT INTO test_runs (run_id, test_name, path)
VALUES ($1, $2, $3) returning id`, VALUES ($1, $2, $3) returning id`,
[passedRunId, testName, path], [passedRunId, testName, path],
); );
return NextResponse.json({ return NextResponse.json({
testId: res.rows[0].id, testId: res.rows[0].id,
}); });
} }
if (testId) { if (testId) {
if (duration) { if (duration) {
await pool.query( await pool.query(
@ -55,13 +37,8 @@ export async function POST(request: Request) {
} catch (error) { } catch (error) {
console.error("Error creating run:", error); console.error("Error creating run:", error);
return NextResponse.json( return NextResponse.json(
{ // @ts-ignore
error: "Failed to create run", {error: "Failed to create run", message: error.message, detail: error.detail},
// @ts-ignore
message: error.message,
// @ts-ignore
detail: error.detail,
},
{ status: 500 }, { status: 500 },
); );
} }

View file

@ -11,10 +11,6 @@ export const handleExportCSV = (dateGroup: any) => {
"Success", "Success",
"Duration (s)" "Duration (s)"
]; ];
console.log(dateGroup);
console.log(toCSV(headers, dateGroup));
// Create and trigger download // Create and trigger download
const blob = new Blob([...toCSV(headers, dateGroup)], { const blob = new Blob([...toCSV(headers, dateGroup)], {
type: "text/csv;charset=utf-8;", type: "text/csv;charset=utf-8;",
@ -32,3 +28,4 @@ export const handleExportCSV = (dateGroup: any) => {
link.click(); link.click();
document.body.removeChild(link); document.body.removeChild(link);
}; };

View file

@ -17,3 +17,5 @@ export default function toCSV(
return [headers.join(","), ...a.map((row) => row.join(","))].join("\n"); return [headers.join(","), ...a.map((row) => row.join(","))].join("\n");
} }

View file

@ -1,12 +1,12 @@
const { defineConfig } = require("cypress"); const { defineConfig } = require("cypress");
const apiRequestPlugin = require("./src/index"); const setupAnalyticsPlugin = require("./src/index");
module.exports = defineConfig({ module.exports = defineConfig({
historyTrackerURL: "http://localhost:3001", historyTrackerURL: "http://localhost:3001",
e2e: { e2e: {
setupNodeEvents(on, config) { setupNodeEvents(on, config) {
// Set up the API request plugin // Set up the analytics plugin
apiRequestPlugin(on, config); setupAnalyticsPlugin(on, config);
return config; return config;
}, },
}, },

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 190 KiB

View file

@ -55,7 +55,7 @@ const apiRequests = {
// Track if event handlers have been registered to prevent duplicate registrations // Track if event handlers have been registered to prevent duplicate registrations
let eventHandlersRegistered = false; let eventHandlersRegistered = false;
function setupApiRequestPlugin(on, config) { function setupAnalyticsPlugin(on, config) {
// If event handlers are already registered, don't register them again // If event handlers are already registered, don't register them again
if (eventHandlersRegistered) { if (eventHandlersRegistered) {
console.log("API plugin event handlers already registered, skipping..."); console.log("API plugin event handlers already registered, skipping...");
@ -142,4 +142,4 @@ function setupApiRequestPlugin(on, config) {
console.log("API plugin event handlers registered successfully"); console.log("API plugin event handlers registered successfully");
} }
module.exports = setupApiRequestPlugin; module.exports = setupAnalyticsPlugin;