1
1
'use strict' ;
2
2
const Emittery = require ( 'emittery' ) ;
3
3
const matcher = require ( 'matcher' ) ;
4
+ const objectHash = require ( 'object-hash' ) ;
4
5
const ContextRef = require ( './context-ref' ) ;
5
6
const createChain = require ( './create-chain' ) ;
6
7
const snapshotManager = require ( './snapshot-manager' ) ;
@@ -79,9 +80,13 @@ class Runner extends Emittery {
79
80
uniqueTestTitles . add ( specifiedTitle ) ;
80
81
}
81
82
83
+ const specifiedHash = this . getTitleHash ( specifiedTitle )
84
+
82
85
if ( this . match . length > 0 ) {
83
86
// --match selects TODO tests.
84
- if ( matcher ( [ specifiedTitle ] , this . match ) . length === 1 ) {
87
+ const titleMatched = matcher ( [ specifiedTitle ] , this . match ) . length === 1 ;
88
+ const hashMatched = matcher ( [ specifiedHash ] , this . match ) . length === 1 ;
89
+ if ( titleMatched || hashMatched ) {
85
90
metadata . exclusive = true ;
86
91
this . runOnlyExclusive = true ;
87
92
}
@@ -90,6 +95,7 @@ class Runner extends Emittery {
90
95
this . tasks . todo . push ( { title : specifiedTitle , metadata} ) ;
91
96
this . emit ( 'stateChange' , {
92
97
type : 'declared-test' ,
98
+ hash : specifiedHash ,
93
99
title : specifiedTitle ,
94
100
knownFailing : false ,
95
101
todo : true
@@ -125,8 +131,10 @@ class Runner extends Emittery {
125
131
uniqueTestTitles . add ( title ) ;
126
132
}
127
133
}
134
+ const hash = this . getTitleHash ( title ) ;
128
135
129
136
const task = {
137
+ hash,
130
138
title,
131
139
implementation,
132
140
args,
@@ -136,7 +144,9 @@ class Runner extends Emittery {
136
144
if ( metadata . type === 'test' ) {
137
145
if ( this . match . length > 0 ) {
138
146
// --match overrides .only()
139
- task . metadata . exclusive = matcher ( [ title ] , this . match ) . length === 1 ;
147
+ const titleMatched = matcher ( [ title ] , this . match ) . length === 1 ;
148
+ const hashMatched = matcher ( [ hash ] , this . match ) . length === 1 ;
149
+ task . metadata . exclusive = titleMatched || hashMatched ;
140
150
}
141
151
142
152
if ( task . metadata . exclusive ) {
@@ -146,6 +156,7 @@ class Runner extends Emittery {
146
156
this . tasks [ metadata . serial ? 'serial' : 'concurrent' ] . push ( task ) ;
147
157
this . emit ( 'stateChange' , {
148
158
type : 'declared-test' ,
159
+ hash,
149
160
title,
150
161
knownFailing : metadata . failing ,
151
162
todo : false
@@ -165,7 +176,9 @@ class Runner extends Emittery {
165
176
always : false
166
177
} , meta ) ;
167
178
}
168
-
179
+ getTitleHash ( title ) {
180
+ return title ? objectHash ( title ) . substring ( 0 , 10 ) : undefined ;
181
+ }
169
182
compareTestSnapshot ( options ) {
170
183
if ( ! this . snapshots ) {
171
184
this . snapshots = snapshotManager . load ( {
@@ -276,20 +289,23 @@ class Runner extends Emittery {
276
289
compareTestSnapshot : this . boundCompareTestSnapshot ,
277
290
updateSnapshots : this . updateSnapshots ,
278
291
metadata : task . metadata ,
292
+ hash : this . getTitleHash ( `${ task . title } ${ titleSuffix || '' } ` ) ,
279
293
title : `${ task . title } ${ titleSuffix || '' } `
280
294
} ) ) ;
281
295
const outcome = await this . runMultiple ( hooks , this . serial ) ;
282
296
for ( const result of outcome . storedResults ) {
283
297
if ( result . passed ) {
284
298
this . emit ( 'stateChange' , {
285
299
type : 'hook-finished' ,
300
+ hash : result . hash ,
286
301
title : result . title ,
287
302
duration : result . duration ,
288
303
logs : result . logs
289
304
} ) ;
290
305
} else {
291
306
this . emit ( 'stateChange' , {
292
307
type : 'hook-failed' ,
308
+ hash : result . hash ,
293
309
title : result . title ,
294
310
err : serializeError ( 'Hook failure' , true , result . error ) ,
295
311
duration : result . duration ,
@@ -316,13 +332,15 @@ class Runner extends Emittery {
316
332
compareTestSnapshot : this . boundCompareTestSnapshot ,
317
333
updateSnapshots : this . updateSnapshots ,
318
334
metadata : task . metadata ,
335
+ hash : task . hash ,
319
336
title : task . title
320
337
} ) ;
321
338
322
339
const result = await this . runSingle ( test ) ;
323
340
if ( result . passed ) {
324
341
this . emit ( 'stateChange' , {
325
342
type : 'test-passed' ,
343
+ hash : result . hash ,
326
344
title : result . title ,
327
345
duration : result . duration ,
328
346
knownFailing : result . metadata . failing ,
@@ -332,6 +350,7 @@ class Runner extends Emittery {
332
350
} else {
333
351
this . emit ( 'stateChange' , {
334
352
type : 'test-failed' ,
353
+ hash : result . hash ,
335
354
title : result . title ,
336
355
err : serializeError ( 'Test failure' , true , result . error ) ,
337
356
duration : result . duration ,
@@ -356,6 +375,7 @@ class Runner extends Emittery {
356
375
357
376
this . emit ( 'stateChange' , {
358
377
type : 'selected-test' ,
378
+ hash : task . hash ,
359
379
title : task . title ,
360
380
knownFailing : task . metadata . failing ,
361
381
skip : task . metadata . skipped ,
@@ -374,6 +394,7 @@ class Runner extends Emittery {
374
394
375
395
this . emit ( 'stateChange' , {
376
396
type : 'selected-test' ,
397
+ hash : task . hash ,
377
398
title : task . title ,
378
399
knownFailing : task . metadata . failing ,
379
400
skip : task . metadata . skipped ,
@@ -396,6 +417,7 @@ class Runner extends Emittery {
396
417
397
418
this . emit ( 'stateChange' , {
398
419
type : 'selected-test' ,
420
+ hash : task . hash ,
399
421
title : task . title ,
400
422
knownFailing : false ,
401
423
skip : false ,
0 commit comments