Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/extract-symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const extractSymbol = (
): SVGSVGElement | null => {
const symbol = spriteSvg.querySelector('#' + CSS.escape(symbolId))

/* istanbul ignore else */
if (symbol?.tagName.toLowerCase() !== 'symbol') {
return null
}
Expand Down
13 changes: 0 additions & 13 deletions src/inject-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const injectElement = (
) => {
const elUrl = el.getAttribute('data-src') ?? el.getAttribute('src')

/* istanbul ignore else */
if (!elUrl) {
callback(new Error('Invalid data-src or src attribute'))
return
Expand All @@ -32,7 +31,6 @@ const injectElement = (
// avoid a race condition if multiple injections for the same element are run.
// :NOTE: Using indexOf() only _after_ we check for SVG support and bail, so
// no need for IE8 indexOf() polyfill.
/* istanbul ignore else */
if (injectedElements.indexOf(el) !== -1) {
// TODO: Extract.
injectedElements.splice(injectedElements.indexOf(el), 1)
Expand All @@ -56,7 +54,6 @@ const injectElement = (
const loadSvg = cacheRequests ? loadSvgCached : loadSvgUncached

loadSvg(baseUrl, httpRequestWithCredentials, (error, loadedSvg) => {
/* istanbul ignore else */
if (!loadedSvg) {
// TODO: Extract.
injectedElements.splice(injectedElements.indexOf(el), 1)
Expand All @@ -70,7 +67,6 @@ const injectElement = (
if (symbolId) {
const symbolSvg = extractSymbol(loadedSvg, symbolId)

/* istanbul ignore else */
if (!symbolSvg) {
injectedElements.splice(injectedElements.indexOf(el), 1)
;(el as ElementType) = null
Expand All @@ -82,25 +78,21 @@ const injectElement = (
}

const elId = el.getAttribute('id')
/* istanbul ignore else */
if (elId) {
svg.setAttribute('id', elId)
}

const elTitle = el.getAttribute('title')
/* istanbul ignore else */
if (elTitle) {
svg.setAttribute('title', elTitle)
}

const elWidth = el.getAttribute('width')
/* istanbul ignore else */
if (elWidth) {
svg.setAttribute('width', elWidth)
}

const elHeight = el.getAttribute('height')
/* istanbul ignore else */
if (elHeight) {
svg.setAttribute('height', elHeight)
}
Expand All @@ -117,7 +109,6 @@ const injectElement = (
svg.setAttribute('class', mergedClasses)

const elStyle = el.getAttribute('style')
/* istanbul ignore else */
if (elStyle) {
svg.setAttribute('style', elStyle)
}
Expand All @@ -136,7 +127,6 @@ const injectElement = (
}
})

/* istanbul ignore else */
if (renumerateIRIElements) {
// Make sure any internally referenced clipPath ids and their clip-path
// references are unique.
Expand Down Expand Up @@ -251,7 +241,6 @@ const injectElement = (
for (let c = 0, allLinksLen = allLinks.length; c < allLinksLen; c++) {
const link = allLinks[c]!
const href = link.getAttribute('href')
/* istanbul ignore else */
if (href) {
const nextHref = replaceHrefReference(href, iriIdMap)
if (nextHref !== href) {
Expand All @@ -260,7 +249,6 @@ const injectElement = (
}

const xlinkHref = link.getAttributeNS(xlinkNamespace, 'href')
/* istanbul ignore else */
if (xlinkHref) {
const nextXlinkHref = replaceHrefReference(xlinkHref, iriIdMap)
if (nextXlinkHref !== xlinkHref) {
Expand Down Expand Up @@ -353,7 +341,6 @@ const injectElement = (
}

// Run/Eval the scripts if needed.
/* istanbul ignore else */
if (
scriptsToEval.length > 0 &&
(evalScripts === 'always' ||
Expand Down
1 change: 0 additions & 1 deletion src/load-svg-cached.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const loadSvgCached = (
queueRequest(url, callback)

makeAjaxRequest(url, httpRequestWithCredentials, (error, httpRequest) => {
/* istanbul ignore else */
if (error) {
cache.set(url, error)
} else if (
Expand Down
1 change: 0 additions & 1 deletion src/load-svg-uncached.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const loadSvgUncached = (
callback: Errback,
) => {
makeAjaxRequest(url, httpRequestWithCredentials, (error, httpRequest) => {
/* istanbul ignore else */
if (error) {
callback(error)
} else if (
Expand Down
10 changes: 1 addition & 9 deletions src/request-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import cache from './cache'
import cloneSvg from './clone-svg'
import type { Errback } from './types'

let requestQueue: Record<string, Errback[]> = {}

export const clear = () => {
requestQueue = {}
}
const requestQueue: Record<string, Errback[]> = {}

export const queueRequest = (url: string, callback: Errback) => {
requestQueue[url] ??= []
Expand All @@ -22,7 +18,6 @@ export const processRequestQueue = (url: string) => {
for (let i = 0, len = callbacks.length; i < len; i++) {
// Make these calls async so we avoid blocking the page/renderer.
setTimeout(() => {
/* istanbul ignore else */
if (Array.isArray(requestQueue[url])) {
const cacheValue = cache.get(url)
const callback = callbacks[i]
Expand All @@ -32,17 +27,14 @@ export const processRequestQueue = (url: string) => {
return
}

/* istanbul ignore else */
if (cacheValue instanceof SVGSVGElement) {
callback(null, cloneSvg(cacheValue))
}

/* istanbul ignore else */
if (cacheValue instanceof Error) {
callback(cacheValue)
}

/* istanbul ignore else */
if (i === callbacks.length - 1) {
delete requestQueue[url]
}
Expand Down
3 changes: 1 addition & 2 deletions test/eval-scripts.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect, test } from '@playwright/test'
import type { Page } from '@playwright/test'
import { expect, test } from './playwright/coverage'
import { formatHtml, injectSvg, setupPage } from './playwright/test-utils'
import './playwright/coverage'

const injectHtml = `
<div
Expand Down
3 changes: 1 addition & 2 deletions test/local.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { expect, test } from '@playwright/test'
import * as path from 'path'
import { pathToFileURL } from 'url'
import { expect, test } from './playwright/coverage'
import { addSvgInjector, formatHtml, injectSvg } from './playwright/test-utils'
import './playwright/coverage'

const fixturesDir = path.resolve(__dirname, 'fixtures')
const thumbUpPath =
Expand Down
3 changes: 1 addition & 2 deletions test/no-extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, test } from '@playwright/test'
import { expect, test } from './playwright/coverage'
import { formatHtml, injectSvg, setupPage } from './playwright/test-utils'
import './playwright/coverage'

test.describe('no extension', () => {
test('missing content type', async ({ page, browserName }) => {
Expand Down
59 changes: 34 additions & 25 deletions test/playwright/coverage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from '@playwright/test'
import { test as base, expect } from '@playwright/test'
import * as fs from 'fs/promises'
import * as path from 'path'

Expand All @@ -12,28 +12,37 @@ const sanitize = (value: string) => {
return value.replace(/[^a-zA-Z0-9_-]+/g, '_')
}

test.afterEach(async ({ page }, testInfo) => {
if (process.env.COVERAGE !== '1') {
return
}

try {
const coverage = await page.evaluate(
() => (window as unknown as CoverageWindow).__coverage__ ?? null,
)

if (!coverage) {
return
}

await fs.mkdir(coverageDir, { recursive: true })

const title = sanitize(testInfo.titlePath.join('-'))
const fileName = `${testInfo.project.name}-${title}.json`
const filePath = path.join(coverageDir, fileName)

await fs.writeFile(filePath, JSON.stringify(coverage), 'utf8')
} catch {
// Ignore coverage collection failures to avoid masking test results.
}
const test = base.extend<{ _collectCoverage: void }>({
_collectCoverage: [
async ({ page }, use, testInfo) => {
await use()

if (process.env.COVERAGE !== '1') {
return
}

try {
const coverage = await page.evaluate(
() => (window as unknown as CoverageWindow).__coverage__ ?? null,
)

if (!coverage) {
return
}

await fs.mkdir(coverageDir, { recursive: true })

const title = sanitize(testInfo.titlePath.join('-'))
const fileName = `${testInfo.project.name}-${title}.json`
const filePath = path.join(coverageDir, fileName)

await fs.writeFile(filePath, JSON.stringify(coverage), 'utf8')
} catch {
// Ignore coverage collection failures to avoid masking test results.
}
},
{ auto: true },
],
})

export { expect, test }
3 changes: 1 addition & 2 deletions test/renumerate-iri-elements.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, test } from '@playwright/test'
import { expect, test } from './playwright/coverage'
import { formatHtml, injectSvg, setupPage } from './playwright/test-utils'
import './playwright/coverage'

test.describe('renumerate iri elements', () => {
test('renumerateIRIElements: false', async ({ page }) => {
Expand Down
3 changes: 1 addition & 2 deletions test/sprite.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, test } from '@playwright/test'
import { expect, test } from './playwright/coverage'
import { formatHtml, injectSvg, setupPage } from './playwright/test-utils'
import './playwright/coverage'

const thumbUpPath =
'M4.47 0c-.19.02-.37.15-.47.34-.13.26-1.09 2.19-1.28 2.38-.19.19-.44.28-.72.28v4h3.5c.21 0 .39-.13.47-.31 0 0 1.03-2.91 1.03-3.19 0-.28-.22-.5-.5-.5h-1.5c-.28 0-.5-.25-.5-.5s.39-1.58.47-1.84c.08-.26-.05-.54-.31-.63-.07-.02-.12-.04-.19-.03zm-4.47 3v4h1v-4h-1z'
Expand Down
3 changes: 1 addition & 2 deletions test/svg-injector.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { expect, test } from '@playwright/test'
import { expect, test } from './playwright/coverage'
import {
formatHtml,
injectSvg,
setupPage,
type SvgInjectorWindow,
} from './playwright/test-utils'
import './playwright/coverage'

const thumbUpPath =
'M4.47 0c-.19.02-.37.15-.47.34-.13.26-1.09 2.19-1.28 2.38-.19.19-.44.28-.72.28v4h3.5c.21 0 .39-.13.47-.31 0 0 1.03-2.91 1.03-3.19 0-.28-.22-.5-.5-.5h-1.5c-.28 0-.5-.25-.5-.5s.39-1.58.47-1.84c.08-.26-.05-.54-.31-.63-.07-.02-.12-.04-.19-.03zm-4.47 3v4h1v-4h-1z'
Expand Down
3 changes: 1 addition & 2 deletions test/unique-id.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, test } from '@playwright/test'
import { expect, test } from './playwright/coverage'
import uniqueId from '../src/unique-id'
import './playwright/coverage'

test('unique id generates unique ids', () => {
expect(uniqueId()).toBe(1)
Expand Down