• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vuepress / vuepress-next / 7184128480

12 Dec 2023 04:07PM CUT coverage: 69.405% (+0.2%) from 69.176%
7184128480

Pull #1314

github

web-flow
Merge e9e22663d into f7d6dde7d
Pull Request #1314: fix(client): avoid updating existing head tags, close #1268

332 of 464 branches covered (0.0%)

Branch coverage included in aggregate %.

13 of 14 new or added lines in 2 files covered. (92.86%)

648 of 948 relevant lines covered (68.35%)

48.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.94
/packages/shared/src/utils/resolveHeadIdentifier.ts
1
import type { HeadConfig } from '../types/index.js'
2

3
const TAGS_ALLOWED = ['link', 'meta', 'script', 'style', 'noscript', 'template']
45✔
4
const TAGS_UNIQUE = ['title', 'base']
45✔
5

6
/**
7
 * Resolve identifier of a tag, to avoid duplicated tags in `<head>`
8
 */
9
export const resolveHeadIdentifier = ([tag, attrs, content]: HeadConfig):
45✔
10
  | string
11
  | null => {
12
  // avoid duplicated unique tags
13
  if (TAGS_UNIQUE.includes(tag)) {
67✔
14
    return tag
12✔
15
  }
16

17
  // avoid disallowed tags
18
  if (!TAGS_ALLOWED.includes(tag)) {
55!
NEW
19
    return null
×
20
  }
21

22
  // avoid duplicated `<meta>` with same `name`
23
  if (tag === 'meta' && attrs.name) {
55✔
24
    return `${tag}.${attrs.name}`
9✔
25
  }
26

27
  // avoid duplicated `<template>` with same `id`
28
  if (tag === 'template' && attrs.id) {
46✔
29
    return `${tag}.${attrs.id}`
9✔
30
  }
31

32
  return JSON.stringify([
37✔
33
    tag,
34
    Object.entries(attrs)
35
      .map(([key, value]) => {
36
        // normalize boolean attributes
37
        if (typeof value === 'boolean') {
47✔
38
          return value ? [key, ''] : null
6✔
39
        }
40
        return [key, value]
41✔
41
      })
42
      .filter((item): item is [string, string] => item != null)
47✔
43
      .sort(([keyA], [keyB]) => keyA.localeCompare(keyB)),
14✔
44
    content,
45
  ])
46
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc