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

adobe / sizewatcher / 14209779941

02 Apr 2025 01:52AM UTC coverage: 57.528% (+0.4%) from 57.081%
14209779941

Pull #110

github

web-flow
Merge aea3c37e4 into cf160b76b
Pull Request #110: fix: revise checkout logic

105 of 229 branches covered (45.85%)

Branch coverage included in aggregate %.

31 of 32 new or added lines in 3 files covered. (96.88%)

1 existing line in 1 file now uncovered.

300 of 475 relevant lines covered (63.16%)

4.14 hits per line

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

29.58
/lib/render.js
1
/*
2
 * Copyright 2020 Adobe. All rights reserved.
3
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
 * you may not use this file except in compliance with the License. You may obtain a copy
5
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
 *
7
 * Unless required by applicable law or agreed to in writing, software distributed under
8
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
 * OF ANY KIND, either express or implied. See the License for the specific language
10
 * governing permissions and limitations under the License.
11
 */
12

13
'use strict';
14

15
// render.js - formats comparison result text
16

17
const config = require("./config");
1✔
18
const pb = require('pretty-bytes');
1✔
19

20
const ICONS = {
1✔
21
    cheers: "🎉",
22
    ok: "✅",
23
    warn: "⚠️",
24
    fail: "❌",
25
    error: "🚨"
26
};
27

28
const SUMMARY = {
1✔
29
    cheers: "congratulates on the size improvement 📉:",
30
    ok: "found no problematic size increases.",
31
    warn: "detected a size increase 📈:",
32
    fail: "detected a problematic size increase 📈:",
33
    error: "had a measurement error:"
34
};
35

36
const EXPANDED_CASES = ["cheers", "warn", "fail", "error"];
1✔
37

38
function indentEachLine(string, indent="  ") {
4✔
39
    return string.replace(/^(?!\s*$)/gm, indent);
4✔
40
}
41

42
function renderAsText(deltas) {
43
    let text = `Sizewatcher measured the following changes:\n\n`;
6✔
44

45
    text += `  '${deltas.before.branch}' (sha ${deltas.before.sha}) => '${deltas.after.branch}' (sha ${deltas.after.sha})\n\n`;
6✔
46

47
    for (const d of deltas) {
6✔
48
        if (d.error) {
10!
49
            text += `+ ${ICONS.error} ${d.name}: measurement error: ${d.error.message || d.error}\n`;
×
50
        } else {
51
            text += `+ ${ICONS[d.result]}  ${d.name}: ${d.increase}% (${pb(d.beforeSize)} => ${pb(d.afterSize)})\n\n`;
10✔
52

53
            if (d.details) {
10✔
54
                text += `  ${d.detailsLabel}:\n\n`;
4✔
55
                text += indentEachLine(d.details.trim()) + "\n";
4✔
56
            }
57
        }
58
        text += `\n`;
10✔
59
    }
60

61
    return text;
6✔
62
}
63

64
function renderAsMarkdown(deltas) {
65
    const summaryState = deltas.summary || "ok";
×
66
    const detailState = EXPANDED_CASES.includes(summaryState) ? "open" : "";
×
67

68
    let markdown = `<details ${detailState}><summary>${ICONS[summaryState]} <a href="https://github.com/adobe/sizewatcher">Sizewatcher</a> ${SUMMARY[summaryState]}</summary>\n`;
×
69
    markdown += `<p><blockquote>\n\n`;
×
70

71
    for (const d of deltas) {
×
72
        let change;
73

74
        if (d.error) {
×
75
            d.result = "error";
×
76
            change = `measurement error: ${d.error.message || d.error}`;
×
77

78
        } else if (d.increase >= 0.1) {
×
79
            change = `<b>+${d.increase}%</b> (${pb(d.beforeSize)} => ${pb(d.afterSize)})`;
×
80

81
        } else if (d.increase <= -0.1) {
×
82
            change = `<b>${d.increase}%</b> (${pb(d.beforeSize)} => ${pb(d.afterSize)})`;
×
83

84
        } else {
85
            change = `has no changes (${pb(d.afterSize)})`;
×
86

87
        }
88

89
        if (d.details) {
×
90
            markdown += `<details><summary>`;
×
91
        } else {
92
            markdown += "&nbsp;&nbsp;&nbsp;";
×
93
        }
94
        markdown += `${ICONS[d.result]} <code>${d.name}</code> ${change}`;
×
95
        if (d.details) {
×
96
            markdown += `</summary><br>${d.detailsLabel}:<pre>${d.details.trim().replace(/\n/g, "<br>")}</pre></details>`;
×
97
        }
98

99
        markdown += `\n\n`;
×
100
    }
101

102
    markdown += `<details><summary>Notes</summary><br>\n\n`;
×
103
    markdown += `- PR branch: \`${deltas.after.branch}\` @ ${deltas.after.sha}\n`;
×
NEW
104
    markdown += `- Base branch: \`${deltas.before.branch}\` @ ${deltas.before.sha}\n`;
×
105
    markdown += `- Sizewatcher v${require('../package.json').version}\n`;
×
106
    markdown += `- Effective Configuration:\n`;
×
107
    markdown += `\n\`\`\`yaml\n${config.asYaml()}\`\`\`\n`;
×
108
    markdown += `</details>\n\n`;
×
109

110
    markdown += `</blockquote></p>\n`;
×
111
    markdown += `</details>\n`;
×
112

113
    return markdown;
×
114
}
115

116
module.exports = {
1✔
117
    asText: renderAsText,
118
    asMarkdown: renderAsMarkdown
119
};
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

© 2026 Coveralls, Inc