From 0332d5a0b86c9fa3e1f8dfde2b0d85f6c1cc0a97 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Tue, 29 Nov 2022 03:37:15 +0800 Subject: [PATCH] fixes --- README.md | 6 +++--- src/eval.js | 4 ++-- test/test.js | 12 +++++++----- test/utils.js | 16 +++++++++------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f491da4..a3a32a1 100644 --- a/README.md +++ b/README.md @@ -113,9 +113,9 @@ import BigNumber from './path/to/bignumber.mjs'; ![External import](docs/images/external_import.png) -Currently every external is loaded once and cached until Leporello is restarted -(TODO what happens if we load modules in iframe and then recreate iframe) -(TODO serve modules from service worker, change host every time) +Currently every external is loaded once and cached until Leporello is restarted +(TODO change path to modules every time it changed on disk, since modules are +served from service workers). ## Hotkeys diff --git a/src/eval.js b/src/eval.js index a9dd42e..7bb82c7 100644 --- a/src/eval.js +++ b/src/eval.js @@ -58,8 +58,8 @@ type Node = ToplevelCall | Call // TODO just export const Iframe_Function? const make_function = (...args) => { - if(globalThis.process != null) { - // Tests are run in Node.js + if(globalThis.run_window == null) { + // Code is executed in test env return new Function(...args) } else { // Code run in browser and user opened run_window diff --git a/test/test.js b/test/test.js index 35e3e5d..d836a0f 100644 --- a/test/test.js +++ b/test/test.js @@ -2241,14 +2241,16 @@ const y = x()` }), test('get_initial_state toplevel not entrypoint', () => { - const s = COMMANDS.get_initial_state({ - files: { + const s = test_initial_state( + { '' : `import {x} from 'x'; x()`, 'x' : `export const x = () => 1; x()`, }, - entrypoint: '', - current_module: 'x', - }) + { + entrypoint: '', + current_module: 'x', + } + ) assert_equal(s.current_calltree_node.toplevel, true) assert_equal(s.active_calltree_node, null) }), diff --git a/test/utils.js b/test/utils.js index e70252d..30339f4 100644 --- a/test/utils.js +++ b/test/utils.js @@ -28,13 +28,15 @@ export const assert_code_error = (codestring, error) => { } export const test_initial_state = (code, state) => { - return COMMANDS.get_initial_state( - { - ...state, - files: typeof(code) == 'object' ? code : { '' : code}, - entrypoint: '', - current_module: '', - }, + return COMMANDS.open_run_window( + COMMANDS.get_initial_state( + { + files: typeof(code) == 'object' ? code : { '' : code}, + entrypoint: '', + current_module: '', + ...state, + }, + ) ) }