1 |
|
2 |
|
3 | import { readFileSync } from 'fs';
|
4 | import path from 'path';
|
5 | import template from 'babel-template';
|
6 | import astify from 'babel-literal-to-ast';
|
7 | import meta from './meta';
|
8 |
|
9 | const render = template(readFileSync(
|
10 | path.join(__dirname, '..', 'share', 'prelude.js'), 'utf8'
|
11 | ));
|
12 |
|
13 | export default function prelude(state) {
|
14 | const coverage = meta(state);
|
15 | const name = state.file.opts.filenameRelative;
|
16 | const global = (state.opts && state.opts.global) || '__coverage__';
|
17 | return render({
|
18 | GLOBAL: astify(global),
|
19 | HASH: astify(coverage.hash),
|
20 | TAGS: astify(coverage.tags),
|
21 | VARIABLE: coverage.variable,
|
22 | FILE: astify(name),
|
23 | LOCATIONS: astify(coverage.entries),
|
24 | COUNT: astify(coverage.entries.length),
|
25 | });
|
26 | }
|