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

source-academy / js-slang / 19080105112

04 Nov 2025 07:13PM UTC coverage: 76.655% (-1.5%) from 78.192%
19080105112

push

github

web-flow
Migrate to Vitest (#1815)

* Upgrade TS to 5.8

* Remove deprecated tsconfig option

* Remove duplicate properties

* Upgrade TS to v5.9

* Add types for mathjs

* Fix some type errors

* Update tsconfig

* Fix more type errors

* Fix remaining errors

* Update GitHub workflows

* Fix type error

* Update scm-slang to latest

* Add newline to EOF

* Fix cse-machine types and utils to use fewer type assertions

* Migrate to vitest tests

* Migrate tests to vitest

* Relocate base error files and types

* Get modules tests working

* run format

* Sort tsconfig compiler options

* Update eslint packages to match typescript version

* Small linting change

* Use function names instead of strings for describe blocks

* Include scripts in linting

* Move tests and replace describe titles with functions

* Add type modifiers and reformat tests

* Simplify isEnvDependent code

* Instruct tsc to ignore py-slang's tests during build

* Move walkers to be under utils/ast

* Update tests failing due to timeout

* Update cse-machine typings

* Incorporate import assertions into docs importer

* Add context property to error result

* Update test timeout and add no-restricted-import rule for commander imports

* Update snapshots

* Run format

* Update snapshots again....

* Run format

* Change to use the test.each

* Disable the svmc snapshot test cause it doesn't work

* Add a new test for properties when loading modules

* Run format

* Convert stdlib parser to use nodetypetonode helper type

* A working version of the statementSeqTransform

* More compact version of seq transform

* Remove unnecessary type assertions

* Clean up some documentation bits and pieces

* Use type imports for tracer

* Swap the list library to use generics

* Fix some error messages and tests

* Fix list tests

* Run format

* Update stream library and tests

* Running format

* Add some documentation for the scripts

* Remove unnecessary packages

* Remove even more unnecessary ty... (continued)

3501 of 4761 branches covered (73.53%)

Branch coverage included in aggregate %.

429 of 636 new or added lines in 54 files covered. (67.45%)

34 existing lines in 12 files now uncovered.

7085 of 9049 relevant lines covered (78.3%)

193248.37 hits per line

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

88.0
/src/runner/sourceRunner.ts
1
import * as _ from 'lodash'
2
import type { RawSourceMap } from 'source-map'
3

4
import { JSSLANG_PROPERTIES } from '../constants'
5
import { CSEResultPromise, evaluate as CSEvaluate } from '../cse-machine/interpreter'
6
import { ExceptionError } from '../errors/errors'
7
import { RuntimeSourceError } from '../errors/runtimeSourceError'
8
import { TimeoutError } from '../errors/timeoutErrors'
9
import { sandboxedEval } from '../transpiler/evalContainer'
10
import { transpile } from '../transpiler/transpiler'
11
import { getSteps } from '../tracer/steppers'
12
import { toSourceError } from './errors'
13
import type { Runner } from './types'
14
import fullJSRunner from './fullJSRunner'
15

16
let isPreviousCodeTimeoutError = false
59✔
17
const runners = {
59✔
18
  fulljs: fullJSRunner,
19
  'cse-machine': (program, context, options) => {
20
    const value = CSEvaluate(program, context, options)
1,041✔
21
    return CSEResultPromise(context, value)
1,041✔
22
  },
23
  substitution: (program, context, options) => {
24
    const steps = getSteps(program, context, options)
×
25
    if (context.errors.length > 0) {
×
NEW
26
      return Promise.resolve({ status: 'error', context })
×
27
    }
28
    return Promise.resolve({
×
29
      status: 'finished',
30
      context,
31
      value: steps
32
    })
33
  },
34
  native: async (program, context, options) => {
35
    if (!options.isPrelude) {
712✔
36
      if (context.shouldIncreaseEvaluationTimeout && isPreviousCodeTimeoutError) {
413✔
37
        context.nativeStorage.maxExecTime *= JSSLANG_PROPERTIES.factorToIncreaseBy
3✔
38
      } else {
39
        context.nativeStorage.maxExecTime = options.originalMaxExecTime
410✔
40
      }
41
    }
42

43
    // For whatever reason, the transpiler mutates the state of the AST as it is transpiling and inserts
44
    // a bunch of global identifiers to it. Once that happens, the infinite loop detection instrumentation
45
    // ends up generating code that has syntax errors. As such, we need to make a deep copy here to preserve
46
    // the original AST for future use, such as with the infinite loop detector.
47
    const transpiledProgram = _.cloneDeep(program)
712✔
48
    let transpiled
49
    let sourceMapJson: RawSourceMap | undefined
50
    try {
712✔
51
      ;({ transpiled, sourceMapJson } = transpile(transpiledProgram, context))
712✔
52
      let value = sandboxedEval(transpiled, context.nativeStorage)
712✔
53

54
      if (!options.isPrelude) {
712✔
55
        isPreviousCodeTimeoutError = false
346✔
56
      }
57

58
      return {
645✔
59
        status: 'finished',
60
        context,
61
        value
62
      }
63
    } catch (error) {
64
      if (error instanceof RuntimeSourceError) {
67✔
65
        context.errors.push(error)
19✔
66
        if (error instanceof TimeoutError) {
19✔
67
          isPreviousCodeTimeoutError = true
7✔
68
        }
69
        return { status: 'error', context }
19✔
70
      }
71
      if (error instanceof ExceptionError) {
48✔
72
        // if we know the location of the error, just throw it
73
        if (error.location.start.line !== -1) {
45✔
74
          context.errors.push(error)
40✔
75
          return { status: 'error', context }
40✔
76
        } else {
77
          error = error.error // else we try to get the location from source map
5✔
78
        }
79
      }
80

81
      const sourceError = await toSourceError(error, sourceMapJson)
8✔
82
      context.errors.push(sourceError)
8✔
83
      return { status: 'error', context }
8✔
84
    }
85
  }
86
} satisfies Record<string, Runner>
87

88
export default runners
89

90
export type RunnerTypes = keyof typeof runners
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