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

pmcelhaney / counterfact / 9716080407

28 Jun 2024 04:41PM UTC coverage: 87.469% (+0.2%) from 87.296%
9716080407

Pull #964

github

pmcelhaney
ability at runtime for a context object to access other context objects
Pull Request #964: ability at runtime for a context object to access other context objects

994 of 1103 branches covered (90.12%)

Branch coverage included in aggregate %.

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

2 existing lines in 1 file now uncovered.

3250 of 3749 relevant lines covered (86.69%)

44.97 hits per line

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

96.12
/src/server/context-registry.ts
1
// eslint-disable-next-line max-classes-per-file
2✔
2
export class Context {
2✔
3
  // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-empty-function
2✔
4
  public constructor() {}
2✔
5

2✔
6
  [key: string]: unknown;
2✔
7
}
2✔
8

2✔
9
export function parentPath(path: string): string {
2✔
10
  return String(path.split("/").slice(0, -1).join("/")) || "/";
92✔
11
}
92✔
12

2✔
13
export class ContextRegistry {
2✔
14
  private readonly entries = new Map<string, Context>();
124✔
15

124✔
16
  private readonly cache = new Map<string, Context>();
124✔
17

124✔
18
  private readonly seen = new Set<string>();
124✔
19

124✔
20
  public constructor() {
124✔
21
    this.add("/", {});
124✔
22
  }
124✔
23

124✔
24
  private getContextIgnoreCase(map: Map<string, Context>, key: string) {
124✔
25
    const lowerCaseKey = key.toLowerCase();
220✔
26
    for (const currentKey of map.keys()) {
220✔
27
      if (currentKey.toLowerCase() === lowerCaseKey) {
260✔
28
        return map.get(currentKey);
132✔
29
      }
132✔
30
    }
260✔
31
    return undefined;
88✔
32
  }
88✔
33

124✔
34
  public add(path: string, context: Context): void {
124✔
35
    this.entries.set(path, context);
156✔
36
    this.cache.set(path, structuredClone(context));
156✔
37
  }
156✔
38

124✔
39
  public find(path: string): Context {
124✔
40
    return (
220✔
41
      this.getContextIgnoreCase(this.entries, path) ??
220✔
42
      this.find(parentPath(path))
88✔
43
    );
220✔
44
  }
220✔
45

124✔
46
  // eslint-disable-next-line max-statements
124✔
47
  public update(path: string, updatedContext?: Context): void {
124✔
48
    if (updatedContext === undefined) {
22!
UNCOV
49
      return;
×
UNCOV
50
    }
×
51

22✔
52
    if (!this.seen.has(path)) {
22✔
53
      this.seen.add(path);
18✔
54
      this.add(path, updatedContext);
18✔
55
      return;
18✔
56
    }
18✔
57

4✔
58
    const context = this.find(path);
4✔
59

4✔
60
    for (const property in updatedContext) {
10✔
61
      if (updatedContext[property] !== this.cache.get(path)?.[property]) {
10✔
62
        context[property] = updatedContext[property];
4✔
63
      }
4✔
64
    }
10✔
65

4✔
66
    // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
4✔
67
    Object.setPrototypeOf(context, Object.getPrototypeOf(updatedContext));
4✔
68

4✔
69
    this.cache.set(path, structuredClone(updatedContext));
4✔
70
  }
4✔
71
}
124✔
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