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

pmcelhaney / counterfact / 5941942840

22 Aug 2023 05:13PM CUT 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

46.36
/src/typescript-generator/repository.js
1
import nodePath from "node:path";
1✔
2
import fs from "node:fs/promises";
1✔
3
import { constants as fsConstants } from "node:fs";
1✔
4

1✔
5
import prettier from "prettier";
1✔
6

1✔
7
import { Script } from "./script.js";
1✔
8

1✔
9
// eslint-disable-next-line no-underscore-dangle
1✔
10
const __dirname = nodePath.dirname(new URL(import.meta.url).pathname);
1✔
11

1✔
12
async function ensureDirectoryExists(filePath) {
×
13
  const directory = nodePath.dirname(filePath);
×
14

×
15
  try {
×
16
    await fs.access(directory, fsConstants.W_OK);
×
17
  } catch {
×
18
    await fs.mkdir(directory, { recursive: true });
×
19
  }
×
20
}
×
21

1✔
22
export class Repository {
1✔
23
  constructor() {
1✔
24
    this.scripts = new Map();
9✔
25
  }
9✔
26

1✔
27
  get(path) {
1✔
28
    if (this.scripts.has(path)) {
92✔
29
      return this.scripts.get(path);
40✔
30
    }
40✔
31

52✔
32
    const script = new Script(this, path);
52✔
33

52✔
34
    this.scripts.set(path, script);
52✔
35

52✔
36
    return script;
52✔
37
  }
52✔
38

1✔
39
  async finished() {
1✔
40
    while (
1✔
41
      Array.from(this.scripts.values()).some((script) => script.isInProgress())
1✔
42
    ) {
1✔
43
      // eslint-disable-next-line no-await-in-loop
1✔
44
      await Promise.all(
1✔
45
        Array.from(this.scripts.values(), (script) => script.finished())
1✔
46
      );
1✔
47
    }
1✔
48
  }
1✔
49

1✔
50
  copyCoreFiles(destination) {
1✔
51
    const files = ["package.json", "response-builder-factory.ts"];
×
52

×
53
    return files.map((file) => {
×
54
      const path = nodePath.join(destination, file).replaceAll("\\", "/");
×
55

×
56
      process.stdout.write(`writing ${path}\n`);
×
57

×
58
      return fs.copyFile(
×
59
        nodePath
×
60
          .join(__dirname, `../../templates/${file}`)
×
61
          .replaceAll("\\", "/"),
×
62
        path
×
63
      );
×
64
    });
×
65
  }
×
66

1✔
67
  async writeFiles(destination) {
1✔
68
    await this.finished();
×
69

×
70
    const writeFiles = Array.from(
×
71
      this.scripts.entries(),
×
72
      async ([path, script]) => {
×
73
        const contents = prettier.format(script.contents(), {
×
74
          parser: "typescript",
×
75
        });
×
76

×
77
        const fullPath = nodePath.join(destination, path).replaceAll("\\", "/");
×
78

×
79
        await ensureDirectoryExists(fullPath);
×
80

×
81
        if (
×
82
          path.startsWith("paths") &&
×
83
          (await fs
×
84
            .stat(fullPath)
×
85
            .then((stat) => stat.isFile())
×
86
            .catch(() => false))
×
87
        ) {
×
88
          process.stdout.write(`not overwriting ${fullPath}\n`);
×
89

×
90
          return;
×
91
        }
×
92

×
93
        await fs.writeFile(fullPath, contents);
×
94

×
95
        process.stdout.write(`writing ${fullPath}\n`);
×
96
      }
×
97
    );
×
98

×
99
    await Promise.all(writeFiles);
×
100

×
101
    await this.copyCoreFiles(destination);
×
102
  }
×
103
}
1✔
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