How to use the js-slang.runInContext function in js-slang

To help you get started, we’ve selected a few js-slang examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github source-academy / cadet-frontend / src / sagas / __tests__ / workspaces.ts View on Github external
test('with error in the code, should return correct line number in error', () => {
      code = '// Prepend\n error';
      state = generateDefaultState(workspaceLocation, { editorPrepend: '// Prepend' });

      runInContext(code, context, { scheduler: 'preemptive', originalMaxExecTime: 1000 }).then(
        result => (context = (result as Finished).context)
      );

      const errors = context.errors.map((error: SourceError) => {
        const newError = cloneDeep(error);
        newError.location.start.line = newError.location.start.line - 1;
        newError.location.end.line = newError.location.end.line - 1;
        return newError;
      });

      return expectSaga(evalCode, code, context, execTime, workspaceLocation, actionType)
        .withState(state)
        .call(runInContext, code, context, {
          scheduler: 'preemptive',
          originalMaxExecTime: execTime
        })