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

pmcelhaney / counterfact / 6908216888

17 Nov 2023 07:22PM UTC coverage: 82.435% (-0.2%) from 82.634%
6908216888

Pull #652

github

pmcelhaney
add a --prefix option for route prefix

fixes #636
Pull Request #652: add a --prefix option for route prefix

738 of 828 branches covered (0.0%)

Branch coverage included in aggregate %.

7 of 10 new or added lines in 2 files covered. (70.0%)

36 existing lines in 4 files now uncovered.

2397 of 2975 relevant lines covered (80.57%)

36.89 hits per line

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

55.65
/src/typescript-generator/repository.js
1
import fs from "node:fs/promises";
2✔
2
import nodePath, { dirname } from "node:path";
2✔
3
import { fileURLToPath } from "node:url";
2✔
4

2✔
5
import createDebug from "debug";
2✔
6

2✔
7
import { ensureDirectoryExists } from "../util/ensure-directory-exists.js";
2✔
8
import { Script } from "./script.js";
2✔
9

2✔
10
const debug = createDebug("counterfact:server:repository");
2✔
11

2✔
12
// eslint-disable-next-line no-underscore-dangle
2✔
13
const __dirname = dirname(fileURLToPath(import.meta.url)).replaceAll("\\", "/");
2✔
14

2✔
15
debug("dirname is %s", __dirname);
2✔
16

2✔
17
export class Repository {
2✔
18
  constructor() {
2✔
19
    this.scripts = new Map();
22✔
20
  }
22✔
21

2✔
22
  get(path) {
2✔
23
    debug("getting script at %s", path);
186✔
24

186✔
25
    if (this.scripts.has(path)) {
186✔
26
      debug("already have script %s, returning it", path);
76✔
27

76✔
28
      return this.scripts.get(path);
76✔
29
    }
76✔
30

110✔
31
    debug("don't have %s, creating it", path);
110✔
32

110✔
33
    const script = new Script(this, path);
110✔
34

110✔
35
    this.scripts.set(path, script);
110✔
36

110✔
37
    return script;
110✔
38
  }
110✔
39

2✔
40
  async finished() {
2✔
41
    while (
2✔
42
      Array.from(this.scripts.values()).some((script) => script.isInProgress())
2✔
43
    ) {
2✔
44
      debug("waiting for %i scripts to finish", this.scripts.size);
2✔
45
      // eslint-disable-next-line no-await-in-loop
2✔
46
      await Promise.all(
2✔
47
        Array.from(this.scripts.values(), (script) => script.finished()),
2✔
48
      );
2✔
49
    }
2✔
50
  }
2✔
51

2✔
52
  copyCoreFiles(destination) {
2✔
53
    const files = ["response-builder-factory.ts"];
×
54

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

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

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

2✔
69
  async writeFiles(destination) {
2✔
70
    debug(
×
71
      "waiting for %i or more scripts to finish before writing files",
×
72
      this.scripts.size,
×
73
    );
×
74
    await this.finished();
×
75
    debug("all %i scripts are finished", this.scripts.size);
×
76

×
77
    const writeFiles = Array.from(
×
78
      this.scripts.entries(),
×
79
      async ([path, script]) => {
×
80
        const contents = await script.contents();
×
81

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

×
84
        await ensureDirectoryExists(fullPath);
×
85

×
86
        if (
×
87
          path.startsWith("paths") &&
×
88
          (await fs
×
89
            .stat(fullPath)
×
90
            .then((stat) => stat.isFile())
×
91
            .catch(() => false))
×
92
        ) {
×
93
          process.stdout.write(`not overwriting ${fullPath}\n`);
×
94

×
95
          return;
×
96
        }
×
97

×
98
        debug("about to write", fullPath);
×
99
        await fs.writeFile(fullPath, contents);
×
100
        debug("did write", fullPath);
×
101

×
UNCOV
102
        process.stdout.write(`writing ${fullPath}\n`);
×
UNCOV
103
      },
×
UNCOV
104
    );
×
UNCOV
105

×
UNCOV
106
    await Promise.all(writeFiles);
×
UNCOV
107

×
UNCOV
108
    await this.copyCoreFiles(destination);
×
UNCOV
109
  }
×
110
}
2✔
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