Skip to content

Commit f89d491

Browse files
test(client): ignore lines from test coverage
1 parent a303c82 commit f89d491

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ jobs:
2121
run: npm ci --prefer-offline
2222

2323
- name: Run server test
24-
run: npm run test:server
24+
run: npm run test:coverage
2525

2626
- name: Generate coverage report
27-
run: |
28-
mkdir -p coverage
29-
npx nyc report --reporter=text-lcov > coverage/lcov.info
27+
run: npx nyc report --reporter=text-lcov > coverage/lcov.info
3028

3129
- name: Upload coverage reports to Codecov
3230
uses: codecov/codecov-action@v5

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"test:client": "npm run test:client:watch -- --single-run",
5050
"test:client:build": "NODE_ENV=test npm run build",
5151
"test:client:watch": "npm run test:client:build && karma start",
52+
"test:coverage": "npm run test:server && nyc report --reporter=html",
5253
"test:esm": "npm run build && node --test test/esm",
5354
"test:server": "npm run build:cjs && nyc mocha"
5455
},

src/client/domparser.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ if (typeof DOMParser === 'function') {
4646
* @returns - Document.
4747
*/
4848
parseFromString = (html: string, tagName?: string): Document => {
49+
/* istanbul ignore if */
4950
if (tagName) {
50-
/* istanbul ignore next */
5151
html = `<${tagName}>${html}</${tagName}>`;
5252
}
5353

@@ -74,6 +74,7 @@ if (typeof document === 'object' && document.implementation) {
7474
* @returns - Document
7575
*/
7676
parseFromDocument = function (html: string, tagName?: string): Document {
77+
/* istanbul ignore if */
7778
if (tagName) {
7879
const element = htmlDocument.documentElement.querySelector(tagName);
7980

@@ -113,6 +114,7 @@ if (template && template.content) {
113114
};
114115
}
115116

117+
/* istanbul ignore next */
116118
const createNodeList = () => document.createDocumentFragment().childNodes;
117119

118120
/**
@@ -136,11 +138,13 @@ export default function domparser(html: string): NodeList {
136138
// so make sure to remove them if they don't actually exist
137139
if (!HEAD_TAG_REGEX.test(html)) {
138140
const element = doc.querySelector(HEAD);
141+
/* istanbul ignore next */
139142
element?.parentNode?.removeChild(element);
140143
}
141144

142145
if (!BODY_TAG_REGEX.test(html)) {
143146
const element = doc.querySelector(BODY);
147+
/* istanbul ignore next */
144148
element?.parentNode?.removeChild(element);
145149
}
146150

@@ -153,6 +157,7 @@ export default function domparser(html: string): NodeList {
153157

154158
// if there's a sibling element, then return both elements
155159
if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
160+
/* istanbul ignore next */
156161
return elements[0].parentNode?.childNodes ?? createNodeList();
157162
}
158163

@@ -166,7 +171,10 @@ export default function domparser(html: string): NodeList {
166171
return parseFromTemplate(html);
167172
}
168173

174+
/* istanbul ignore next */
169175
const element = parseFromDocument(html, BODY).querySelector(BODY);
176+
177+
/* istanbul ignore next */
170178
return element?.childNodes ?? createNodeList();
171179
}
172180
}

src/client/utilities.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ export function formatDOM(
121121
}
122122

123123
case 3:
124+
/* istanbul ignore next */
124125
current = new Text(revertEscapedCharacters(node.nodeValue ?? ''));
125126
break;
126127

127128
case 8:
129+
/* istanbul ignore next */
128130
current = new Comment(node.nodeValue ?? '');
129131
break;
130132

0 commit comments

Comments
 (0)