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

vuepress / vuepress-next / 6927681358

20 Nov 2023 08:56AM UTC coverage: 69.266% (+0.2%) from 69.092%
6927681358

Pull #1314

github

web-flow
Merge 3491a4bc3 into 009501d4b
Pull Request #1314: fix(client): avoid updating existing head tags, close #1268

348 of 492 branches covered (0.0%)

Branch coverage included in aggregate %.

10 of 11 new or added lines in 2 files covered. (90.91%)

1 existing line in 1 file now uncovered.

700 of 1021 relevant lines covered (68.56%)

47.63 hits per line

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

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

3
const onlyTags = ['title', 'base']
49✔
4
const allowedTags = ['link', 'meta', 'script', 'style', 'noscript', 'template']
49✔
5

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

17
  // there should be only one `<title>` or `<base>`
18
  if (onlyTags.includes(tag)) {
58✔
19
    return tag
12✔
20
  }
21

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

27
  if (allowedTags.includes(tag)) {
37!
28
    return JSON.stringify([
37✔
29
      tag,
30
      Object.fromEntries(
31
        Object.entries(attrs)
32
          // handle boolean attributes
33
          .map(([key, value]) =>
34
            typeof value === 'boolean'
47✔
35
              ? value
6✔
36
                ? [key, '']
37
                : null
38
              : [key, value]
39
          )
40
          .filter((item): item is [string, string] => item != null)
47✔
41
          // sort keys
42
          .sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
14✔
43
      ),
44
      content,
45
    ])
46
  }
47

48
  // tags are not allowed
NEW
UNCOV
49
  return null
×
50
}
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