Skip to content

[no-ticket] always finish created builds #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions visual-js/visual-snapshots/src/app/pdf-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,43 @@ export interface PdfCommandParams
concurrency: number;
}

export enum PdfCommandStatus {
SUCCESS,
FAILURE,
}

export class PdfCommandHandler {
constructor(
private readonly visualSnapshotsApi: VisualSnapshotsApi,
private readonly pdfSnapshotUploader: PdfSnapshotUploader
) {}

public async handle(globsOrDirs: string[], params: PdfCommandParams) {
public async handle(
globsOrDirs: string[],
params: PdfCommandParams
): Promise<PdfCommandStatus> {
const pdfFilePaths = await getFiles(globsOrDirs, "*.pdf");

const buildId =
params.buildId ?? (await this.visualSnapshotsApi.createBuild(params));

await this.pdfSnapshotUploader.uploadSnapshots({
buildId,
pdfFilePaths,
suiteName: params.suiteName,
testNameFormat: params.testName,
snapshotNameFormat: params.snapshotName,
});
let status: PdfCommandStatus;
try {
await this.pdfSnapshotUploader.uploadSnapshots({
buildId,
pdfFilePaths,
suiteName: params.suiteName,
testNameFormat: params.testName,
snapshotNameFormat: params.snapshotName,
});
status = PdfCommandStatus.SUCCESS;
} catch (_) {
status = PdfCommandStatus.FAILURE;
}

if (!params.buildId) {
await this.visualSnapshotsApi.finishBuild(buildId);
}
return status;
}
}
20 changes: 16 additions & 4 deletions visual-js/visual-snapshots/src/commands/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
suiteNameOption,
usernameOption,
} from "./options.js";
import { PdfCommandHandler, PdfCommandParams } from "../app/pdf-handler.js";
import {
PdfCommandHandler,
PdfCommandParams,
PdfCommandStatus,
} from "../app/pdf-handler.js";
import { EOL } from "os";
import { VisualSnapshotsApi } from "../api/visual-snapshots-api.js";
import { initializeVisualApi } from "../api/visual-client.js";
Expand Down Expand Up @@ -67,11 +71,19 @@ export const pdfCommand = (clientVersion: string) => {

new PdfCommandHandler(visualSnapshotsApi, pdfSnapshotUploader)
.handle(globsOrDirs, params)
.then(() => {
console.log("Successfully created PDF snapshots");
.then((status: PdfCommandStatus) => {
if (status == PdfCommandStatus.SUCCESS) {
console.info("Successfully created PDF snapshots.");
} else {
console.error(
"At least one PDF snapshot creation failed. Please contact Sauce Labs customer support."
);
}
})
.catch((err) => {
console.error(`An error occured when creating PDF snapshots: ${err}`);
console.error(
`An unexpected error occured when creating PDF snapshots: ${err}. Please contact Sauce Labs customer support.`
);
});
});
};
Loading