async calls WIP

This commit is contained in:
Dmitry Vasilev
2022-10-25 02:29:59 +08:00
parent 7c9c74988d
commit 1d1215b718
5 changed files with 98 additions and 12 deletions

View File

@@ -2227,4 +2227,18 @@ const y = x()`
)
}),
test_only('async calls', () => {
const code = `
const fn = () => {
}
// Use Function constructor to exec impure code for testing
new Function('fn', 'globalThis.__run_async_call = fn')(fn)
`
const i = test_initial_state(code, {
on_async_call: (calls) => {console.log('test on async call', calls)}
})
globalThis.__run_async_call()
delete globalThis.__run_async_call
}),
]

View File

@@ -27,12 +27,15 @@ export const assert_code_error = (codestring, error) => {
assert_equal(result.error, error)
}
export const test_initial_state = code => {
return get_initial_state({
export const test_initial_state = (code, state) => {
return get_initial_state(
{
...state,
files: typeof(code) == 'object' ? code : { '' : code},
entrypoint: '',
current_module: '',
})
},
)
}
export const stringify = val =>