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

pmcelhaney / counterfact / 5941942840

22 Aug 2023 05:13PM UTC coverage: 87.442% (+0.1%) from 87.318%
5941942840

Pull #377

github

pmcelhaney
is the promise really just not resolving?
Pull Request #377: run CI on Windows as well as Linux

432 of 460 branches covered (93.91%)

Branch coverage included in aggregate %.

214 of 214 new or added lines in 13 files covered. (100.0%)

2005 of 2327 relevant lines covered (86.16%)

21.13 hits per line

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

92.42
/src/util/read-file.js
1
/* eslint-disable no-magic-numbers */
1✔
2
import fs from "node:fs/promises";
1✔
3

1✔
4
import nodeFetch from "node-fetch";
1✔
5

1✔
6
function log(...strings) {
52✔
7
  process.stdout.write(`[read-file] ${strings.join("\t")}\n`);
52✔
8
}
52✔
9

1✔
10
// eslint-disable-next-line max-statements
1✔
11
export async function readFile(urlOrPath) {
1✔
12
  log("reading file or URL", urlOrPath);
12✔
13

12✔
14
  if (urlOrPath.startsWith("http")) {
12✔
15
    log("reading url", urlOrPath);
1✔
16

1✔
17
    const response = await nodeFetch(urlOrPath);
1✔
18

1✔
19
    return response.text();
1✔
20
  }
1✔
21

11✔
22
  if (urlOrPath.startsWith("file")) {
12✔
23
    log("reading file URl", urlOrPath);
1✔
24

1✔
25
    return fs.readFile(new URL(urlOrPath), "utf8");
1✔
26
  }
1✔
27

10✔
28
  log("reading plain old file", urlOrPath);
10✔
29

10✔
30
  // eslint-disable-next-line init-declarations
10✔
31
  let result;
10✔
32

10✔
33
  try {
12✔
34
    result = fs.readFile(urlOrPath, "utf8");
12✔
35

12✔
36
    log("did read plain old file", urlOrPath);
12✔
37
  } catch (error) {
12!
38
    log("error reading file", urlOrPath, error);
×
39

×
40
    return `ERROR: ${error}`;
×
41
  }
×
42

10✔
43
  log("waiting for result to resolve");
10✔
44

10✔
45
  // eslint-disable-next-line promise/avoid-new
10✔
46
  const timeout = new Promise((resolve) => {
10✔
47
    setTimeout(() => resolve("COULD NOT READ FILE IN A REASONABLE TIME"), 1000);
10✔
48
  });
10✔
49

10✔
50
  const text = await Promise.race([timeout, result]);
10✔
51

8✔
52
  log("returning result", text);
8✔
53

8✔
54
  return result;
8✔
55
}
8✔
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