Skip to content

Commit

Permalink
fix: the cypress reporter
Browse files Browse the repository at this point in the history
Cypress doesn't finish the process after the last test.
The reporter will wait for all results to be sent to Qase and will not block the process after sending.
  • Loading branch information
gibiw committed Jul 22, 2024
1 parent 438295b commit 26d5a73
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
7 changes: 7 additions & 0 deletions qase-cypress/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [email protected]

## What's new

Cypress doesn't finish the process after the last test.
The reporter will wait for all results to be sent to Qase and will not block the process after sending.

# [email protected]

## What's new
Expand Down
2 changes: 1 addition & 1 deletion qase-cypress/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cypress-qase-reporter",
"version": "2.0.2",
"version": "2.0.3",
"description": "Qase Cypress Reporter",
"homepage": "https://github.com/qase-tms/qase-javascript",
"sideEffects": false,
Expand Down
7 changes: 7 additions & 0 deletions qase-cypress/src/child.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const runChild = async () => {
setTimeout(() => {
// do nothing
}, 10000);
}

runChild();
22 changes: 2 additions & 20 deletions qase-cypress/src/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import { v4 as uuidv4 } from 'uuid';
import { spawnSync } from 'child_process';

import { MochaOptions, reporters, Runner, Suite, Test } from 'mocha';

Expand All @@ -25,9 +26,6 @@ const {

type CypressState = 'failed' | 'passed' | 'pending';

// eslint-disable-next-line @typescript-eslint/unbound-method
const _exit = process.exit;

export type CypressQaseOptionsType = Omit<MochaOptions, 'reporterOptions'> & {
reporterOptions: ReporterOptionsType;
};
Expand Down Expand Up @@ -148,12 +146,9 @@ export class CypressQaseReporter extends reporters.Base {

// eslint-disable-next-line @typescript-eslint/no-misused-promises
runner.once(EVENT_RUN_END, async () => {
this.preventExit();
await this.reporter.publish();

if (process.exitCode !== undefined) {
process.exit(process.exitCode);
}
spawnSync('node', [`${__dirname}/child.js`], { stdio: 'inherit' });
});
}

Expand Down Expand Up @@ -211,22 +206,9 @@ export class CypressQaseReporter extends reporters.Base {
title: test.title,
};

console.log(result.signature);
void this.reporter.addTestResult(result);
}

/**
* @private
*/
private preventExit() {
const mutableProcess: Record<'exit', (code: number) => void> = process;

mutableProcess.exit = (code: number) => {
process.exitCode = code || 0;
process.exit = _exit;
};
}

/**
* @param {Test} test
* @param {number[]} ids
Expand Down
2 changes: 1 addition & 1 deletion qase-cypress/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"noEmit": false
},

"include": ["./src/**/*.ts"]
"include": ["./src/**/*.ts", "./src/*.js"],
}

0 comments on commit 26d5a73

Please sign in to comment.