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

pmcelhaney / counterfact / 6512307620

13 Oct 2023 07:26PM UTC coverage: 86.122% (-1.7%) from 87.815%
6512307620

Pull #606

github

pmcelhaney
don't run the migration script if there are not files to migrate
Pull Request #606: fix root context not shared

747 of 823 branches covered (0.0%)

Branch coverage included in aggregate %.

113 of 113 new or added lines in 6 files covered. (100.0%)

2455 of 2895 relevant lines covered (84.8%)

39.54 hits per line

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

0.0
/src/migrations/0.27.js
1
import {
×
2
  existsSync,
×
3
  readdirSync,
×
4
  readFileSync,
×
5
  statSync,
×
6
  writeFileSync,
×
7
} from "node:fs";
×
8
import { join } from "node:path";
×
9

×
10
function processFile(filePath) {
×
11
  const content = readFileSync(filePath, "utf8");
×
12

×
13
  if (
×
14
    content.includes("export type ContextType =") ||
×
15
    content.includes("export type { ContextType }")
×
16
  ) {
×
17
    return;
×
18
  }
×
19

×
20
  if (content.includes("export default new Context")) {
×
21
    writeFileSync(filePath, "export type ContextType = typeof Context;\n", {
×
22
      flag: "a",
×
23
    });
×
24
  } else {
×
25
    writeFileSync(
×
26
      filePath,
×
27
      'export type { ContextType } from "../$.context";\n',
×
28
    );
×
29
  }
×
30
}
×
31

×
32
function migrateContextFiles(path) {
×
33
  if (!existsSync(path)) {
×
34
    return;
×
35
  }
×
36

×
37
  const items = readdirSync(path);
×
38

×
39
  for (const item of items) {
×
40
    const itemPath = join(path, item);
×
41
    const stats = statSync(itemPath);
×
42

×
43
    if (stats.isDirectory()) {
×
44
      migrateContextFiles(itemPath);
×
45
    }
×
46

×
47
    if (stats.isFile() && item === "$.context.ts") {
×
48
      processFile(itemPath);
×
49
    }
×
50
  }
×
51
}
×
52

×
53
export function migrate(rootPath) {
×
54
  if (!existsSync(rootPath)) {
×
55
    return;
×
56
  }
×
57

×
58
  migrateContextFiles(join(rootPath, "paths"));
×
59
}
×
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