From 2cb6e5f0fb2da3756d3268248f758941c180e6b0 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 10 Jun 2021 11:20:23 +0300 Subject: [PATCH 1/5] Use describe names for the suite name issue #179 --- __tests__/allure-api/attachment.test.js | 33 +++++++------ __tests__/allure-api/description.test.js | 11 +++-- __tests__/allure-api/logStep.test.js | 19 ++++---- __tests__/allure-api/parameter.test.js | 13 ++--- __tests__/allure-api/severity.test.js | 62 ++++++++++++------------ __tests__/docblocks.test.js | 21 ++++---- __tests__/reporter.test.js | 30 ++++++++++++ __tests__/status.test.js | 34 +++++++------ src/allure-reporter.ts | 34 +++++-------- 9 files changed, 142 insertions(+), 115 deletions(-) create mode 100644 __tests__/reporter.test.js diff --git a/__tests__/allure-api/attachment.test.js b/__tests__/allure-api/attachment.test.js index 7b7bf30..931f4a0 100644 --- a/__tests__/allure-api/attachment.test.js +++ b/__tests__/allure-api/attachment.test.js @@ -1,10 +1,11 @@ const {ContentType} = require('../../dist'); -test('allure.attachment()', () => { - allure.attachment('TEXT-attachment', 'line1\nline2\nline3\n', ContentType.TEXT); - 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', +describe('Attachments', () => { + test('allure.attachment()', () => { + allure.attachment('TEXT-attachment', 'line1\nline2\nline3\n', ContentType.TEXT); + 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, @@ -12,15 +13,15 @@ test('allure.attachment()', () => { 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', '

This is an HTML doc

{ - expect(ContentType.HTML).toStrictEqual('text/html'); -}); + allure.attachment('JPEG-attachment', '', ContentType.JPEG); + allure.attachment('PNG-attachment', '', ContentType.PNG); + allure.attachment('SVG attachment', '', ContentType.SVG); + allure.attachment('HTML attachment', '

This is an HTML doc

{ + expect(ContentType.HTML).toStrictEqual('text/html'); + }); +}) \ No newline at end of file diff --git a/__tests__/allure-api/description.test.js b/__tests__/allure-api/description.test.js index fe19314..07f8f24 100644 --- a/__tests__/allure-api/description.test.js +++ b/__tests__/allure-api/description.test.js @@ -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); + }); +}) \ No newline at end of file diff --git a/__tests__/allure-api/logStep.test.js b/__tests__/allure-api/logStep.test.js index 844c044..3c6dd58 100644 --- a/__tests__/allure-api/logStep.test.js +++ b/__tests__/allure-api/logStep.test.js @@ -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); + }); +}) \ No newline at end of file diff --git a/__tests__/allure-api/parameter.test.js b/__tests__/allure-api/parameter.test.js index 522f50f..be71e67 100644 --- a/__tests__/allure-api/parameter.test.js +++ b/__tests__/allure-api/parameter.test.js @@ -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); + }); +}) diff --git a/__tests__/allure-api/severity.test.js b/__tests__/allure-api/severity.test.js index 84e507f..a785eb2 100644 --- a/__tests__/allure-api/severity.test.js +++ b/__tests__/allure-api/severity.test.js @@ -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); + }); +}) \ No newline at end of file diff --git a/__tests__/docblocks.test.js b/__tests__/docblocks.test.js index 0b1a73b..eceacaf 100644 --- a/__tests__/docblocks.test.js +++ b/__tests__/docblocks.test.js @@ -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); + }); +}) \ No newline at end of file diff --git a/__tests__/reporter.test.js b/__tests__/reporter.test.js new file mode 100644 index 0000000..6f333e4 --- /dev/null +++ b/__tests__/reporter.test.js @@ -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); +}); diff --git a/__tests__/status.test.js b/__tests__/status.test.js index f40fa63..b93c6fa 100644 --- a/__tests__/status.test.js +++ b/__tests__/status.test.js @@ -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; + }); +}) \ No newline at end of file diff --git a/src/allure-reporter.ts b/src/allure-reporter.ts index 764eed6..e16b158 100644 --- a/src/allure-reporter.ts +++ b/src/allure-reporter.ts @@ -1,5 +1,4 @@ import {createHash} from 'crypto'; -import * as os from 'os'; import { AllureGroup, AllureRuntime, @@ -178,7 +177,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); this.pushTest(currentTest); } @@ -369,27 +368,18 @@ export default class AllureReporter { } } - private addSuiteLabelsToTestCase(currentTest: AllureTest, 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(' > ')); + private addSuiteLabelsToTestCase(currentTest: AllureTest, parent: jest.Circus.DescribeBlock): AllureTest { + 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); + // currentTest.addLabel(LabelName.SUB_SUITE, parent.name); + } else if ((parent as any)?.parent && (parent as any)?.parent.name === 'ROOT_DESCRIBE_BLOCK') { + currentTest.addLabel(LabelName.PARENT_SUITE, (parent as any).name); } - - if (subSuite) { - currentTest.addLabel(LabelName.SUB_SUITE, subSuite); - } - return currentTest; } From 22025e7f12d4695203c5b8900e343493884e1604 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 11 Jun 2021 15:53:33 +0300 Subject: [PATCH 2/5] cleaning --- src/allure-reporter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/allure-reporter.ts b/src/allure-reporter.ts index e16b158..cd737cc 100644 --- a/src/allure-reporter.ts +++ b/src/allure-reporter.ts @@ -376,7 +376,6 @@ export default class AllureReporter { } 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); - // currentTest.addLabel(LabelName.SUB_SUITE, parent.name); } else if ((parent as any)?.parent && (parent as any)?.parent.name === 'ROOT_DESCRIBE_BLOCK') { currentTest.addLabel(LabelName.PARENT_SUITE, (parent as any).name); } From bfadd2fa7b2e82bdbfda132d6736ca84bdb980a9 Mon Sep 17 00:00:00 2001 From: Alex Neo Date: Thu, 21 Oct 2021 11:39:09 +0300 Subject: [PATCH 3/5] change view with no describe tests --- __tests__/allure-api/attachment.test.js | 46 ++++++++++++------------- src/allure-base-environment.ts | 12 ++++--- src/allure-reporter.ts | 36 ++++++++++++++----- 3 files changed, 57 insertions(+), 37 deletions(-) diff --git a/__tests__/allure-api/attachment.test.js b/__tests__/allure-api/attachment.test.js index 931f4a0..984c2d3 100644 --- a/__tests__/allure-api/attachment.test.js +++ b/__tests__/allure-api/attachment.test.js @@ -1,27 +1,25 @@ const {ContentType} = require('../../dist'); -describe('Attachments', () => { - test('allure.attachment()', () => { - allure.attachment('TEXT-attachment', 'line1\nline2\nline3\n', ContentType.TEXT); - 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); - allure.attachment('JPEG-attachment', '', ContentType.JPEG); - allure.attachment('PNG-attachment', '', ContentType.PNG); - allure.attachment('SVG attachment', '', ContentType.SVG); - allure.attachment('HTML attachment', '

This is an HTML doc

{ + allure.attachment('TEXT-attachment', 'line1\nline2\nline3\n', ContentType.TEXT); + 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); + allure.attachment('JPEG-attachment', '', ContentType.JPEG); + allure.attachment('PNG-attachment', '', ContentType.PNG); + allure.attachment('SVG attachment', '', ContentType.SVG); + allure.attachment('HTML attachment', '

This is an HTML doc

{ - expect(ContentType.HTML).toStrictEqual('text/html'); - }); -}) \ No newline at end of file +test('HTML is available on ContentType enum', () => { + expect(ContentType.HTML).toStrictEqual('text/html'); +}); \ No newline at end of file diff --git a/src/allure-base-environment.ts b/src/allure-base-environment.ts index afef7a9..2f21767 100644 --- a/src/allure-base-environment.ts +++ b/src/allure-base-environment.ts @@ -100,13 +100,15 @@ function extendAllureBaseEnvironment(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': diff --git a/src/allure-reporter.ts b/src/allure-reporter.ts index cd737cc..175ae32 100644 --- a/src/allure-reporter.ts +++ b/src/allure-reporter.ts @@ -1,4 +1,5 @@ import {createHash} from 'crypto'; +import * as os from 'os'; import { AllureGroup, AllureRuntime, @@ -177,7 +178,7 @@ export default class AllureReporter { currentTest.addLabel(LabelName.THREAD, state.parentProcess.env.JEST_WORKER_ID); } - currentTest = this.addSuiteLabelsToTestCase(currentTest, test.parent); + currentTest = this.addSuiteLabelsToTestCase(currentTest, test.parent, testPath); this.pushTest(currentTest); } @@ -368,17 +369,36 @@ export default class AllureReporter { } } - private addSuiteLabelsToTestCase(currentTest: AllureTest, parent: jest.Circus.DescribeBlock): 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 ((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); + 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); + 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); + 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; } From 8a7bd620600c14da2d7eb3bac247838bd6e92dcc Mon Sep 17 00:00:00 2001 From: Alex Neo Date: Thu, 21 Oct 2021 11:43:08 +0300 Subject: [PATCH 4/5] version up --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0eb79cf..7a260ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jest-circus-allure-environment", - "version": "1.1.1", + "version": "1.2.0", "repository": "https://github.com/ryparker/jest-circus-allure-environment.git", "author": "Ryan Parker ", "license": "MIT", From b721025c0d95f35010d67c91ecb40e7b1c5b2b7b Mon Sep 17 00:00:00 2001 From: Alex Neo Date: Thu, 21 Oct 2021 11:45:06 +0300 Subject: [PATCH 5/5] npm scope --- package.json | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7a260ce..bb5e4d4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,10 @@ { - "name": "jest-circus-allure-environment", + "name": "@alex_neo/jest-circus-allure-environment", "version": "1.2.0", - "repository": "https://github.com/ryparker/jest-circus-allure-environment.git", + "repository": { + "type": "git", + "url": "git+https://github.com/ryparker/jest-circus-allure-environment.git" + }, "author": "Ryan Parker ", "license": "MIT", "files": [ @@ -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" }