Skip to content

Commit

Permalink
Merge pull request #147 from argos-ci/test-report
Browse files Browse the repository at this point in the history
test report
  • Loading branch information
gregberge authored Sep 2, 2024
2 parents d5b9650 + 95edc87 commit dd61776
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 72 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"check-types": "pnpm -r exec tsc",
"test": "vitest",
"release": "npm run build && lerna publish --conventional-commits --create-release=github",
"release-canary": "npm run build && lerna publish --force-publish --canary --dist-tag canary"
"release-canary": "npm run build && lerna publish --force-publish --dist-tag canary --canary"
},
"engines": {
"node": "20",
Expand Down
2 changes: 2 additions & 0 deletions packages/api-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import createFetchClient, { FetchResponse } from "openapi-fetch";
import type { paths } from "./schema";

export * as ArgosAPISchema from "./schema";

export type ArgosAPIClient = ReturnType<typeof createClient>;

/**
Expand Down
159 changes: 95 additions & 64 deletions packages/api-client/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,23 @@ export interface paths {
export type webhooks = Record<string, never>;
export interface components {
schemas: {
/** @description SHA1 hash */
Sha1Hash: string;
/** @description SHA256 hash */
Sha256Hash: string;
/** @description Build */
Build: {
/**
* @description A unique identifier for the build
* @example 12345
*/
id: string;
id: components["schemas"]["BuildId"];
/** @description The build number */
number: number;
/** @description The status of the build */
status: ("accepted" | "rejected") | ("stable" | "diffDetected") | ("expired" | "pending" | "progress" | "error" | "aborted");
/** Format: uri */
/**
* Format: uri
* @description The URL of the build
*/
url: string;
/** @description The notification payload for the build */
notification: {
description: string;
context: string;
Expand All @@ -112,6 +118,11 @@ export interface components {
};
} | null;
};
/**
* @description A unique identifier for the build
* @example 12345
*/
BuildId: string;
/** @description Error response */
Error: {
error: string;
Expand All @@ -124,6 +135,76 @@ export interface components {
* @example 12345
*/
buildId: string;
/** @description Screenshot input */
ScreenshotInput: {
key: string;
name: string;
baseName?: string | null;
metadata?: {
url?: string;
viewport?: {
width: number;
height: number;
};
/** @enum {string} */
colorScheme?: "light" | "dark";
/** @enum {string} */
mediaType?: "screen" | "print";
test?: {
id?: string;
title: string;
titlePath: string[];
retries?: number;
retry?: number;
repeat?: number;
location?: {
file: string;
line: number;
column: number;
};
} | null;
browser?: {
name: string;
version: string;
};
automationLibrary: {
name: string;
version: string;
};
sdk: {
name: string;
version: string;
};
} | null;
pwTraceKey?: string | null;
threshold?: number | null;
};
/** @description Build metadata */
BuildMetadata: {
testReport?: {
/** @enum {string} */
status: "passed" | "failed" | "timedout" | "interrupted";
stats?: {
startTime?: string;
duration?: number;
};
};
};
/** @description Project */
Project: {
id: string;
defaultBaseBranch: string;
hasRemoteContentAccess: boolean;
};
/** @description Page information */
PageInfo: {
/** @description Total number of items */
total: number;
/** @description Current page number */
page: number;
/** @description Number of items per page */
perPage: number;
};
};
responses: never;
parameters: never;
Expand All @@ -143,10 +224,10 @@ export interface operations {
requestBody?: {
content: {
"application/json": {
commit: string;
commit: components["schemas"]["Sha1Hash"];
branch: string;
screenshotKeys: string[];
pwTraceKeys?: string[];
screenshotKeys: components["schemas"]["Sha256Hash"][];
pwTraceKeys?: components["schemas"]["Sha256Hash"][];
name?: string | null;
parallel?: boolean | null;
parallelNonce?: string | null;
Expand Down Expand Up @@ -318,52 +399,11 @@ export interface operations {
requestBody?: {
content: {
"application/json": {
screenshots: {
key: string;
name: string;
baseName?: string | null;
metadata?: {
url?: string;
viewport?: {
width: number;
height: number;
};
/** @enum {string} */
colorScheme?: "light" | "dark";
/** @enum {string} */
mediaType?: "screen" | "print";
test?: {
id?: string;
title: string;
titlePath: string[];
retries?: number;
retry?: number;
repeat?: number;
location?: {
file: string;
line: number;
column: number;
};
} | null;
browser?: {
name: string;
version: string;
};
automationLibrary: {
name: string;
version: string;
};
sdk: {
name: string;
version: string;
};
} | null;
pwTraceKey?: string | null;
threshold?: number | null;
}[];
screenshots: components["schemas"]["ScreenshotInput"][];
parallel?: boolean | null;
parallelTotal?: number | null;
parallelIndex?: number | null;
metadata?: components["schemas"]["BuildMetadata"];
};
};
};
Expand Down Expand Up @@ -450,11 +490,7 @@ export interface operations {
[name: string]: unknown;
};
content: {
"application/json": {
id: string;
defaultBaseBranch: string;
hasRemoteContentAccess: boolean;
};
"application/json": components["schemas"]["Project"];
};
};
/** @description Unauthorized */
Expand Down Expand Up @@ -484,8 +520,7 @@ export interface operations {
perPage?: string;
/** @description Page number */
page?: string;
/** @description Commit hash. */
commit?: string;
commit?: components["schemas"]["Sha1Hash"];
/** @description Only return the latest builds created, unique by name and commit. */
distinctName?: string;
};
Expand All @@ -502,11 +537,7 @@ export interface operations {
};
content: {
"application/json": {
pageInfo: {
total: number;
page: number;
perPage: number;
};
pageInfo: components["schemas"]["PageInfo"];
results: components["schemas"]["Build"][];
};
};
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/upload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { createClient, throwAPIError } from "@argos-ci/api-client";
import {
ArgosAPISchema,
createClient,
throwAPIError,
} from "@argos-ci/api-client";
import { readConfig } from "./config";
import { discoverScreenshots } from "./discovery";
import { optimizeScreenshot } from "./optimize";
Expand All @@ -16,6 +20,8 @@ import { getMergeBaseCommitSha } from "./ci-environment";
*/
const CHUNK_SIZE = 10;

type BuildMetadata = ArgosAPISchema.components["schemas"]["BuildMetadata"];

export interface UploadParameters {
/**
* Globs matching image file paths to upload
Expand Down Expand Up @@ -88,6 +94,10 @@ export interface UploadParameters {
* @default 0.5
*/
threshold?: number;
/**
* Build metadata.
*/
metadata?: BuildMetadata;
}

async function getConfigFromOptions({
Expand Down Expand Up @@ -324,6 +334,7 @@ export async function upload(params: UploadParameters) {
parallel: config.parallel,
parallelTotal: config.parallelTotal,
parallelIndex: config.parallelIndex,
metadata: params.metadata,
},
});

Expand Down
33 changes: 29 additions & 4 deletions packages/cypress/src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ export type RegisterArgosTaskOptions = Omit<
uploadToArgos?: boolean;
};

function checkIsCypressFailedResult(
results:
| CypressCommandLine.CypressFailedRunResult
| CypressCommandLine.CypressRunResult,
): results is CypressCommandLine.CypressFailedRunResult {
return "status" in results && results.status === "failed";
}

export function registerArgosTask(
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions,
Expand All @@ -37,16 +45,33 @@ export function registerArgosTask(

return { path: newPath };
});
on("after:run", async () => {
on("after:run", async (results) => {
const { screenshotsFolder } = config;
if (!screenshotsFolder) return;
if (!screenshotsFolder) {
return;
}
const { uploadToArgos = true } = options || {};
if (!uploadToArgos) return;
if (!uploadToArgos) {
return;
}

const res = await upload({
...options,
files: ["**/*.png"],
root: screenshotsFolder,
...options,
metadata: {
testReport: checkIsCypressFailedResult(results)
? { status: "failed" }
: {
status: "passed",
stats: {
startTime: results.startedTestsAt,
duration: results.totalDuration,
},
},
},
});

console.log(`✅ Argos build created: ${res.build.url}`);
});
}
14 changes: 12 additions & 2 deletions packages/playwright/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class ArgosReporter implements Reporter {
);
}

async onEnd(_result: FullResult) {
async onEnd(result: FullResult) {
debug("ArgosReporter:onEnd");
const rootUploadDir = await this.getRootUploadDirectory();
if (!this.uploadToArgos) {
Expand All @@ -258,7 +258,17 @@ class ArgosReporter implements Reporter {
files: ["**/*.png"],
parallel: parallel ?? undefined,
...this.config,
};
buildName: undefined, // We will set it later
metadata: {
testReport: {
status: result.status,
stats: {
startTime: result.startTime.toISOString(),
duration: result.duration,
},
},
},
} satisfies Partial<UploadParameters>;
try {
if (checkIsDynamicBuildName(buildNameConfig)) {
debug(
Expand Down

0 comments on commit dd61776

Please sign in to comment.