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

source-academy / js-slang / 14529259416

18 Apr 2025 03:46AM UTC coverage: 80.538%. Remained the same
14529259416

Pull #1757

github

web-flow
Merge 63eac9783 into fea2b4cad
Pull Request #1757: Language options

3458 of 4687 branches covered (73.78%)

Branch coverage included in aggregate %.

15 of 88 new or added lines in 6 files covered. (17.05%)

84 existing lines in 6 files now uncovered.

10811 of 13030 relevant lines covered (82.97%)

142544.19 hits per line

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

93.1
/src/mocks/context.ts
1
import * as es from 'estree'
2

3
import createContext, { EnvTree } from '../createContext'
70✔
4
import OldClosure from '../interpreter/closure'
70✔
5
import Closure from '../cse-machine/closure'
70✔
6
import { createBlockEnvironment } from '../interpreter/interpreter'
70✔
7
import { Chapter, Context, Environment, Variant } from '../types'
70✔
8
import { Transformers } from '../cse-machine/interpreter'
70✔
9

10
export function mockContext(
70✔
11
  chapter: Chapter = Chapter.SOURCE_1,
40✔
12
  variant: Variant = Variant.DEFAULT,
720✔
13
  languageOptions = {}
895✔
14
): Context {
15
  return createContext(chapter, variant, languageOptions)
895✔
16
}
17

18
export function mockImportDeclaration(): es.ImportDeclaration {
70✔
UNCOV
19
  const mockImportDecl: es.ImportDeclaration = {
×
20
    type: 'ImportDeclaration',
21
    specifiers: [
22
      {
23
        type: 'ImportDefaultSpecifier',
24
        local: {
25
          type: 'Identifier',
26
          name: 'MockName'
27
        }
28
      }
29
    ],
30
    source: {
31
      type: 'Literal',
32
      value: 'mock-path',
33
      raw: "'mock-path'"
34
    }
35
  }
UNCOV
36
  return mockImportDecl
×
37
}
38

39
export function mockRuntimeContext(): Context {
70✔
40
  const context = createContext()
1,014✔
41
  context.runtime = {
1,014✔
42
    break: false,
43
    debuggerOn: true,
44
    isRunning: true,
45
    environmentTree: new EnvTree(),
46
    environments: [],
47
    nodes: [
48
      {
49
        type: 'Literal',
50
        loc: {
51
          start: { line: 1, column: 0 },
52
          end: { line: 1, column: 1 }
53
        },
54
        value: 0,
55
        raw: '0',
56
        range: [0, 1]
57
      }
58
    ],
59
    control: null,
60
    stash: null,
61
    objectCount: 0,
62
    envStepsTotal: 0,
63
    breakpointSteps: [],
64
    changepointSteps: []
65
  }
66
  return context
1,014✔
67
}
68

69
export function mockClosure(cseMachineClosure: true): Closure
70
export function mockClosure(cseMachineClosure?: false): OldClosure
71
export function mockClosure(cseMachineClosure?: boolean): Closure | OldClosure {
70✔
72
  const context = createContext()
3✔
73
  if (cseMachineClosure) {
3✔
74
    return new Closure(
2✔
75
      {
76
        type: 'ArrowFunctionExpression',
77
        expression: true,
78
        loc: null,
79
        params: [],
80
        body: {
81
          type: 'BlockStatement',
82
          body: []
83
        }
84
      } as es.ArrowFunctionExpression,
85
      mockEnvironment(context),
86
      mockTransformers(),
87
      context
88
    )
89
  }
90
  return new OldClosure(
1✔
91
    {
92
      type: 'ArrowFunctionExpression',
93
      expression: true,
94
      loc: null,
95
      params: [],
96
      body: {
97
        type: 'BlockStatement',
98
        body: []
99
      }
100
    } as es.ArrowFunctionExpression,
101
    mockEnvironment(context),
102
    context
103
  )
104
}
105

106
export function mockEnvironment(context: Context, name = 'blockEnvironment'): Environment {
70✔
107
  return createBlockEnvironment(context, name)
11✔
108
}
109

110
export function mockTransformers(): any {
70✔
111
  return new Transformers()
2✔
112
}
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