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

source-academy / js-slang / 24834367427

23 Apr 2026 12:09PM UTC coverage: 78.541% (+0.2%) from 78.391%
24834367427

Pull #1893

github

web-flow
Merge ab101147d into 715603479
Pull Request #1893: Error Handling and Stringify Changes

3126 of 4197 branches covered (74.48%)

Branch coverage included in aggregate %.

801 of 975 new or added lines in 76 files covered. (82.15%)

20 existing lines in 11 files now uncovered.

7056 of 8767 relevant lines covered (80.48%)

173930.4 hits per line

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

88.89
/src/utils/misc.ts
1
import { TimeoutError } from '../errors/timeoutErrors';
2
import type { Node } from '../types';
3
import { Chapter, Variant } from '../langs';
4

5
export class PromiseTimeoutError extends TimeoutError {
6
  public override explain() {
NEW
7
    return 'An internal operation timed out while executing.';
×
8
  }
9
}
10

11
export const timeoutPromise = <T>(promise: Promise<T>, timeout: number, node?: Node) =>
72✔
12
  new Promise<T>((resolve, reject) => {
11✔
13
    const timeoutid = setTimeout(() => reject(new PromiseTimeoutError(node)), timeout);
11✔
14

15
    promise
11✔
16
      .then(res => {
17
        clearTimeout(timeoutid);
8✔
18
        resolve(res);
8✔
19
      })
20
      .catch(e => {
21
        clearTimeout(timeoutid);
2✔
22
        reject(e);
2✔
23
      });
24
  });
25

26
/**
27
 * Run the mapping function over the items, filtering out any items that
28
 * that the mapping function returned `undefined` for
29
 */
30
export function mapAndFilter<T, U>(items: T[], mapper: (input: T) => U | undefined) {
31
  return items.reduce((res, item) => {
30,704✔
32
    const newItem = mapper(item);
33,003✔
33
    if (newItem !== undefined) return [...res, newItem];
33,003✔
34
    return res;
26,402✔
35
  }, [] as U[]);
36
}
37

38
/**
39
 * Type safe `Object.keys`
40
 */
41
export function objectKeys<T extends string | number | symbol>(obj: Record<T, any>): T[] {
42
  return Object.keys(obj) as T[];
165✔
43
}
44

45
/**
46
 * Given the chapter value, return the string name of that chapter
47
 */
48
export function getChapterName(chapter: Chapter) {
49
  return objectKeys(Chapter).find(name => Chapter[name] === chapter)!;
707✔
50
}
51

52
/**
53
 * Given the variant value, return the string name of that variant
54
 */
55
export function getVariantName(variant: Variant) {
NEW
56
  return objectKeys(Variant).find(name => Variant[name] === variant)!;
×
57
}
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

© 2026 Coveralls, Inc