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

pmcelhaney / counterfact / 6512240392

13 Oct 2023 07:17PM UTC coverage: 86.447% (-1.4%) from 87.815%
6512240392

Pull #606

github

pmcelhaney
add changeset for fixing shared context
Pull Request #606: fix root context not shared

747 of 823 branches covered (0.0%)

Branch coverage included in aggregate %.

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

2455 of 2881 relevant lines covered (85.21%)

39.72 hits per line

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

78.08
/src/server/context-registry.ts
1
export interface Context {
2✔
2
  [key: string]: unknown;
2✔
3
}
2✔
4

2✔
5
export function parentPath(path: string): string {
2✔
6
  return String(path.split("/").slice(0, -1).join("/")) || "/";
96✔
7
}
96✔
8

2✔
9
export class ContextRegistry {
2✔
10
  private readonly entries = new Map<string, Context>();
86✔
11

86✔
12
  public constructor() {
86✔
13
    this.add("/", {});
86✔
14
  }
86✔
15

86✔
16
  public add(path: string, context?: Context): void {
86✔
17
    if (context === undefined) {
110!
18
      // If $.context.ts exists but only exports a type, then the context object will be undefined here.
×
19
      // This should be handled upstream, so that add() is not called in the first place.
×
20
      // But module-loader.ts needs to be refactored a bit using type guards and the is operator
×
21
      // before that can be done cleanly.
×
22
      return;
×
23
    }
×
24

110✔
25
    this.entries.set(path, context);
110✔
26
  }
110✔
27

86✔
28
  public find(path: string): Context {
86✔
29
    return this.entries.get(path) ?? this.find(parentPath(path));
180✔
30
  }
180✔
31

86✔
32
  public update(path: string, updatedContext?: Context): void {
86✔
33
    if (updatedContext === undefined) {
2!
34
      return;
×
35
    }
×
36

2✔
37
    const context = this.find(path);
2✔
38

2✔
39
    for (const property in updatedContext) {
2✔
40
      if (
2✔
41
        Object.prototype.hasOwnProperty.call(updatedContext, property) &&
2✔
42
        !Object.prototype.hasOwnProperty.call(context, property)
2✔
43
      ) {
2!
44
        context[property] = updatedContext[property];
×
45
      }
×
46
    }
2✔
47

2✔
48
    // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
2✔
49
    Object.setPrototypeOf(context, Object.getPrototypeOf(updatedContext));
2✔
50
  }
2✔
51
}
86✔
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