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

feature: added the ability to specify a test metadata in tests #693

Merged
merged 1 commit into from
Sep 26, 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
57 changes: 37 additions & 20 deletions qase-jest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ module.exports = {
Now, run the Jest tests as usual.
Test results will be reported to a new test run in Qase.


```console
$ npx jest
Determining test suites to run...
Expand All @@ -79,32 +78,49 @@ and suites from your test data.
But if necessary, you can independently register the ID of already
existing test cases from TMS before the executing tests. For example:

```typescript
const { qase } = require("jest-qase-reporter/jest");
### Metadata

describe('My First Test', () => {
test(qase([1,2], 'Several ids'), () => {
expect(true).toBe(true);
})
- `qase.title` - set the title of the test case
- `qase.fields` - set the fields of the test case
- `qase.suite` - set the suite of the test case
- `qase.comment` - set the comment of the test case
- `qase.parameters` - set the parameters of the test case
- `qase.groupParameters` - set the group parameters of the test case
- `qase.ignore` - ignore the test case in Qase. The test will be executed, but the results will not be sent to Qase.
- `qase.step` - create a step in the test case
- `qase.attach` - attach a file to the test case

test(qase(3, 'Correct test'), () => {
expect(true).toBe(true);
})

test.skip(qase("4", 'Skipped test'), () => {
expect(true).toBe(true);
})
```typescript
const { qase } = require('jest-qase-reporter/jest');

test(qase(["5", "6"], 'Failed test'), () => {
expect(true).toBe(false);
})
describe('My First Test', () => {
test(qase([1, 2], 'Several ids'), () => {
expect(true).toBe(true);
});

test(qase(3, 'Correct test'), () => {
qase.title('Title');
expect(true).toBe(true);
});

test.skip(qase('4', 'Skipped test'), () => {
expect(true).toBe(true);
});

test(qase(['5', '6'], 'Failed test'), () => {
expect(true).toBe(false);
});
});
```

To run tests and create a test run, execute the command (for example from folder examples):

```bash
QASE_MODE=testops npx jest
```

or

```bash
npm test
```
Expand All @@ -125,7 +141,7 @@ Reporter options (* - required):

- `mode` - `testops`/`off` Enables reporter, default - `off`
- `debug` - Enables debug logging, default - `false`
- `environment` - To execute with the sending of the envinroment information
- `environment` - To execute with the sending of the envinroment information
- *`testops.api.token` - Token for API access, you can find more information
[here](https://developers.qase.io/#authentication)
- *`testops.project` - Qase project code, for example, in https://app.qase.io/project/DEMO the code is `DEMO`
Expand Down Expand Up @@ -167,7 +183,7 @@ Supported ENV variables:

- `QASE_MODE` - Same as `mode`
- `QASE_DEBUG` - Same as `debug`
- `QASE_ENVIRONMENT` - Same as `environment`
- `QASE_ENVIRONMENT` - Same as `environment`
- `QASE_TESTOPS_API_TOKEN` - Same as `testops.api.token`
- `QASE_TESTOPS_PROJECT` - Same as `testops.project`
- `QASE_TESTOPS_RUN_ID` - Pass Run ID from ENV and override reporter option `testops.run.id`
Expand All @@ -176,7 +192,8 @@ Supported ENV variables:

## Requirements

We maintain the reporter on LTS versions of Node. You can find the current versions by following the [link](https://nodejs.org/en/about/releases/)
We maintain the reporter on LTS versions of Node. You can find the current versions by following
the [link](https://nodejs.org/en/about/releases/)

`jest >= 28.0.0`

Expand Down
39 changes: 38 additions & 1 deletion qase-jest/changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
# [email protected]

## What's new

Added the ability to specify a test metadata in tests:

- `qase.title` - set the test title
- `qase.fields` - set the test fields
- `qase.suite` - set the test suite
- `qase.comment` - set the test comment
- `qase.parameters` - set the test parameters
- `qase.groupParameters` - set the test group parameters
- `qase.ignore` - ignore the test in Qase
- `qase.attach` - attach a file to the test
- `qase.steps` - add the test steps

```ts
const { qase } = require('jest-qase-reporter/jest');

test('test', () => {
qase.title('Title');
qase.fields({ custom_field: 'value' });
qase.suite('Suite');
qase.comment('Comment');
qase.parameters({ param01: 'value' });
qase.groupParameters({ param02: 'value' });
qase.ignore();
qase.attach({ name: 'attachment.txt', content: 'Hello, world!', type: 'text/plain' });

qase.step('Step 1', () => {
expect(true).toBe(true);
});

expect(true).toBe(true);
});
```

# [email protected]

## What's new

Fixed a bug when a test was marked as skipped.
This reporter has uploaded this test as blocked.
This reporter has uploaded this test as blocked.
Right now the reporter will upload this test as skipped.

# [email protected]
Expand Down
4 changes: 2 additions & 2 deletions qase-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-qase-reporter",
"version": "2.0.2",
"version": "2.0.3",
"description": "Qase TMS Jest Reporter",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -45,7 +45,7 @@
"dependencies": {
"lodash.get": "^4.4.2",
"lodash.has": "^4.5.2",
"qase-javascript-commons": "~2.2.0",
"qase-javascript-commons": "~2.2.1",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand Down
69 changes: 69 additions & 0 deletions qase-jest/src/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { JestQaseReporter } from './reporter';
import { Attachment, TestStepType } from 'qase-javascript-commons';

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace NodeJS {
interface Global {
Qase: Qase;
}
}
}

export class Qase {
private reporter: JestQaseReporter;

constructor(reporter: JestQaseReporter) {
this.reporter = reporter;
}

title(title: string): void {
this.reporter.addTitle(title);
}

ignore(): void {
this.reporter.addIgnore();
}

comment(value: string): void {
this.reporter.addComment(value);
}

suite(value: string): void {
this.reporter.addSuite(value);
}

fields(values: Record<string, string>): void {
const stringRecord: Record<string, string> = {};
for (const [key, value] of Object.entries(values)) {
stringRecord[String(key)] = String(value);
}
this.reporter.addFields(stringRecord);
}

parameters(values: Record<string, string>): void {
const stringRecord: Record<string, string> = {};
for (const [key, value] of Object.entries(values)) {
stringRecord[String(key)] = String(value);
}
this.reporter.addParameters(stringRecord);
}

groupParams(values: Record<string, string>): void {
const stringRecord: Record<string, string> = {};
for (const [key, value] of Object.entries(values)) {
stringRecord[String(key)] = String(value);
}
this.reporter.addGroupParams(stringRecord);
}

step(step: TestStepType): void {
this.reporter.addStep(step);
}

attachment(attachment: Attachment): void {
this.reporter.addAttachment(attachment);
}
}

export {};
Loading
Loading