Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rconner46 committed Apr 18, 2024
1 parent bcdff02 commit 7c1a6d1
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 35 deletions.
43 changes: 37 additions & 6 deletions dist/index.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.cjs.map

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions dist/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.min.js.map

Large diffs are not rendered by default.

43 changes: 37 additions & 6 deletions dist/index.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.mjs.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/auto-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,29 @@ export class AutoApi {
this.callsInFlight -= 1;
}
}

async uploadAsset(
resultId: number,
file: Buffer,
assetName: string,
providerSessionGuid: string,
assetType: string
): Promise<AxiosResponse<void>> {
this.callsInFlight += 1;

try {
// this filters out falsy values (null, undefined, 0)
return await this.client.postForm<void>(
`/api/v1.0/test-result/${resultId}/upload`,
{
file,
assetName,
providerSessionGuid,
assetType
}
);
} finally {
this.callsInFlight -= 1;
}
}
}
59 changes: 46 additions & 13 deletions src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@ export class ApplauseReporter {
this.initializer = new RunInitializer(this.autoApi);
}

public runnerStart(tests?: string[]): void {
public runnerStart(tests?: string[]): Promise<number> {
this.reporter = this.initializer.initializeRun(tests);
void this.reporter.then(() => {
return this.reporter.then(r => {
this.runStarted = true;
return r.testRunId;
});
}

public startTestCase(
id: string,
testCaseName: string,
params?: AdditionalTestCaseParams
): void {
): Promise<number> {
if (this.reporter === undefined) {
throw new Error(
'Cannot start a test case for a run that was never initialized'
);
}
void this.reporter.then(reporter =>
return this.reporter.then(reporter =>
reporter.startTestCase(id, testCaseName, params)
);
}
Expand All @@ -47,13 +48,13 @@ export class ApplauseReporter {
id: string,
status: TestResultStatus,
params?: AdditionalTestCaseResultParams
): void {
): Promise<number> {
if (this.reporter === undefined) {
throw new Error(
'Cannot submit test case result for a run that was never initialized'
);
}
void this.reporter.then(reporter =>
return this.reporter.then(reporter =>
reporter.submitTestCaseResult(id, status, params)
);
}
Expand All @@ -67,6 +68,20 @@ export class ApplauseReporter {
.then(() => (this.runFinished = true));
}

public async attachTestCaseAsset(
id: string,
assetName: string,
providerSessionGuid: string,
assetType: string,
asset: Buffer
): Promise<void> {
if (this.reporter === undefined) {
throw new Error('Cannot attach an asset for a run that was never initialized');
}
return await this.reporter
.then(reporter => reporter.attachTestCaseAsset(id, assetName, providerSessionGuid, assetType, asset))
}

public isSynchronized(): boolean {
// Verify the run is not yet started or it has ended, and all calls made to the applause api have finished
return (
Expand Down Expand Up @@ -102,21 +117,21 @@ export class RunInitializer {

export class RunReporter {
private uidToResultIdMap: Record<string, Promise<number>> = {};
private resultSubmissionMap: Record<string, Promise<void>> = {};
private resultSubmissionMap: Record<string, Promise<number>> = {};

constructor(
private autoApi: AutoApi,
private testRunId: number,
public readonly testRunId: number,
private heartbeatService: TestRunHeartbeatService
) {}

public startTestCase(
id: string,
testCaseName: string,
params?: AdditionalTestCaseParams
): void {
): Promise<number> {
const parsedTestCase = parseTestCaseName(testCaseName);
this.uidToResultIdMap[id] = this.autoApi
let submission = this.autoApi
.startTestCase({
testCaseName: parsedTestCase.testCaseName,
testCaseId: parsedTestCase.testRailTestCaseId,
Expand All @@ -131,20 +146,38 @@ export class RunReporter {
.then(res => {
return res.data.testResultId;
});
this.uidToResultIdMap[id] = submission;
return submission;
}

public submitTestCaseResult(
id: string,
status: TestResultStatus,
params?: AdditionalTestCaseResultParams
): void {
this.resultSubmissionMap[id] = this.uidToResultIdMap[id]?.then(resultId =>
): Promise<number> {
let submission = this.uidToResultIdMap[id]?.then(resultId =>
this.autoApi.submitTestCaseResult({
status: status,
testResultId: resultId,
...params,
})
}).then(() => resultId)
);
this.resultSubmissionMap[id] = submission;
return submission;
}

public attachTestCaseAsset(
id: string,
assetName: string,
providerSessionGuid: string,
assetType: string,
asset: Buffer
): Promise<any> {
let submission = this.uidToResultIdMap[id]?.then(resultId =>
this.autoApi.uploadAsset(resultId,
asset, assetName, providerSessionGuid, assetType)
);
return submission;
}

public async runnerEnd(): Promise<void> {
Expand Down

0 comments on commit 7c1a6d1

Please sign in to comment.