UNPKG

751 BJavaScriptView Raw
1/* global __dirname */
2
3import { readFileSync } from 'fs';
4import path from 'path';
5import template from 'babel-template';
6import astify from 'babel-literal-to-ast';
7import meta from './meta';
8
9const render = template(readFileSync(
10 path.join(__dirname, '..', 'share', 'prelude.js'), 'utf8'
11));
12
13export 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}