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
@@ -126,7 +132,10 @@ class Runner extends Emittery {
126
132
}
127
133
}
128
134
135
+ const hash = this . getTitleHash ( title ) ;
136
+
129
137
const task = {
138
+ hash,
130
139
title,
131
140
implementation,
132
141
args,
@@ -136,7 +145,9 @@ class Runner extends Emittery {
136
145
if ( metadata . type === 'test' ) {
137
146
if ( this . match . length > 0 ) {
138
147
// --match overrides .only()
139
- task . metadata . exclusive = matcher ( [ title ] , this . match ) . length === 1 ;
148
+ const titleMatched = matcher ( [ title ] , this . match ) . length === 1 ;
149
+ const hashMatched = matcher ( [ hash ] , this . match ) . length === 1 ;
150
+ task . metadata . exclusive = titleMatched || hashMatched ;
140
151
}
141
152
142
153
if ( task . metadata . exclusive ) {
@@ -146,6 +157,7 @@ class Runner extends Emittery {
146
157
this . tasks [ metadata . serial ? 'serial' : 'concurrent' ] . push ( task ) ;
147
158
this . emit ( 'stateChange' , {
148
159
type : 'declared-test' ,
160
+ hash,
149
161
title,
150
162
knownFailing : metadata . failing ,
151
163
todo : false
@@ -166,6 +178,10 @@ class Runner extends Emittery {
166
178
} , meta ) ;
167
179
}
168
180
181
+ getTitleHash ( title ) {
182
+ return title ? objectHash ( title ) . substring ( 0 , 10 ) : undefined ;
183
+ }
184
+
169
185
compareTestSnapshot ( options ) {
170
186
if ( ! this . snapshots ) {
171
187
this . snapshots = snapshotManager . load ( {
@@ -276,20 +292,23 @@ class Runner extends Emittery {
276
292
compareTestSnapshot : this . boundCompareTestSnapshot ,
277
293
updateSnapshots : this . updateSnapshots ,
278
294
metadata : task . metadata ,
295
+ hash : this . getTitleHash ( `${ task . title } ${ titleSuffix || '' } ` ) ,
279
296
title : `${ task . title } ${ titleSuffix || '' } `
280
297
} ) ) ;
281
298
const outcome = await this . runMultiple ( hooks , this . serial ) ;
282
299
for ( const result of outcome . storedResults ) {
283
300
if ( result . passed ) {
284
301
this . emit ( 'stateChange' , {
285
302
type : 'hook-finished' ,
303
+ hash : result . hash ,
286
304
title : result . title ,
287
305
duration : result . duration ,
288
306
logs : result . logs
289
307
} ) ;
290
308
} else {
291
309
this . emit ( 'stateChange' , {
292
310
type : 'hook-failed' ,
311
+ hash : result . hash ,
293
312
title : result . title ,
294
313
err : serializeError ( 'Hook failure' , true , result . error ) ,
295
314
duration : result . duration ,
@@ -316,13 +335,15 @@ class Runner extends Emittery {
316
335
compareTestSnapshot : this . boundCompareTestSnapshot ,
317
336
updateSnapshots : this . updateSnapshots ,
318
337
metadata : task . metadata ,
338
+ hash : task . hash ,
319
339
title : task . title
320
340
} ) ;
321
341
322
342
const result = await this . runSingle ( test ) ;
323
343
if ( result . passed ) {
324
344
this . emit ( 'stateChange' , {
325
345
type : 'test-passed' ,
346
+ hash : result . hash ,
326
347
title : result . title ,
327
348
duration : result . duration ,
328
349
knownFailing : result . metadata . failing ,
@@ -332,6 +353,7 @@ class Runner extends Emittery {
332
353
} else {
333
354
this . emit ( 'stateChange' , {
334
355
type : 'test-failed' ,
356
+ hash : result . hash ,
335
357
title : result . title ,
336
358
err : serializeError ( 'Test failure' , true , result . error ) ,
337
359
duration : result . duration ,
@@ -356,6 +378,7 @@ class Runner extends Emittery {
356
378
357
379
this . emit ( 'stateChange' , {
358
380
type : 'selected-test' ,
381
+ hash : task . hash ,
359
382
title : task . title ,
360
383
knownFailing : task . metadata . failing ,
361
384
skip : task . metadata . skipped ,
@@ -374,6 +397,7 @@ class Runner extends Emittery {
374
397
375
398
this . emit ( 'stateChange' , {
376
399
type : 'selected-test' ,
400
+ hash : task . hash ,
377
401
title : task . title ,
378
402
knownFailing : task . metadata . failing ,
379
403
skip : task . metadata . skipped ,
@@ -396,6 +420,7 @@ class Runner extends Emittery {
396
420
397
421
this . emit ( 'stateChange' , {
398
422
type : 'selected-test' ,
423
+ hash : task . hash ,
399
424
title : task . title ,
400
425
knownFailing : false ,
401
426
skip : false ,
0 commit comments