-
Notifications
You must be signed in to change notification settings - Fork 29.9k
/
istanbul-lib-instrument-tests.ts
73 lines (62 loc) · 1.71 KB
/
istanbul-lib-instrument-tests.ts
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
import {
createInstrumenter,
readInitialCoverage,
programVisitor
} from 'istanbul-lib-instrument';
import * as babelTypes from 'babel-types';
import { RawSourceMap } from 'source-map';
const code = 'foo';
const filename = 'bar.txt';
createInstrumenter();
createInstrumenter({});
createInstrumenter({
coverageVariable: 'coverage'
});
const instrumenter = createInstrumenter({
preserveComments: true,
compact: false,
esModules: true,
autoWrap: false,
produceSourceMap: true,
sourceMapUrlCallback: (filename: string, url: string) => {},
debug: false
});
const sourceMap: RawSourceMap = {
version: 1 as any as string, // Fixed by https://github.com/mozilla/source-map/pull/293 but the fix is not yet published
sources: ['foo', 'bar'],
names: ['foo', 'bar'],
mappings: 'foo',
file: 'foo'
};
instrumenter.instrumentSync(code, filename);
const newCode = instrumenter.instrumentSync(code, filename, sourceMap);
code.trim();
// instrument with all args
instrumenter.instrument(code, filename, (error, code) => {
if (error) {
error.stack;
} else {
code.trim();
}
}, sourceMap);
// instrument without a filename
instrumenter.instrument(code, (error, code) => {
if (error) {
error.stack;
} else {
code.trim();
}
});
const cov = instrumenter.lastFileCoverage();
Object.create(cov);
const map = instrumenter.lastSourceMap();
Object.create(map);
const initialCov = readInitialCoverage(code);
initialCov.gcv;
programVisitor(babelTypes);
programVisitor(babelTypes, filename);
programVisitor(babelTypes, filename, { coverageVariable: 'coverage' });
const visitor = programVisitor(babelTypes, filename, { inputSourceMap: sourceMap });
visitor.enter(filename);
const data = visitor.exit(filename);
Object.create(data.fileCoverage);