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

adobe / sizewatcher / 14182534597

31 Mar 2025 10:17PM UTC coverage: 57.73% (+0.6%) from 57.081%
14182534597

Pull #108

github

web-flow
Merge 06472c63c into cf160b76b
Pull Request #108: fix(git): git comparator reporting incorrect deltas

99 of 222 branches covered (44.59%)

Branch coverage included in aggregate %.

26 of 35 new or added lines in 4 files covered. (74.29%)

14 existing lines in 2 files now uncovered.

308 of 483 relevant lines covered (63.77%)

4.7 hits per line

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

10.81
/lib/comparators/custom.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
// comparators/custom.js - compares custom path
16

17
const debug = require("debug")("sizewatcher:custom");
1✔
18
const du = require("du");
1✔
19
const path = require("path");
1✔
20
const fs = require("fs");
1✔
21
const pb = require('pretty-bytes');
1✔
22
const { spawn } = require('child_process');
1✔
23
const glob = require("glob");
1✔
24

25
async function spawnProcess(command, args, options) {
26
    return new Promise((resolve, reject) => {
×
27
        const child = spawn(command, args, options);
×
28

29
        child.on("error", (err) => reject(err));
×
30
        child.on("exit", (code, signal) => {
×
31
            if (code !== 0) {
×
32
                let cmdString = command;
×
33
                if (args.length > 0) {
×
34
                    cmdString += ` ${args.join(" ")}`;
×
35
                }
36
                const err = new Error(`\`${cmdString}\` failed with exit code ${code}${signal ? `(received signal: ${signal})` : ""}`);
×
37
                err.exitCode = code;
×
38
                err.signal = signal;
×
39
                reject(err);
×
40
            }
41
            resolve();
×
42
        });
43
    });
44
}
45

46
async function runScript(script, path) {
47
    await spawnProcess(script, [], {
×
48
        shell: true,
49
        cwd: path,
50
        // log / pass-through all output
51
        stdio: "inherit"
52
    });
53
}
54

55
async function measure(baseDir, globPath, fileListing) {
56
    let total = 0;
×
57
    const files = glob.sync(path.join(baseDir, globPath));
×
58
    for (const file of files) {
×
59
        if (fs.existsSync(file)) {
×
NEW
60
            const fileSize = await du(file);
×
61
            total += fileSize;
×
62

63
            if (fileListing) {
×
64
                fileListing.push(`${pb(fileSize)} ${path.relative(baseDir, file)}`);
×
65
            }
66
        }
67
    }
68
    return total;
×
69
}
70

71
module.exports = {
1✔
72

73
    shouldRun: async function(beforeDir, afterDir) {
74
        if (!this.config.path || typeof this.config.path !== "string") {
×
75
            return false;
×
76
        }
77
        // if it has a script, we have to run (the script might create the files)
78
        if (typeof this.config.script === "string") {
×
79
            return true;
×
80
        }
81

82
        if (this.config.path.startsWith("/")) {
×
83
            console.error("Error: custom comparator path must be relative:", this.config.path);
×
84
            return false;
×
85
        }
86
        return glob.sync(path.join(beforeDir, this.config.path)).length > 0 ||
×
87
                glob.sync(path.join(afterDir, this.config.path)).length > 0;
88
    },
89

90
    compare: async function(before, after) {
91
        if (this.config.script) {
×
92
            debug(`running script in ${before.dir}: ${this.config.script}`);
×
93
            await runScript(this.config.script, before.dir);
×
94

95
            debug(`running script in ${after.dir}: ${this.config.script}`);
×
96
            await runScript(this.config.script, after.dir);
×
97
        }
98

99
        const fileListing = [];
×
100

101
        debug(`measuring ${this.config.path} in ${before.dir}...`);
×
102
        const beforeSize = await measure(before.dir, this.config.path);
×
103

104
        debug(`measuring ${this.config.path} in ${after.dir}...`);
×
105
        const afterSize = await measure(after.dir, this.config.path, fileListing);
×
106

107
        return {
×
108
            name: this.config.name || this.config.path,
×
109
            beforeSize,
110
            afterSize,
111
            detailsLabel: "New size",
112
            details: fileListing.join("\n")
113
        };
114
    }
115
};
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