Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Use describe names for the suite name #198

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 9 additions & 10 deletions __tests__/allure-api/attachment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ test('allure.attachment()', () => {
allure.attachment('CSS-attachment', 'CSS content', ContentType.CSS);
allure.attachment('CSV-attachment', 'a,b,c,d,e,f\n1,2,3,4,5,6', ContentType.CSV);
allure.attachment('JSON-attachment',
JSON.stringify({
string: 'foobar',
number: 1,
boolean: true,
function: () => console.log('Ok it works.')
}, null, 2),
ContentType.JSON);
JSON.stringify({
string: 'foobar',
number: 1,
boolean: true,
function: () => console.log('Ok it works.')
}, null, 2),
ContentType.JSON);
allure.attachment('JPEG-attachment', '', ContentType.JPEG);
allure.attachment('PNG-attachment', '', ContentType.PNG);
allure.attachment('SVG attachment', '', ContentType.SVG);
allure.attachment('HTML attachment', '<div><p>This is an HTML doc</p></div', ContentType.HTML);

expect(1 + 2).toBe(3);
});

Copy link
Owner

@ryparker ryparker Jun 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are still valuable for use cases where users have tests that do not use describe to wrap their tests. We should keep these as is and instead add new tests that wrap them with describe

test('HTML is available on ContentType enum', () => {
expect(ContentType.HTML).toStrictEqual('text/html');
});

});
11 changes: 6 additions & 5 deletions __tests__/allure-api/description.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

test('allure.description()', () => {
allure.description('This is an example description');
expect(5).toBe(5);
});
describe('Description', () => {
test('allure.description()', () => {
allure.description('This is an example description');
expect(5).toBe(5);
});
})
19 changes: 10 additions & 9 deletions __tests__/allure-api/logStep.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const {Status} = require('../../dist');

test('allure.logStep()', () => {
allure.logStep('This is a PASSED logStep', Status.PASSED);
allure.logStep('This is a FAILED logStep', Status.FAILED);
allure.logStep('This is a BLOCKED logStep', Status.BROKEN);
allure.logStep('This is a SKIPPED logStep', Status.SKIPPED);

expect(5).toBe(5);
});
describe('logStep', () => {
test('allure.logStep()', () => {
allure.logStep('This is a PASSED logStep', Status.PASSED);
allure.logStep('This is a FAILED logStep', Status.FAILED);
allure.logStep('This is a BLOCKED logStep', Status.BROKEN);
allure.logStep('This is a SKIPPED logStep', Status.SKIPPED);

expect(5).toBe(5);
});
})
13 changes: 7 additions & 6 deletions __tests__/allure-api/parameter.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

test('allure.parameter()', () => {
allure.parameter('Argument 1', 'exampleValue');

expect(5).toBe(5);
});
describe('Parameter', () => {
test('allure.parameter()', () => {
allure.parameter('Argument 1', 'exampleValue');

expect(5).toBe(5);
});
})
62 changes: 31 additions & 31 deletions __tests__/allure-api/severity.test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
const {Severity} = require('../../dist');

test('.severity = BLOCKER', () => {
allure.severity(Severity.BLOCKER);

expect(1 + 1).toBe(2);
});

test('.severity = CRITICAL', () => {
allure.severity(Severity.CRITICAL);

expect(1 + 1).toBe(2);
});

test('.severity = MINOR', () => {
allure.severity(Severity.MINOR);

expect(1 + 1).toBe(2);
});

test('.severity = NORMAL', () => {
allure.severity(Severity.NORMAL);

expect(1 + 1).toBe(2);
});

test('.severity = TRIVIAL', () => {
allure.severity(Severity.TRIVIAL);

expect(1 + 1).toBe(2);
});

describe('severity', () => {
test('.severity = BLOCKER', () => {
allure.severity(Severity.BLOCKER);
expect(1 + 1).toBe(2);
});
test('.severity = CRITICAL', () => {
allure.severity(Severity.CRITICAL);
expect(1 + 1).toBe(2);
});
test('.severity = MINOR', () => {
allure.severity(Severity.MINOR);
expect(1 + 1).toBe(2);
});
test('.severity = NORMAL', () => {
allure.severity(Severity.NORMAL);
expect(1 + 1).toBe(2);
});
test('.severity = TRIVIAL', () => {
allure.severity(Severity.TRIVIAL);
expect(1 + 1).toBe(2);
});
})
21 changes: 11 additions & 10 deletions __tests__/docblocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ function sum(a, b) {
/**
* @my-custom-pragma above-test1
*/
test('Ignore Docblock, when located above test', () => {
expect(sum(1, 2)).toBe(3);
});
describe('Docblock', () => {
test('Ignore Docblock, when located above test', () => {
expect(sum(1, 2)).toBe(3);
});

test('Read Docblock, when located under test', () => {
/**
* @my-custom-pragma under-test1
*/

expect(sum(1, 2)).toBe(3);
});
test('Read Docblock, when located under test', () => {
/**
* @my-custom-pragma under-test1
*/

expect(sum(1, 2)).toBe(3);
});
})
30 changes: 30 additions & 0 deletions __tests__/reporter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe('Root suite', () => {
describe('Nested root suite 1', () => {
it('first assert', async () => {
expect(true).toEqual(true);
});
describe('Nested Nested root suite 1', () => {
it('Nested Nested first assert', async () => {
expect(true).toEqual(true);
});
});
});

it('second assert', async () => {
expect(true).toEqual(true);
});

describe('Nested suite 2', () => {
it('suite 2 first assert', async () => {
expect(true).toEqual(true);
});

it('suite 2 second assert', async () => {
expect(true).toEqual(true);
});
});
});

it('ROOT assert', async () => {
expect(true).toEqual(true);
});
34 changes: 18 additions & 16 deletions __tests__/status.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
test('Expect to pass', () => {
expect(1 + 2).toBe(3);
});

test.skip('Expect to skip', () => {
expect(1 + 2).toBe(3);
});

test('Expect to fail', () => {
expect(2 + 2).toBe(6);
});

test('Expect to break', () => {
expect(3 + 2).toBe(5);
foo.bar;
});
describe('Status', () => {
test('Expect to pass', () => {
expect(1 + 2).toBe(3);
});

test.skip('Expect to skip', () => {
expect(1 + 2).toBe(3);
});

test('Expect to fail', () => {
expect(2 + 2).toBe(6);
});

test('Expect to break', () => {
expect(3 + 2).toBe(5);
foo.bar;
});
})
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "jest-circus-allure-environment",
"version": "1.1.1",
"repository": "https://github.com/ryparker/jest-circus-allure-environment.git",
"name": "@alex_neo/jest-circus-allure-environment",
"version": "1.2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/ryparker/jest-circus-allure-environment.git"
},
"author": "Ryan Parker <[email protected]>",
"license": "MIT",
"files": [
Expand Down Expand Up @@ -130,5 +133,10 @@
"reports",
"collect",
"analyze"
]
],
"description": "[![jest](https://jestjs.io/img/jest-badge.svg)](https://github.com/facebook/jest)\r ![Lint-Build-Test-Publish](https://github.com/ryparker/jest-circus-allure-reporter/workflows/Lint-Build-Test-Publish/badge.svg)\r [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)\r [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\r [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)",
"bugs": {
"url": "https://github.com/ryparker/jest-circus-allure-environment/issues"
},
"homepage": "https://github.com/ryparker/jest-circus-allure-environment#readme"
}
12 changes: 7 additions & 5 deletions src/allure-base-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ function extendAllureBaseEnvironment<TBase extends typeof JestEnvironment>(Base:
* @privateRemarks
* Only called if "describe()" blocks are present.
*/

console.log('start_describe_definition', event)

break;
case 'finish_describe_definition':
/**
* @privateRemarks
* Only called if "describe()" blocks are present.
*/
/**
* @privateRemarks
* Only called if "describe()" blocks are present.
*/
console.log('finish_describe_definition', event)

break;
case 'run_describe_start':
Expand Down
37 changes: 23 additions & 14 deletions src/allure-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class AllureReporter {
currentTest.addLabel(LabelName.THREAD, state.parentProcess.env.JEST_WORKER_ID);
}

currentTest = this.addSuiteLabelsToTestCase(currentTest, testPath);
currentTest = this.addSuiteLabelsToTestCase(currentTest, test.parent, testPath);
this.pushTest(currentTest);
}

Expand Down Expand Up @@ -369,27 +369,36 @@ export default class AllureReporter {
}
}

private addSuiteLabelsToTestCase(currentTest: AllureTest, testPath: string): AllureTest {
private addSuiteLabelsToTestCase(currentTest: AllureTest, parent: jest.Circus.DescribeBlock, testPath: string): AllureTest {
const isWindows = os.type() === 'Windows_NT';
const pathDelimiter = isWindows ? '\\' : '/';
const pathsArray = testPath.split(pathDelimiter);

const [parentSuite, ...suites] = pathsArray;
const subSuite = suites.pop();

if (parentSuite) {
currentTest.addLabel(LabelName.PARENT_SUITE, parentSuite);
currentTest.addLabel(LabelName.PACKAGE, parentSuite);
}

if (suites.length > 0) {
currentTest.addLabel(LabelName.SUITE, suites.join(' > '));
}

if (subSuite) {
currentTest.addLabel(LabelName.SUB_SUITE, subSuite);
if ((parent?.parent as any)?.parent?.parent && (parent?.parent as any)?.parent?.parent.name === 'ROOT_DESCRIBE_BLOCK') {
currentTest.addLabel(LabelName.PARENT_SUITE, (parent.parent as any).parent.name);
currentTest.addLabel(LabelName.SUITE, (parent.parent as any).name);
currentTest.addLabel(LabelName.SUB_SUITE, parent.name);
} else if ((parent?.parent as any)?.parent && (parent?.parent as any)?.parent.name === 'ROOT_DESCRIBE_BLOCK') {
currentTest.addLabel(LabelName.PARENT_SUITE, (parent.parent as any).name);
currentTest.addLabel(LabelName.SUITE, (parent as any).name);
} else if ((parent as any)?.parent && (parent as any)?.parent.name === 'ROOT_DESCRIBE_BLOCK') {
currentTest.addLabel(LabelName.PARENT_SUITE, (parent as any).name);
} else {
if (parentSuite) {
currentTest.addLabel(LabelName.PARENT_SUITE, parentSuite);
currentTest.addLabel(LabelName.PACKAGE, parentSuite);
}
if (suites.length > 0) {
currentTest.addLabel(LabelName.SUITE, suites.join(' > '));
}
if (subSuite) {
currentTest.addLabel(LabelName.SUB_SUITE, subSuite);
}
}

return currentTest;
}

Expand Down