-
Notifications
You must be signed in to change notification settings - Fork 14
Use describe names for the suite name #198
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
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, | ||
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); | ||
}); | ||
|
||
test('HTML is available on ContentType enum', () => { | ||
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', '<div><p>This is an HTML doc</p></div', ContentType.HTML); | ||
|
||
expect(1 + 2).toBe(3); | ||
}); | ||
|
||
test('HTML is available on ContentType enum', () => { | ||
expect(ContentType.HTML).toStrictEqual('text/html'); | ||
}); | ||
}) |
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); | ||
}); | ||
}) |
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); | ||
}); | ||
}) |
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); | ||
}); | ||
}) |
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); | ||
}); | ||
}) |
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); | ||
}); |
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; | ||
}); | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,17 @@ 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After testing this with the original tests by running I also noticed that the test file name is not the highest layer of the tests report. To match other Allure library implementations this would be something we should support. Especially for cases where there are multiple describe blocks with the same name. One interesting way i've seen this implemented is in the Allure Jasmine library. They solve this by collecting the Something like this could allow us to detect wether the test is in fact wrapped in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
for example, I have very long spec files and for convenience I divide them into several files, but the tests in these files have a common describe and in the report I would like to see all these tests in one describe group There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, but my knowledge is probably not enough to implement this in the way you suggest using the start_describe_definition and finish_describe_definition events)) 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);
} 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;
} it will look like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ryparker can you take me any feedback |
||
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); | ||
} | ||
|
||
if (subSuite) { | ||
currentTest.addLabel(LabelName.SUB_SUITE, subSuite); | ||
} | ||
|
||
return currentTest; | ||
} | ||
|
||
|
There was a problem hiding this comment.
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 withdescribe