From 5a67ba08bd2f1ecca42febd57247129e4c75e9ee Mon Sep 17 00:00:00 2001 From: Anton Usmansky Date: Fri, 23 Sep 2022 10:08:09 +0300 Subject: [PATCH] chore: remove outdated coverage stuff --- .../browser/client-scripts/index.coverage.js | 108 ------------------ lib/core/browser/client-scripts/index.js | 6 - lib/core/client-bridge/index.js | 4 - test/lib/core/client-bridge/index.js | 15 --- 4 files changed, 133 deletions(-) delete mode 100644 lib/core/browser/client-scripts/index.coverage.js diff --git a/lib/core/browser/client-scripts/index.coverage.js b/lib/core/browser/client-scripts/index.coverage.js deleted file mode 100644 index f0b970326..000000000 --- a/lib/core/browser/client-scripts/index.coverage.js +++ /dev/null @@ -1,108 +0,0 @@ -'use strict'; - -var util = require('./util'), - coverageLevel = require('../../coverage/coverage-level'), - rect = require('./rect'), - lib = require('./lib'); - -exports.collectCoverage = function collectCoverage(rect) { - var coverage = {}, - sheets = document.styleSheets; - for (var i = 0; i < sheets.length; i++) { - var href = sheets[i].href, - rules = getRules(sheets[i]); - - if (rules.ignored) { - coverage[href] = rules; - continue; - } - var ctx = { - // media rule counter - // coverage for media rules is stored by its index within stylesheet - media: -1, - href: href, - coverage: coverage - }; - for (var r = 0; r < rules.length; r++) { - coverageForRule(rules[r], rect, ctx); - } - } - - return coverage; -}; - -function getRules(styleSheet) { - try { - return styleSheet.cssRules || styleSheet.rules; - } catch (e) { - if (e.name === 'SecurityError') { - return { - ignored: true, - message: 'Unable to read stylesheet rules due to the same origin policy' - }; - } - throw e; - } -} - -function coverageForRule(rule, area, ctx) { - if (rule.cssRules || rule.styleSheet) { - if (rule.conditionText) { - ctx.media++; - if (!lib.matchMedia(rule.conditionText).matches) { - return; - } - } - - var rules = rule.cssRules || rule.styleSheet.cssRules; - for (var r = 0; r < rules.length; r++) { - coverageForRule(rules[r], area, ctx); - } - - return; - } - - if (!rule.selectorText) { - return; - } - - util.each(rule.selectorText.split(','), function(selector) { - selector = lib.trim(selector); - var coverage = coverageLevel.NONE, - matches = lib.queryAll(selector); - - var re = /:{1,2}(?:after|before|first-letter|first-line|selection)(:{1,2}\w+)?$/; - // if selector contains pseudo-elements cut it off and try to find element without it - if (matches.length === 0 && re.test(selector)) { - var newSelector = lib.trim(selector.replace(re, '$1')); - - if (newSelector.length > 0) { - matches = lib.queryAll(newSelector); - } - } - - if (matches.length > 0) { - for (var match = 0; match < matches.length; match++) { - var newCoverage = coverageForElem(matches[match], area); - coverage = coverageLevel.merge(coverage, newCoverage); - } - } - - var byURL = ctx.coverage[ctx.href] = ctx.coverage[ctx.href] || {}; - if (rule.parentRule && rule.parentRule.conditionText) { - selector = '?' + ctx.media + ':' + selector; - } - - byURL[selector] = coverageLevel.merge(byURL[selector], coverage); - }); -} - -function coverageForElem(elem, captureRect) { - var elemRect = rect.getAbsoluteClientRect(elem); - if (captureRect.rectInside(elemRect)) { - return coverageLevel.FULL; - } else if (captureRect.rectIntersects(elemRect)) { - return coverageLevel.PARTIAL; - } - return coverageLevel.NONE; -} diff --git a/lib/core/browser/client-scripts/index.js b/lib/core/browser/client-scripts/index.js index aad162cc5..34a8975c4 100644 --- a/lib/core/browser/client-scripts/index.js +++ b/lib/core/browser/client-scripts/index.js @@ -70,7 +70,6 @@ function prepareScreenshotUnsafe(areas, opts) { viewportWidth = document.documentElement.clientWidth, documentHeight = document.documentElement.scrollHeight, documentWidth = document.documentElement.scrollWidth, - coverage, viewPort = new Rect({ left: util.getScrollLeft(scrollElem), top: util.getScrollTop(scrollElem), @@ -94,10 +93,6 @@ function prepareScreenshotUnsafe(areas, opts) { }; } - if (opts.coverage) { - coverage = require('./index.coverage').collectCoverage(rect); - } - return { captureArea: rect.serialize(), ignoreAreas: findIgnoreAreas(opts.ignoreSelectors, scrollElem), @@ -109,7 +104,6 @@ function prepareScreenshotUnsafe(areas, opts) { }, documentHeight: Math.round(documentHeight), documentWidth: Math.round(documentWidth), - coverage: coverage, canHaveCaret: isEditable(document.activeElement), pixelRatio: pixelRatio }; diff --git a/lib/core/client-bridge/index.js b/lib/core/client-bridge/index.js index 910a65c89..5a6f64499 100644 --- a/lib/core/client-bridge/index.js +++ b/lib/core/client-bridge/index.js @@ -13,10 +13,6 @@ exports.build = (browser, opts = {}) => { basedir: path.join(__dirname, '..', 'browser', 'client-scripts') }); - if (!opts.coverage) { - script.exclude('./index.coverage'); - } - script.transform({ sourcemap: false, global: true, diff --git a/test/lib/core/client-bridge/index.js b/test/lib/core/client-bridge/index.js index 583ab7c46..d6b578090 100644 --- a/test/lib/core/client-bridge/index.js +++ b/test/lib/core/client-bridge/index.js @@ -30,16 +30,6 @@ describe('clientBridge', () => { .then(() => assert.calledOnceWith(browserify, sinon.match({entries: './index', basedir: sinon.match(/browser\/client-scripts/)}))); }); - it('should exclude coverage client script if coverage is disabled', () => { - return clientBridge.build(null, {coverage: false}) - .then(() => assert.calledOnceWith(script.exclude, './index.coverage')); - }); - - it('should not exclude coverage client script if coverage is enabled', () => { - return clientBridge.build(null, {coverage: true}) - .then(() => assert.notCalled(script.exclude)); - }); - it('should transform client scripts', () => { return clientBridge.build() .then(() => { @@ -53,11 +43,6 @@ describe('clientBridge', () => { }); }); - it('should transform client scripts after excluding of a coverage client script', () => { - return clientBridge.build(null, {coverage: false}) - .then(() => assert.callOrder(script.exclude, script.transform)); - }); - it('should transform client scripts using native library', () => { return clientBridge.build(null, {calibration: {needsCompatLib: false}}) .then(() => {