Skip to content
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

fix: the cypress reporter #639

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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"],
}
Loading