Skip to content

Commit c132a23

Browse files
committed
docs: update function definitions and links in documentation
1 parent 9022c1f commit c132a23

File tree

11 files changed

+92
-63
lines changed

11 files changed

+92
-63
lines changed

docs/functions/findTestById.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **findTestById**(`report`, `testId`): `undefined` \| [`Test`](../interfaces/Test.md)
1010
11-
Defined in: src/methods/test-id.ts:84
11+
Defined in: [src/methods/test-id.ts:91](https://github.com/ctrf-io/ctrf-core-js/blob/main/src/methods/test-id.ts#L91)
1212

1313
Finds a test by its ID in a report
1414

docs/functions/generateTestIdFromProperties.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **generateTestIdFromProperties**(`name`, `suite?`, `filePath?`): `string`
1010
11-
Defined in: src/methods/test-id.ts:95
11+
Defined in: [src/methods/test-id.ts:102](https://github.com/ctrf-io/ctrf-core-js/blob/main/src/methods/test-id.ts#L102)
1212

1313
Generates a new test ID based on test properties (exposed utility)
1414

docs/functions/getTestId.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **getTestId**(`test`): `string`
1010
11-
Defined in: src/methods/test-id.ts:61
11+
Defined in: [src/methods/test-id.ts:68](https://github.com/ctrf-io/ctrf-core-js/blob/main/src/methods/test-id.ts#L68)
1212

1313
Gets the test ID from a test object, generating one if it doesn't exist
1414

docs/functions/setTestId.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **setTestId**(`test`): [`Test`](../interfaces/Test.md)
1010
11-
Defined in: src/methods/test-id.ts:49
11+
Defined in: [src/methods/test-id.ts:56](https://github.com/ctrf-io/ctrf-core-js/blob/main/src/methods/test-id.ts#L56)
1212

1313
Sets a test ID for a test object based on its properties
1414

docs/functions/setTestIdsForReport.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **setTestIdsForReport**(`report`): [`Report`](../interfaces/Report.md)
1010
11-
Defined in: src/methods/test-id.ts:73
11+
Defined in: [src/methods/test-id.ts:80](https://github.com/ctrf-io/ctrf-core-js/blob/main/src/methods/test-id.ts#L80)
1212

1313
Sets test IDs for all tests in a report
1414

docs/functions/storePreviousResults.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **storePreviousResults**(`currentReport`, `previousReports`): [`Report`](../interfaces/Report.md)
1010
11-
Defined in: [src/methods/store-previous-results.ts:34](https://github.com/ctrf-io/ctrf-core-js/blob/main/src/methods/store-previous-results.ts#L34)
11+
Defined in: [src/methods/store-previous-results.ts:35](https://github.com/ctrf-io/ctrf-core-js/blob/main/src/methods/store-previous-results.ts#L35)
1212

1313
Stores previous results in the current report's previousResults array.
1414
Extracts key metrics from each previous report and adds them to the current report.

docs/variables/CTRF_NAMESPACE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> `const` **CTRF\_NAMESPACE**: `"6ba7b810-9dad-11d1-80b4-00c04fd430c8"` = `'6ba7b810-9dad-11d1-80b4-00c04fd430c8'`
1010
11-
Defined in: src/methods/test-id.ts:11
11+
Defined in: [src/methods/test-id.ts:11](https://github.com/ctrf-io/ctrf-core-js/blob/main/src/methods/test-id.ts#L11)
1212

1313
The CTRF namespace UUID used for generating deterministic test IDs.
1414
This namespace ensures that all CTRF test IDs are generated consistently

examples/test-id-example.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
This example demonstrates how to use the new deterministic test ID functionality.
44

55
```typescript
6-
import {
7-
setTestId,
8-
getTestId,
9-
setTestIdsForReport,
6+
import {
7+
setTestId,
8+
getTestId,
9+
setTestIdsForReport,
1010
findTestById,
11-
generateTestIdFromProperties
11+
generateTestIdFromProperties,
1212
} from 'ctrf'
1313
import type { Test, Report } from 'ctrf'
1414

@@ -18,7 +18,7 @@ const test: Test = {
1818
status: 'passed',
1919
duration: 150,
2020
suite: ['auth', 'login'],
21-
filePath: 'src/auth/login.test.ts'
21+
filePath: 'src/auth/login.test.ts',
2222
}
2323

2424
// Set a test ID (generates deterministic UUID based on properties)
@@ -40,7 +40,7 @@ console.log('Generated ID:', customId) // Always the same for these inputs
4040
// Demonstrate deterministic behavior
4141
const sameId = generateTestIdFromProperties(
4242
'my test',
43-
['suite1', 'suite2'],
43+
['suite1', 'suite2'],
4444
'my-test.ts'
4545
)
4646
console.log('Same ID?', customId === sameId) // true!
@@ -59,25 +59,25 @@ const report: Report = {
5959
pending: 0,
6060
other: 0,
6161
start: Date.now(),
62-
stop: Date.now() + 1000
62+
stop: Date.now() + 1000,
6363
},
6464
tests: [
6565
{
6666
name: 'test 1',
6767
status: 'passed',
6868
duration: 100,
6969
suite: ['unit'],
70-
filePath: 'test1.ts'
70+
filePath: 'test1.ts',
7171
},
7272
{
73-
name: 'test 2',
73+
name: 'test 2',
7474
status: 'passed',
7575
duration: 200,
7676
suite: ['integration'],
77-
filePath: 'test2.ts'
78-
}
79-
]
80-
}
77+
filePath: 'test2.ts',
78+
},
79+
],
80+
},
8181
}
8282

8383
// Set IDs for all tests

src/methods/test-id.test.ts

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ describe('test-id', () => {
5656
it('should add a deterministic UUID to a test without one', () => {
5757
const test = { ...mockTest }
5858
const result = setTestId(test)
59-
59+
6060
expect(result.id).toBeDefined()
6161
expect(typeof result.id).toBe('string')
62-
expect(result.id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
63-
62+
expect(result.id).toMatch(
63+
/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
64+
)
65+
6466
const test2 = { ...mockTest }
6567
const result2 = setTestId(test2)
6668
expect(result.id).toBe(result2.id)
@@ -69,7 +71,7 @@ describe('test-id', () => {
6971
it('should not overwrite existing ID', () => {
7072
const test = { ...mockTest, id: 'existing-id' }
7173
const result = setTestId(test)
72-
74+
7375
expect(result.id).toBe('existing-id')
7476
})
7577
})
@@ -78,19 +80,21 @@ describe('test-id', () => {
7880
it('should return existing ID', () => {
7981
const test = { ...mockTest, id: 'existing-id' }
8082
const result = getTestId(test)
81-
83+
8284
expect(result).toBe('existing-id')
8385
})
8486

8587
it('should generate and return deterministic UUID if none exists', () => {
8688
const test = { ...mockTest }
8789
const result = getTestId(test)
88-
90+
8991
expect(result).toBeDefined()
9092
expect(typeof result).toBe('string')
91-
expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
92-
expect(test.id).toBe(result)
93-
93+
expect(result).toMatch(
94+
/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
95+
)
96+
expect(test.id).toBe(result)
97+
9498
const test2 = { ...mockTest }
9599
const result2 = getTestId(test2)
96100
expect(result).toBe(result2)
@@ -99,9 +103,9 @@ describe('test-id', () => {
99103

100104
describe('setTestIdsForReport', () => {
101105
it('should set IDs for all tests in a report', () => {
102-
const report = JSON.parse(JSON.stringify(mockReport))
106+
const report = JSON.parse(JSON.stringify(mockReport))
103107
const result = setTestIdsForReport(report)
104-
108+
105109
expect(result.results.tests).toHaveLength(2)
106110
expect(result.results.tests[0].id).toBeDefined()
107111
expect(result.results.tests[1].id).toBeDefined()
@@ -111,9 +115,9 @@ describe('test-id', () => {
111115
it('should not overwrite existing IDs', () => {
112116
const report = JSON.parse(JSON.stringify(mockReport))
113117
report.results.tests[0].id = 'existing-id'
114-
118+
115119
const result = setTestIdsForReport(report)
116-
120+
117121
expect(result.results.tests[0].id).toBe('existing-id')
118122
expect(result.results.tests[1].id).toBeDefined()
119123
expect(result.results.tests[1].id).not.toBe('existing-id')
@@ -125,18 +129,18 @@ describe('test-id', () => {
125129
const report = JSON.parse(JSON.stringify(mockReport))
126130
report.results.tests[0].id = 'test-id-1'
127131
report.results.tests[1].id = 'test-id-2'
128-
132+
129133
const result = findTestById(report, 'test-id-1')
130-
134+
131135
expect(result).toBeDefined()
132136
expect(result?.name).toBe('test 1')
133137
})
134138

135139
it('should return undefined for non-existent ID', () => {
136140
const report = JSON.parse(JSON.stringify(mockReport))
137-
141+
138142
const result = findTestById(report, 'non-existent-id')
139-
143+
140144
expect(result).toBeUndefined()
141145
})
142146
})
@@ -148,11 +152,13 @@ describe('test-id', () => {
148152
['suite1', 'suite2'],
149153
'test.ts'
150154
)
151-
155+
152156
expect(result).toBeDefined()
153157
expect(typeof result).toBe('string')
154-
expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
155-
158+
expect(result).toMatch(
159+
/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
160+
)
161+
156162
const result2 = generateTestIdFromProperties(
157163
'test name',
158164
['suite1', 'suite2'],
@@ -163,16 +169,26 @@ describe('test-id', () => {
163169

164170
it('should handle missing optional parameters', () => {
165171
const result = generateTestIdFromProperties('test name')
166-
172+
167173
expect(result).toBeDefined()
168174
expect(typeof result).toBe('string')
169-
expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
175+
expect(result).toMatch(
176+
/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
177+
)
170178
})
171179

172180
it('should generate different UUIDs for different properties', () => {
173-
const result1 = generateTestIdFromProperties('test1', ['suite1'], 'file1.ts')
174-
const result2 = generateTestIdFromProperties('test2', ['suite2'], 'file2.ts')
175-
181+
const result1 = generateTestIdFromProperties(
182+
'test1',
183+
['suite1'],
184+
'file1.ts'
185+
)
186+
const result2 = generateTestIdFromProperties(
187+
'test2',
188+
['suite2'],
189+
'file2.ts'
190+
)
191+
176192
expect(result1).not.toBe(result2)
177193
})
178194
})
@@ -181,11 +197,13 @@ describe('test-id', () => {
181197
it('should be a valid UUID', () => {
182198
expect(CTRF_NAMESPACE).toBeDefined()
183199
expect(typeof CTRF_NAMESPACE).toBe('string')
184-
expect(CTRF_NAMESPACE).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)
200+
expect(CTRF_NAMESPACE).toMatch(
201+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
202+
)
185203
})
186204

187205
it('should be stable and not change', () => {
188206
expect(CTRF_NAMESPACE).toBe('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
189207
})
190208
})
191-
})
209+
})

src/methods/test-id.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Test, Report } from '../../types/ctrf.js'
55
* The CTRF namespace UUID used for generating deterministic test IDs.
66
* This namespace ensures that all CTRF test IDs are generated consistently
77
* across different implementations and tools.
8-
*
8+
*
99
* @public
1010
*/
1111
export const CTRF_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'
@@ -17,27 +17,34 @@ export const CTRF_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'
1717
* @param filePath - Test file path
1818
* @returns A deterministic UUID v5 string based on the properties
1919
*/
20-
function generateTestId(name: string, suite?: string[], filePath?: string): string {
20+
function generateTestId(
21+
name: string,
22+
suite?: string[],
23+
filePath?: string
24+
): string {
2125
const suiteString = suite ? suite.join('/') : ''
2226
const identifier = `${name}|${suiteString}|${filePath || ''}`
23-
24-
const namespaceBytes = CTRF_NAMESPACE.replace(/-/g, '').match(/.{2}/g)!.map(byte => parseInt(byte, 16))
25-
27+
28+
const namespaceBytes = CTRF_NAMESPACE.replace(/-/g, '')
29+
.match(/.{2}/g)!
30+
.map(byte => parseInt(byte, 16))
31+
2632
const input = Buffer.concat([
2733
Buffer.from(namespaceBytes),
28-
Buffer.from(identifier, 'utf8')
34+
Buffer.from(identifier, 'utf8'),
2935
])
30-
36+
3137
const hash = createHash('sha1').update(input).digest('hex')
32-
38+
3339
const uuid = [
3440
hash.substring(0, 8),
3541
hash.substring(8, 12),
3642
'5' + hash.substring(13, 16),
37-
((parseInt(hash.substring(16, 17), 16) & 0x3) | 0x8).toString(16) + hash.substring(17, 20),
38-
hash.substring(20, 32)
43+
((parseInt(hash.substring(16, 17), 16) & 0x3) | 0x8).toString(16) +
44+
hash.substring(17, 20),
45+
hash.substring(20, 32),
3946
].join('-')
40-
47+
4148
return uuid
4249
}
4350

@@ -93,9 +100,9 @@ export function findTestById(report: Report, testId: string): Test | undefined {
93100
* @returns A deterministic UUID v5 string based on the properties
94101
*/
95102
export function generateTestIdFromProperties(
96-
name: string,
97-
suite?: string[],
103+
name: string,
104+
suite?: string[],
98105
filePath?: string
99106
): string {
100107
return generateTestId(name, suite, filePath)
101-
}
108+
}

0 commit comments

Comments
 (0)