refactor test_initial_state

This commit is contained in:
Dmitry Vasilev
2024-02-10 15:20:46 +08:00
parent 92fe237c2b
commit 2fda050118
3 changed files with 21 additions and 9 deletions

View File

@@ -70,12 +70,19 @@ console.time('run')
const i = test_initial_state(
{}, // files
undefined,
{project_dir: dir},
{entrypoint: 'test/run.js'},
{
project_dir: dir,
entrypoint: 'test/run.js',
}
)
if(!i.parse_result.ok) {
console.error('Parse errors:', i.parse_result.problems)
i.parse_result.problems.forEach(p => {
if(p.index != null) {
console.error(p.module + ': ' + p.message + ' at ' + i.files[p.module].slice(p.index, p.index + 80))
}
})
throw new Error('parse error')
}

View File

@@ -3320,9 +3320,7 @@ const y = x()`
'x' : `export const x = () => 1; x()`,
},
undefined,
undefined,
{
entrypoint: '',
current_module: 'x',
}
)

View File

@@ -98,20 +98,27 @@ export const assert_code_error_async = async (codestring, error) => {
assert_equal(result.error, error)
}
export const test_initial_state = (code, cursor_pos, other, entrypoint_settings) => {
export const test_initial_state = (code, cursor_pos, options = {}) => {
if(cursor_pos < 0) {
throw new Error('illegal cursor_pos')
}
const {
//entrypoint = '',
current_module,
project_dir,
on_deferred_call,
} = options
const entrypoint = options.entrypoint ?? ''
return COMMANDS.open_app_window(
COMMANDS.get_initial_state(
{
files: typeof(code) == 'object' ? code : { '' : code},
...other
project_dir,
on_deferred_call,
},
{
entrypoint: '',
current_module: '',
...entrypoint_settings,
entrypoint,
current_module: current_module ?? '',
},
cursor_pos
),