Skip to content

Commit

Permalink
Merge pull request #46 from ApplauseOSS/public-api
Browse files Browse the repository at this point in the history
Minor updates to common reporter
  • Loading branch information
rconner46 authored Jul 31, 2024
2 parents c747041 + 0d5dd01 commit e341e41
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 120 deletions.
57 changes: 26 additions & 31 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.

31 changes: 21 additions & 10 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.

57 changes: 26 additions & 31 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.

44 changes: 1 addition & 43 deletions src/auto-api/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { TestRunHeartbeatService } from './heartbeat.ts';
import { join as pathJoin } from 'path';
import { AutoApiConfig } from './auto-api-config.ts';
import { parseTestCaseName } from '../shared/test-case.ts';

export class ApplauseReporter {
private autoApi: AutoApi;
Expand Down Expand Up @@ -173,46 +174,3 @@ export class RunReporter {
}
}
}
export const TEST_RAIL_CASE_ID_PREFIX: string = 'TestRail-';
export const APPLAUSE_CASE_ID_PREFIX: string = 'Applause-';

export function parseTestCaseName(testCaseName: string): ParsedTestCaseName {
// Split the name on spaces. We will reassemble after parsing out the other ids
const tokens = testCaseName.split(' ');
let testRailTestCaseId: string | undefined;
let applauseTestCaseId: string | undefined;
tokens.forEach(token => {
if (token?.startsWith(TEST_RAIL_CASE_ID_PREFIX)) {
if (testRailTestCaseId !== undefined) {
console.warn('Multiple TestRail case ids detected in testCase name');
}
testRailTestCaseId = token.substring(TEST_RAIL_CASE_ID_PREFIX.length);
} else if (token?.startsWith(APPLAUSE_CASE_ID_PREFIX)) {
if (applauseTestCaseId !== undefined) {
console.warn('Multiple Applause case ids detected in testCase name');
}
applauseTestCaseId = token.substring(APPLAUSE_CASE_ID_PREFIX.length);
}
});
return {
applauseTestCaseId,
testRailTestCaseId,
testCaseName: tokens
.filter(
token =>
token !== `${TEST_RAIL_CASE_ID_PREFIX}${testRailTestCaseId || ''}`
)
.filter(
token =>
token !== `${APPLAUSE_CASE_ID_PREFIX}${applauseTestCaseId || ''}`
)
.join(' ')
.trim(),
};
}

interface ParsedTestCaseName {
testCaseName: string;
testRailTestCaseId?: string;
applauseTestCaseId?: string;
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './auto-api/index.ts';
export * from './public-api/index.ts';
export * from './config/config.ts';
export * from './shared/index.ts';
13 changes: 12 additions & 1 deletion src/public-api/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface TestRunAutoResultDto {
testCycleId: number;
status: TestRunAutoResultStatus;
failureReason?: string;
sessionDetailsJson?: object;
sessionDetailsJson?: SessionDetails;
startTime?: Date;
endTime?: Date;
}
Expand All @@ -14,3 +14,14 @@ export enum TestRunAutoResultStatus {
CANCELED = 'CANCELED',
ERROR = 'ERROR',
}

export interface SessionDetails {
value: {
deviceName?: string;
orientation?: string;
platformName?: string;
platformVersion?: string;
browserName?: string;
browserVersion?: string;
};
}
1 change: 1 addition & 0 deletions src/shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './test-case.ts';
35 changes: 35 additions & 0 deletions src/shared/test-case.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export const TEST_RAIL_CASE_ID_PREFIX: string = 'TestRail-';
export const APPLAUSE_CASE_ID_PREFIX: string = 'Applause-';

export function parseTestCaseName(testCaseName: string): ParsedTestCaseName {
const matches = testCaseName.match(/(TestRail-\d+|Applause-\d+)/g);
const testRailCaseIds =
matches
?.filter(match => match.startsWith(TEST_RAIL_CASE_ID_PREFIX))
.map(match => match.substring(TEST_RAIL_CASE_ID_PREFIX.length)) || [];
const applauseCaseIds =
matches
?.filter(match => match.startsWith(APPLAUSE_CASE_ID_PREFIX))
.map(match => match.substring(APPLAUSE_CASE_ID_PREFIX.length)) || [];

if (testRailCaseIds.length > 1) {
console.warn('Multiple TestRail case ids detected in testCase name');
}
if (applauseCaseIds.length > 1) {
console.warn('Multiple Applause case ids detected in testCase name');
}
return {
applauseTestCaseId: applauseCaseIds[0],
testRailTestCaseId: testRailCaseIds[0],
testCaseName: testCaseName
.replace(/(TestRail-\d+|Applause-\d+)/g, '')
.replace(/\s+/g, ' ')
.trim(),
};
}

export interface ParsedTestCaseName {
testCaseName: string;
testRailTestCaseId?: string;
applauseTestCaseId?: string;
}
59 changes: 59 additions & 0 deletions test/test-case.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { parseTestCaseName, ParsedTestCaseName } from '../src/shared/test-case.ts';

describe('parseTestCaseName', () => {
it('should parse a test case name without any prefixes', () => {
const testCaseName = 'My Test Case';
const parsedTestCaseName: ParsedTestCaseName = parseTestCaseName(testCaseName);
expect(parsedTestCaseName.testCaseName).toEqual(testCaseName);
expect(parsedTestCaseName.testRailTestCaseId).toBeUndefined();
expect(parsedTestCaseName.applauseTestCaseId).toBeUndefined();
});

it('should parse a test case name with TestRail prefix', () => {
const testCaseName = 'TestRail-123 My Test Case';
const parsedTestCaseName: ParsedTestCaseName = parseTestCaseName(testCaseName);
expect(parsedTestCaseName.testCaseName).toEqual('My Test Case');
expect(parsedTestCaseName.testRailTestCaseId).toEqual('123');
expect(parsedTestCaseName.applauseTestCaseId).toBeUndefined();
});

it('should parse a test case name with Applause prefix', () => {
const testCaseName = 'Applause-456 My Test Case';
const parsedTestCaseName: ParsedTestCaseName = parseTestCaseName(testCaseName);
expect(parsedTestCaseName.testCaseName).toEqual('My Test Case');
expect(parsedTestCaseName.testRailTestCaseId).toBeUndefined();
expect(parsedTestCaseName.applauseTestCaseId).toEqual('456');
});

it('should parse a test case name with both TestRail and Applause prefixes', () => {
const testCaseName = 'TestRail-123 Applause-456 My Test Case';
const parsedTestCaseName: ParsedTestCaseName = parseTestCaseName(testCaseName);
expect(parsedTestCaseName.testCaseName).toEqual('My Test Case');
expect(parsedTestCaseName.testRailTestCaseId).toEqual('123');
expect(parsedTestCaseName.applauseTestCaseId).toEqual('456');
});

it('should parse a test case name with both TestRail and Applause prefixes, with no spaces between', () => {
const testCaseName = 'TestRail-123Applause-456 My Test Case';
const parsedTestCaseName: ParsedTestCaseName = parseTestCaseName(testCaseName);
expect(parsedTestCaseName.testCaseName).toEqual('My Test Case');
expect(parsedTestCaseName.testRailTestCaseId).toEqual('123');
expect(parsedTestCaseName.applauseTestCaseId).toEqual('456');
});

it('should parse a test case name with test case ids at the end of the test case name', () => {
const testCaseName = 'My Test Case TestRail-123';
const parsedTestCaseName: ParsedTestCaseName = parseTestCaseName(testCaseName);
expect(parsedTestCaseName.testCaseName).toEqual('My Test Case');
expect(parsedTestCaseName.testRailTestCaseId).toEqual('123');
expect(parsedTestCaseName.applauseTestCaseId).toBeUndefined();
});

it('should parse a test case name with test case ids in the middle of the test case name', () => {
const testCaseName = 'My Test Case TestRail-123 Another Test Case';
const parsedTestCaseName: ParsedTestCaseName = parseTestCaseName(testCaseName);
expect(parsedTestCaseName.testCaseName).toEqual('My Test Case Another Test Case');
expect(parsedTestCaseName.testRailTestCaseId).toEqual('123');
expect(parsedTestCaseName.applauseTestCaseId).toBeUndefined();
});
});

0 comments on commit e341e41

Please sign in to comment.