Skip to content

Commit

Permalink
Fix tests finishing
Browse files Browse the repository at this point in the history
  • Loading branch information
AmsterGet committed Feb 14, 2024
1 parent 90768ce commit c894c2f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export { LAUNCH_MODES } from './launchModes';
export { TEST_ITEM_TYPES } from './testItemTypes';
export { STATUSES } from './statuses';
export { LOG_LEVELS } from './logLevels';
export { TASK_STATE } from './vitest';
export { TASK_STATUS, TASK_MODE, FINISHED_STATES } from './vitest';
7 changes: 6 additions & 1 deletion src/constants/vitest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
export enum TASK_STATE {
export enum TASK_MODE {
run = 'run',
skip = 'skip',
only = 'only',
todo = 'todo',
}

export enum TASK_STATUS {
pass = 'pass',
fail = 'fail',
}

export const FINISHED_STATES = ['pass', 'fail', 'skip'];
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@

import { RPReporter } from './reporter';

export { RPReporter };

export default RPReporter;
47 changes: 33 additions & 14 deletions src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@
*/

import RPClient from '@reportportal/client-javascript';
import { File, Reporter, Task, TaskResult, TaskResultPack, UserConsoleLog, Vitest } from 'vitest';
import {
File,
Reporter,
Task,
TaskResult,
TaskResultPack,
UserConsoleLog,
Vitest,
TaskState,
} from 'vitest';
import {
Attribute,
FinishTestItemObjType,
Expand All @@ -32,7 +41,15 @@ import {
getCodeRef,
getBasePath,
} from './utils';
import { LAUNCH_MODES, LOG_LEVELS, STATUSES, TEST_ITEM_TYPES, TASK_STATE } from './constants';
import {
LAUNCH_MODES,
LOG_LEVELS,
STATUSES,
TEST_ITEM_TYPES,
TASK_MODE,
TASK_STATUS,
FINISHED_STATES,
} from './constants';

export interface TestItem {
id: string;
Expand Down Expand Up @@ -122,11 +139,11 @@ export class RPReporter implements Reporter {
const tempId = testItemObj.tempId;

// Finish statically skipped test immediately as its result won't be derived to _onTaskUpdate_
if (mode === TASK_STATE.skip || mode === TASK_STATE.todo) {
if (mode === TASK_MODE.skip || mode === TASK_MODE.todo) {
const finishTestItemObj: FinishTestItemObjType = {
endTime: startTime,
status: STATUSES.SKIPPED,
attributes: mode === TASK_STATE.todo ? [{ value: TASK_STATE.todo }] : [],
attributes: mode === TASK_MODE.todo ? [{ value: TASK_MODE.todo }] : [],
};
const { promise } = this.client.finishTestItem(tempId, finishTestItemObj);
this.addRequestToPromisesQueue(promise, 'Failed to finish test item.');
Expand Down Expand Up @@ -156,7 +173,7 @@ export class RPReporter implements Reporter {

for (const [id, taskResult] of packsReversed) {
const testItemId = this.testItems.get(id)?.id;
if (!testItemId) {
if (!testItemId || !FINISHED_STATES.includes(taskResult?.state)) {
continue;
}

Expand All @@ -180,17 +197,17 @@ export class RPReporter implements Reporter {

getFinishTestItemObj(taskResult: TaskResult): FinishTestItemObjType {
const finishTestItemObj: FinishTestItemObjType = {
status: STATUSES.PASSED,
status: STATUSES.FAILED,
};

switch (taskResult.state) {
case TASK_STATE.pass:
case TASK_STATE.fail:
case TASK_STATUS.pass:
case TASK_STATUS.fail:
finishTestItemObj.status =
taskResult.state === TASK_STATE.fail ? STATUSES.FAILED : STATUSES.PASSED;
taskResult.state === TASK_STATUS.fail ? STATUSES.FAILED : STATUSES.PASSED;
finishTestItemObj.endTime = taskResult.startTime + taskResult.duration;
break;
case TASK_STATE.skip:
case TASK_MODE.skip:
finishTestItemObj.status = STATUSES.SKIPPED;
break;
default:
Expand Down Expand Up @@ -239,8 +256,9 @@ export class RPReporter implements Reporter {
this.launchId = null;
}

// onTestRemoved(trigger?: string) {
// }
onTestRemoved(trigger?: string) {
console.log('onTestRemoved ', trigger);
}

// onWatcherStart(files?: File[], errors?: unknown[]) {
// }
Expand All @@ -252,6 +270,7 @@ export class RPReporter implements Reporter {
// }

// TODO: Interrupt the launch?
// onProcessTimeout() {
// }
onProcessTimeout() {
console.log('onProcessTimeout');
}
}

0 comments on commit c894c2f

Please sign in to comment.