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

source-academy / js-slang / 13923617069

18 Mar 2025 12:49PM UTC coverage: 81.097% (+0.01%) from 81.086%
13923617069

Pull #1752

github

web-flow
Merge 2e2380269 into 12bfe7019
Pull Request #1752: Fix for JSON imports not working

3440 of 4608 branches covered (74.65%)

Branch coverage included in aggregate %.

13 of 14 new or added lines in 1 file covered. (92.86%)

10786 of 12934 relevant lines covered (83.39%)

147451.83 hits per line

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

88.24
/src/editors/ace/docTooltip/index.ts
1
import * as ext_lib from './External libraries.json'
58✔
2
import * as source_1 from './source_1.json'
58✔
3
import * as source_1_typed from './source_1_typed.json'
58✔
4
import * as source_2 from './source_2.json'
58✔
5
import * as source_2_typed from './source_2_typed.json'
58✔
6
import * as source_3 from './source_3.json'
58✔
7
import * as source_3_concurrent from './source_3_concurrent.json'
58✔
8
import * as source_3_typed from './source_3_typed.json'
58✔
9
import * as source_4 from './source_4.json'
58✔
10
import * as source_4_typed from './source_4_typed.json'
58✔
11
import * as source_4_explicit_control from './source_4_explicit-control.json'
58✔
12

13
// (18 March 2022)
14
// Problem to be fixed in the future:
15
//
16
// There seems to be an inconsistency between how jest and how typescript
17
// behaves when encountering imports of the form `import * as x from 'x.json'`
18
// jest will set x = jsonobject,
19
// but typescript will instead set x = { default: jsonobject }
20
//
21
// This means that under typescript, we want `import x from 'x.json'`,
22
// while under jest, we want `import * as x from 'x.json'`
23
//
24
// This problem was hidden when transpiling to CommonJS modules before, which
25
// behaves similarly to jest. But now that we are transpiling to es6,
26
// typescript projects that depend on js-slang may now be exposed to this
27
// inconsistency.
28
//
29
// For now, we use brute force until the landscape changes or someone thinks of
30
// a proper solution.
31
function resolveImportInconsistency(json: any) {
32
  // `json` doesn't inherit from `Object`?
33
  // Can't use hasOwnProperty for some reason.
34
  if ('default' in json) {
580!
NEW
35
    return json.default
×
36
  } else {
37
    return json
580✔
38
  }
39
}
40

41
export const SourceDocumentation = {
58✔
42
  builtins: {
43
    '1': resolveImportInconsistency(source_1),
44
    '1_typed': resolveImportInconsistency(source_1_typed),
45
    '2': resolveImportInconsistency(source_2),
46
    '2_typed': resolveImportInconsistency(source_2_typed),
47
    '3': resolveImportInconsistency(source_3),
48
    '3_concurrent': resolveImportInconsistency(source_3_concurrent),
49
    '3_typed': resolveImportInconsistency(source_3_typed),
50
    '4': resolveImportInconsistency(source_4),
51
    '4_typed': resolveImportInconsistency(source_4_typed),
52
    '4_explicit-control': resolveImportInconsistency(source_4_explicit_control)
53
  },
54
  ext_lib
55
}
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