Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.

Commit ffa23fb

Browse files
committed
Generate a stable historyId
1 parent 1903f12 commit ffa23fb

File tree

2 files changed

+53
-21
lines changed

2 files changed

+53
-21
lines changed

examples/regression/tests/Issue27.js

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,56 @@
11
const { action } = require('../../..')
22
const assert = require('assert')
3+
const expect = require('expect')
34
const fs = require('fs')
45
const glob = require('glob')
56
const { execFileSync } = require('child_process')
67

7-
action('Run test (it should fail)', async () => {
8-
let failed = false
8+
action('Clean the results directory', async () => {
99
execFileSync('rm', ['-rf', 'tmp/issue27-allure-results'])
10-
try {
11-
execFileSync(
12-
'./bin/prescript',
13-
[require.resolve('../fixtures/Issue27-AnsiColorTestFixture.js')],
14-
{
15-
env: {
16-
...process.env,
17-
ALLURE_RESULTS_DIR: 'tmp/issue27-allure-results',
18-
ALLURE_SUITE_NAME: 'prescript-regression-issue27',
19-
FORCE_COLOR: '1'
20-
}
21-
}
22-
)
23-
} catch (error) {
24-
failed = true
25-
}
26-
assert(failed, 'Expected prescript command to fail')
2710
})
2811

12+
for (let i = 1; i <= 3; i++) {
13+
action('Run test (it should fail)', async () => {
14+
let failed = false
15+
try {
16+
execFileSync(
17+
'./bin/prescript',
18+
[require.resolve('../fixtures/Issue27-AnsiColorTestFixture.js')],
19+
{
20+
env: {
21+
...process.env,
22+
ALLURE_RESULTS_DIR: 'tmp/issue27-allure-results',
23+
ALLURE_SUITE_NAME: 'prescript-regression-issue27',
24+
FORCE_COLOR: '1'
25+
}
26+
}
27+
)
28+
} catch (error) {
29+
failed = true
30+
}
31+
assert(failed, 'Expected prescript command to fail')
32+
})
33+
}
34+
2935
action('Verify that there are JSON allure results generated', async () => {
3036
const files = glob.sync('*.json', { cwd: 'tmp/issue27-allure-results' })
31-
assert(files.length > 0, 'Expected to file JSON files')
37+
assert(files.length > 0, 'Expected to find JSON files')
38+
})
39+
40+
action('Verify the test results JSON have consistent historyId', async () => {
41+
const files = glob.sync('*-result.json', {
42+
cwd: 'tmp/issue27-allure-results'
43+
})
44+
const historyIds = Array.from(
45+
new Set(
46+
files.map(
47+
f =>
48+
JSON.parse(fs.readFileSync(`tmp/issue27-allure-results/${f}`, 'utf8'))
49+
.historyId
50+
)
51+
)
52+
)
53+
expect(historyIds).toHaveLength(1)
3254
})
3355

3456
action('Generate an allure-report', async () => {

src/createReporter.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import {
88
AllureTest,
99
AllureStep,
1010
Stage,
11-
Status
11+
Status,
12+
LabelName
1213
} from 'allure-js-commons'
14+
import { hostname } from 'os'
1315
import { AllureWriter } from 'allure-js-commons/dist/src/writers'
1416

1517
export default function createReporter(testModulePath, rootStepName) {
@@ -29,6 +31,9 @@ export default function createReporter(testModulePath, rootStepName) {
2931
return `${testPath}${testName ? ` - ${testName}` : ''}`
3032
}
3133
const caseName = process.env.ALLURE_CASE_NAME || getDefaultCaseName()
34+
const historyId = createHash('md5')
35+
.update([suiteName, caseName].join(' / '))
36+
.digest('hex')
3237

3338
const allureConfig: IAllureConfig = {
3439
resultsDir: process.env.ALLURE_RESULTS_DIR || 'allure-results'
@@ -37,6 +42,11 @@ export default function createReporter(testModulePath, rootStepName) {
3742
const runtime = new AllureRuntime({ ...allureConfig, writer })
3843
const group = runtime.startGroup(suiteName)
3944
const test = group.startTest(caseName)
45+
const prescriptVersion = require('../package').version
46+
test.historyId = historyId
47+
test.addLabel(LabelName.THREAD, `${process.pid}`)
48+
test.addLabel(LabelName.HOST, `${hostname()}`)
49+
test.addLabel(LabelName.FRAMEWORK, `prescript@${prescriptVersion}`)
4050
let stack: IStepStack = new TestStepStack(test)
4151
singletonAllureInstance.currentReportingInterface = {
4252
addAttachment: (name, buf, mimeType) => {

0 commit comments

Comments
 (0)