UNPKG

1.82 kBJavaScriptView Raw
1'use strict';
2
3window.ClientCoverage = {
4 LocalStorageWrapper: {
5 getLocalStorage: function getLocalStorage(property, defaultVal) {
6 if (localStorage.hasOwnProperty(property)) {
7 Object.assign(defaultVal, JSON.parse(localStorage.getItem(property)));
8 localStorage.setItem(property, JSON.stringify(defaultVal));return defaultVal;
9 }
10 localStorage.setItem(property, JSON.stringify(defaultVal));return defaultVal || {};
11 },
12 clearLocalStorage: function clearLocalStorage(property) {
13 localStorage.removeItem(property);
14 }
15 }, JS: {
16 jsMethodInstrumentObject: {}, jsStorageKey: 'jsClientCoverageObject', init: function init() {
17 this.jsMethodInstrumentObject = ClientCoverage.LocalStorageWrapper.getLocalStorage(this.jsStorageKey, this.jsMethodInstrumentObject);
18 },
19 visitMethod: function visitMethod(jsFileName, jsMethodName) {
20 this.init();if (this.jsMethodInstrumentObject.hasOwnProperty(jsFileName)) {
21 if (!this.jsMethodInstrumentObject[jsFileName].includes(jsMethodName)) {
22 this.jsMethodInstrumentObject[jsFileName].push(jsMethodName);
23 }
24 } else {
25 this.jsMethodInstrumentObject[jsFileName] = [];this.jsMethodInstrumentObject[jsFileName].push(jsMethodName);
26 }
27 localStorage.setItem(this.jsStorageKey, JSON.stringify(this.jsMethodInstrumentObject));
28 },
29 clear: function clear() {
30 this.jsMethodInstrumentObject = {};ClientCoverage.LocalStorageWrapper.clearLocalStorage(this.jsStorageKey);
31 },
32 getData: function getData() {
33 return { methods: this.jsMethodInstrumentObject };
34 }
35 }, getCoverageData: function getCoverageData() {
36 return { JS: this.JS.getData() };
37 },
38 clear: function clear() {
39 this.JS.clear();
40 },
41 init: function init() {
42 this.JS.init();
43 }
44};
\No newline at end of file