UNPKG

jest-puppeteer-istanbul

Version:

Collect code coverage information from end-to-end jest puppeteer tests.

35 lines (34 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = require("path"); const fs_1 = require("fs"); class CoverageStorage { constructor(coverageDir = "coverage") { this.coverageDirPath = coverageDir; this.coverageJsonPath = path_1.join(this.coverageDirPath, "coverage-puppeteer-istanbul.json"); } read() { if (fs_1.existsSync(this.coverageJsonPath)) { try { return JSON.parse(fs_1.readFileSync(this.coverageJsonPath, "utf-8")); } catch (error) { return {}; } } return {}; } write(coverage) { // Node v8 has not `recursive` option. So make sure that `coverageDirPath` doesn't exist before `mkdirSync`. if (!fs_1.existsSync(this.coverageDirPath)) { fs_1.mkdirSync(this.coverageDirPath, { recursive: true }); } fs_1.writeFileSync(this.coverageJsonPath, JSON.stringify(coverage.data), "utf-8"); } delete() { if (fs_1.existsSync(this.coverageJsonPath)) { fs_1.unlinkSync(this.coverageJsonPath); } } } exports.CoverageStorage = CoverageStorage;