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

pmcelhaney / counterfact / 5942883563

22 Aug 2023 06:52PM UTC coverage: 83.567% (-3.8%) from 87.388%
5942883563

Pull #517

github

web-flow
Merge branch 'main' into windows-support
Pull Request #517: disable the end-to-end test because it won't work on Windows

389 of 423 branches covered (91.96%)

Branch coverage included in aggregate %.

1818 of 2218 relevant lines covered (81.97%)

9.64 hits per line

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

36.45
/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();
8✔
25
  }
8✔
26

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

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

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

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

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