-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathcoverage.js
executable file
·718 lines (500 loc) · 25 KB
/
coverage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
'use strict';
const Fs = require('fs');
const Module = require('module');
const Os = require('os');
const Path = require('path');
const Code = require('@hapi/code');
const _Lab = require('../test_runner');
const Lab = require('../');
const Somever = require('@hapi/somever');
const internals = {
transform: [
{
ext: '.inl', transform: function (content, filename) {
if (Buffer.isBuffer(content)) {
content = content.toString();
}
return content.concat(Os.EOL).concat('//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndoaWxlLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGFBRUE7QUFHQTtBQUVBLEtBQU0sV0FBWSxFQUFsQixDQUdBLFFBQVEsTUFBUixDQUFpQixTQUFVLEtBQVYsQ0FBaUIsQ0FFOUIsTUFBUSxLQUFSLENBQWdCLENBQ1osTUFBUSxLQUFSLENBQ0gsQ0FFRCxNQUFPLE1BQVAsQ0FDSCxDQVBEIiwiZmlsZSI6InNvdXJjZW1hcHMtaW5saW5lLmpzIiwic291cmNlc0NvbnRlbnQiOlsiJ3VzZSBzdHJpY3QnO1xuXG4vLyBMb2FkIG1vZHVsZXNcblxuXG4vLyBEZWNsYXJlIGludGVybmFsc1xuXG5jb25zdCBpbnRlcm5hbHMgPSB7fTtcblxuXG5leHBvcnRzLm1ldGhvZCA9IGZ1bmN0aW9uICh2YWx1ZSkge1xuXG4gICAgd2hpbGUgKCB2YWx1ZSApIHtcbiAgICAgICAgdmFsdWUgPSBmYWxzZTtcbiAgICB9XG5cbiAgICByZXR1cm4gdmFsdWU7XG59O1xuIl19').concat(Os.EOL);
}
},
{ ext: '.js', transform: null }
]
};
const lab = exports.lab = _Lab.script();
const before = lab.before;
const describe = lab.describe;
const it = lab.it;
const expect = Code.expect;
describe('Coverage', () => {
const supportsNullishCoalescing = Somever.match(process.version, '>=14');
before({}, async () => {
await Lab.coverage.instrument({ coveragePath: Path.join(__dirname, 'coverage'), coverageExclude: 'exclude', 'coverage-predicates': { testing: true } });
});
it('computes sloc without comments', async () => {
const Test = require('./coverage/sloc');
Test.method(1);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/sloc') });
expect(cov.percent).to.equal(100);
});
it('computes sloc without comments on transformed file', async () => {
const Test = require('./coverage/transformed');
Test.method(1);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/transformed') });
expect(cov.percent).to.equal(100);
});
it('computes sloc on script that has no comments', async () => {
const Test = require('./coverage/nocomment');
Test.method(1);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/nocomment') });
expect(cov.percent).to.equal(100);
});
it('instruments and measures coverage', async () => {
const Test = require('./coverage/basic');
Test.method(1);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/basic') });
expect(cov.percent).to.equal(100);
});
it('measures coverage on an empty return statement', async () => {
const Test = require('./coverage/return');
Test.method();
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/return') });
expect(cov.percent).to.equal(100);
});
it('identifies lines with partial coverage', async () => {
const Test = require('./coverage/partial');
Test.method(1, 2, 3);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/partial') });
expect(Math.floor(cov.percent)).to.equal(61);
expect(cov.sloc).to.equal(49);
expect(cov.misses).to.equal(19);
expect(cov.hits).to.equal(30);
});
it('measures coverage of a file with test in the name', async () => {
const Test = require('./coverage/test-folder/test-name.js');
Test.method();
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/test-folder'), coverageExclude: ['test', 'node_modules'] });
expect(cov.percent).to.equal(100);
});
it('can exclude individual files by name', async () => {
const Test = require('./coverage/test-folder/test-name.js');
Test.method();
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/test-folder'), coverageExclude: ['test', 'node_modules', 'test-name.js'] });
expect(cov.percent).to.equal(0);
});
it('handles comma operator', async () => {
const Test = require('./coverage/comma');
expect(Test.method1(1)).to.equal(1);
expect(Test.method2(1)(2)).to.equal(2);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/comma') });
expect(cov.percent).to.equal(100);
});
it('logs to stderr when coverageExclude file has fs.stat issue', async (flags) => {
const Test = require('./coverage/test-folder/test-name.js');
Test.method();
const origStatSync = Fs.statSync;
const origErrorLog = console.error;
let calls = 0;
Fs.statSync = () => {
calls++;
if (calls === 3) {
// Only mock for first 3 calls
Fs.statSync = origStatSync;
}
const err = new Error();
err.code = 'BOOM';
throw err;
};
console.error = (data) => {
expect(data.code).to.equal('BOOM');
};
flags.onCleanup = () => {
Fs.statSync = origStatSync;
console.error = origErrorLog;
};
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/test-folder'), coverageExclude: ['test', 'node_modules', 'test-name.js'] });
expect(cov.percent).to.equal(100);
});
it('identifies lines with partial coverage when having external sourcemap', async () => {
const Test = require('./coverage/sourcemaps-external');
Test.method(false);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/sourcemaps-external'), sourcemaps: true });
const source = cov.files[0].source;
const missedLines = [];
Object.keys(source).forEach((lineNumber) => {
const line = source[lineNumber];
if (line.miss) {
missedLines.push({
filename: line.originalFilename,
lineNumber,
originalLineNumber: line.originalLine
});
}
});
expect(missedLines).to.include([
{ filename: 'while.js', lineNumber: '4', originalLineNumber: 13 },
{ filename: 'while.js', lineNumber: '5', originalLineNumber: 14 }
]);
});
it('identifies lines with partial coverage when having inline sourcemap', async () => {
const Test = require('./coverage/sourcemaps-inline');
Test.method(false);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/sourcemaps-inline'), sourcemaps: true });
const source = cov.files[0].source;
const missedLines = [];
const missedChunks = [];
Object.keys(source).forEach((lineNumber) => {
const line = source[lineNumber];
if (line.miss) {
missedLines.push({
filename: line.originalFilename,
lineNumber,
originalLineNumber: line.originalLine
});
if (line.chunks) {
line.chunks.forEach((chunk) => {
if (chunk.miss) {
missedChunks.push({
filename: chunk.originalFilename,
lineNumber,
originalLineNumber: chunk.originalLine,
originalColumn: chunk.originalColumn
});
}
});
}
}
});
expect(missedLines).to.include([
{ filename: 'while.js', lineNumber: '3', originalLineNumber: 11 }
]);
expect(missedChunks).to.include([
{ filename: 'while.js', lineNumber: '3', originalLineNumber: 13, originalColumn: 12 }
]);
});
it('bypasses marked code', async () => {
const Test = require('./coverage/bypass');
Test.method(1, 2, 3);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/bypass') });
expect(Math.floor(cov.percent)).to.equal(100);
expect(cov.sloc).to.equal(12);
expect(cov.misses).to.equal(0);
expect(cov.hits).to.equal(12);
});
it('ignores marked code', async () => {
const Test = require('./coverage/ignore');
Test.method();
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/ignore') });
expect(Math.floor(cov.percent)).to.equal(100);
expect(cov.sloc).to.equal(5);
expect(cov.misses).to.equal(0);
expect(cov.hits).to.equal(5);
});
it('ignores marked code when predicated', async () => {
const Test = require('./coverage/ignore-predicated');
Test.method();
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/ignore-predicated') });
expect(Math.floor(cov.percent)).to.equal(100);
expect(cov.sloc).to.equal(4);
expect(cov.misses).to.equal(0);
expect(cov.hits).to.equal(4);
});
it('does not ignore marked code when predicate fails', async () => {
const Test = require('./coverage/ignore-predicated-fail');
Test.method();
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/ignore-predicated-fail') });
expect(Math.floor(cov.percent)).to.equal(75);
expect(cov.sloc).to.equal(4);
expect(cov.misses).to.equal(1);
expect(cov.hits).to.equal(3);
});
it('bypasses marked code when predicated', async () => {
const Test = require('./coverage/bypass-predicated');
Test.method();
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/bypass-predicated') });
expect(Math.floor(cov.percent)).to.equal(100);
expect(cov.sloc).to.equal(7);
expect(cov.misses).to.equal(0);
expect(cov.hits).to.equal(7);
});
it('bypasses marked code and reports misses correctly', async () => {
const Test = require('./coverage/bypass-misses');
Test.method(1);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/bypass-misses') });
expect(Math.floor(cov.percent)).to.equal(92);
expect(cov.sloc).to.equal(13);
expect(cov.misses).to.equal(1);
expect(cov.hits).to.equal(12);
});
it('uses a stack to bypass marked code', async () => {
const Test = require('./coverage/bypass-stack');
expect(Test.getIsSet()).to.be.a.function();
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/bypass-stack') });
expect(Math.floor(cov.percent)).to.equal(100);
expect(cov.sloc).to.equal(22);
expect(cov.misses).to.equal(0);
expect(cov.hits).to.equal(22);
});
it('uses a stack to bypass marked code and reports misses correctly', async () => {
const Test = require('./coverage/bypass-stack-alt');
expect(Test.getIsSet(Test.withTypes)).to.equal('isSet-shim');
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/bypass-stack') });
expect(Math.floor(cov.percent)).to.equal(100);
expect(cov.sloc).to.equal(40);
expect(cov.misses).to.equal(0);
expect(cov.hits).to.equal(40);
});
it('asserts that bypass marked code does not violate the stack bounds', async () => {
expect(() => require('./coverage/bypass-empty-stack')).to.throw(/stack/);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/bypass-empty-stack') });
expect(cov.sloc).to.equal(0);
});
it('ignores non-matching files', async () => {
require('./coverage/exclude/ignore');
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/exclude/ignore') });
expect(Math.floor(cov.percent)).to.equal(0);
expect(cov.files).to.have.length(0);
});
it('measures missing while statement coverage', async () => {
const Test = require('./coverage/while');
Test.method(false);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/while') });
expect(cov.percent).to.be.lessThan(100);
});
it('measures when errors are thrown', async () => {
const Test = require('./coverage/throws');
const fn = function () {
Test.method(true);
Test.method(false);
};
expect(fn).to.throw(Error);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/throws') });
expect(cov.percent).to.equal(100);
});
it('retains original value of conditional result', () => {
const Test = require('./coverage/conditional');
const value = { a: 1 };
expect(Test.method(value)).to.equal(value);
});
it('retains original value of conditional result with comma operator', () => {
const Test = require('./coverage/conditional2');
const value = 4711;
expect(Test.method(value)).to.equal(value);
});
it('should not change use strict instructions', () => {
const Test = require('./coverage/use-strict.js');
expect(Test.method.toString()).to.not.contain('13'); // This is the line of the inner use strict
const testFile = Path.join(__dirname, 'coverage/use-strict.js').replace(/\\/g, '/');
expect(Test.singleLine.toString()).to.contain('"use strict"; global.__$$labCov._line(\'' + testFile + '\',19);return value;');
expect(Test.shouldFail).to.throw('unknownvar is not defined');
});
it('should work with loop labels', async () => {
const Test = require('./coverage/loop-labels.js');
expect(Test.method()).to.equal([1, 0]);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/loop-labels') });
const source = cov.files[0].source;
const missedChunks = [];
Object.keys(source).forEach((lineNumber) => {
const line = source[lineNumber];
if (line.miss) {
// eslint-disable-next-line prefer-spread
missedChunks.push.apply(missedChunks, line.chunks.filter((chunk) => {
return !!chunk.miss;
}));
}
});
expect(missedChunks).to.have.length(1).and.to.equal([{ source: 'j < 1', miss: 'true', column: 22 }]);
});
it('should work with switch statements', async () => {
const Test = require('./coverage/switch.js');
expect(Test.method(1)).to.equal(1);
expect(Test.method()).to.equal(2);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/switch') });
const source = cov.files[0].source;
const missedChunks = [];
Object.keys(source).forEach((lineNumber) => {
const line = source[lineNumber];
if (line.miss) {
// eslint-disable-next-line prefer-spread
missedChunks.push.apply(missedChunks, line.chunks.filter((chunk) => {
return !!chunk.miss;
}));
}
});
expect(missedChunks).to.have.length(0);
});
it('should measure missing coverage on single-line functions correctly', async () => {
const Test = require('./coverage/single-line-functions');
const results = [];
for (let i = 1; i <= 10; ++i) {
results.push(Test[`method${i}`](3, 4));
}
results.push(Test.method11(5, 10));
results.push(Test.method11(0, 10));
results.push(Test.method11Partial(5, 10));
results.push(Test.method12());
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/single-line-functions') });
const source = cov.files[0].source;
const missedLines = Object.keys(source).filter((lineNumber) => source[lineNumber].miss);
expect(results).to.equal([7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 10, 5, 42]);
expect(missedLines).to.equal(['12', '15', '21', '27', '30', '33', '39', '46', '50', '53', '56', '59']);
});
it('should measure missing coverage on trailing function declarations correctly', async () => {
const Test = require('./coverage/trailing-function-declarations');
const result = Test.method(3, 4);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/trailing-function-declarations') });
const source = cov.files[0].source;
const missedLines = Object.keys(source).filter((lineNumber) => source[lineNumber].miss);
expect(result).to.equal(7);
expect(missedLines).to.equal(['19', '22']);
});
it('should measure coverage on conditional value', async () => {
const Test = require('./coverage/conditional-value');
expect(Test.method(false)).to.equal(false);
expect(Test.method(true, 1, 0)).to.equal(1);
expect(Test.method(true, 0, 1)).to.equal(1);
expect(Test.method(true, 0, 0)).to.equal(0);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/conditional-value') });
const source = cov.files[0].source;
const missedLines = Object.keys(source).filter((lineNumber) => source[lineNumber].miss);
expect(missedLines).to.be.empty();
});
it('should measure coverage on nullish coalescing operator', { skip: !supportsNullishCoalescing }, async () => {
const Test = require('./coverage/conditional-coalesce');
expect(Test.method(false)).to.equal(false);
expect(Test.method()).to.equal('nullish');
expect(Test.method(null)).to.equal('nullish');
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/conditional-coalesce') });
const source = cov.files[0].source;
const missedLines = Object.keys(source).filter((lineNumber) => source[lineNumber].miss);
expect(missedLines).to.be.empty();
});
it('should measure missing coverage on conditional value', async () => {
const Test = require('./coverage/conditional-value2');
expect(Test.method(false, false, false)).to.equal(false);
expect(Test.method(true, false, false)).to.equal(true);
expect(Test.method(false, true, false)).to.equal(true);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/conditional-value2') });
const source = cov.files[0].source;
const missedLines = Object.keys(source).filter((lineNumber) => source[lineNumber].miss);
expect(missedLines).to.equal(['7']);
});
it('should measure missing coverage on nullish coalescing operator', { skip: !supportsNullishCoalescing }, async () => {
const Test = require('./coverage/conditional-coalesce2');
expect(Test.method(1, null)).to.equal('1secondMissing');
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/conditional-coalesce2') });
const source = cov.files[0].source;
const missedLines = Object.keys(source).filter((lineNumber) => source[lineNumber].miss);
expect(missedLines).to.equal(['13', '14']);
});
describe('analyze()', () => {
it('sorts file paths in report', async () => {
const files = global.__$$labCov.files;
const paths = ['./a/b', './a/b/c', './a/c/b', './a/c', './a/b/c', './a/b/a'];
paths.forEach((path) => {
files[path] = { source: [] };
});
const cov = await Lab.coverage.analyze({ coveragePath: './a' });
const sorted = cov.files.map((file) => {
return file.filename;
});
expect(sorted).to.equal(['./a/b', './a/c', './a/b/a', './a/b/c', './a/c/b']);
});
});
describe('Clear require cache', () => {
it('does not reset file coverage', () => {
const cacheBackup = require.cache; // backup require cache
const filename = Path.resolve(__dirname, './coverage/basic.js');
let file = require('./coverage/basic');
const fileCovBefore = global.__$$labCov.files[filename];
require.cache = Module._cache = {}; // clear require cache before additional require
file = require('./coverage/basic'); //eslint-disable-line no-unused-vars
require.cache = Module._cache = cacheBackup; // restore require cache
const fileCovAfter = global.__$$labCov.files[filename];
expect(fileCovAfter).to.equal(fileCovBefore);
});
});
describe('coverage-all option', () => {
it('reports coverage for all matching files', async () => {
const Test = require('./coverage/coverage-all/covered');
expect(Test.method(true)).to.equal(true);
const cov = await Lab.coverage.analyze({
'coverage-all': true,
coveragePath: Path.join(__dirname, 'coverage/coverage-all'),
coveragePattern: /\.(js)$/
});
expect(cov.percent).to.equal(70);
expect(cov.files).to.have.length(2);
const filename = cov.files[1].filename;
expect(filename).to.equal('test/coverage/coverage-all/nested-folder/uncovered.js');
const source = cov.files[1].source;
const missedLines = Object.keys(source).filter((lineNumber) => source[lineNumber].miss);
expect(missedLines).to.equal(['8', '11', '13']);
});
it('reports coverage when the path is a single file', async () => {
const Test = require('./coverage/coverage-all/covered');
expect(Test.method(true)).to.equal(true);
const cov = await Lab.coverage.analyze({ 'coverage-all': true, coveragePath: Path.join(__dirname, 'coverage/coverage-all/covered.js') });
expect(cov.files).to.have.length(1);
expect(cov.percent).to.equal(100);
});
it('respects the coverage-flat option', async () => {
const Test = require('./coverage/coverage-all/covered');
expect(Test.method(true)).to.equal(true);
const cov = await Lab.coverage.analyze({
'coverage-all': true,
'coverage-flat': true,
coveragePath: Path.join(__dirname, 'coverage/coverage-all'),
coveragePattern: /\.(js)$/
});
expect(cov.files).to.have.length(1);
expect(cov.percent).to.equal(100);
});
});
});
describe('Coverage via Transform API', () => {
lab.before(async () => {
internals.js = require.extensions['.js'];
internals.inl = require.extensions['.inl'];
await Lab.coverage.instrument({ coveragePath: Path.join(__dirname, 'coverage'), coverageExclude: 'exclude', transform: internals.transform });
});
lab.after(() => {
require.extensions['.js'] = internals.js;
require.extensions['.inl'] = internals.inl;
});
it('identifies lines with partial coverage when having inline sourcemap', async () => {
const Test = require('./coverage/sourcemaps-transformed');
Test.method(false);
const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/sourcemaps-transformed'), sourcemaps: true });
const source = cov.files[0].source;
const missedLines = [];
const missedChunks = [];
Object.keys(source).forEach((lineNumber) => {
const line = source[lineNumber];
if (line.miss) {
missedLines.push({
filename: line.originalFilename,
lineNumber,
originalLineNumber: line.originalLine
});
if (line.chunks) {
line.chunks.forEach((chunk) => {
if (chunk.miss) {
missedChunks.push({
filename: chunk.originalFilename,
lineNumber,
originalLineNumber: chunk.originalLine,
originalColumn: chunk.originalColumn
});
}
});
}
}
});
expect(missedLines).to.include([
{ filename: 'while.js', lineNumber: '3', originalLineNumber: 11 }
]);
expect(missedChunks).to.include([
{ filename: 'while.js', lineNumber: '3', originalLineNumber: 13, originalColumn: 12 }
]);
});
});