mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
WIP
This commit is contained in:
@@ -67,10 +67,8 @@ const dir = load_dir('.')
|
||||
console.time('run')
|
||||
|
||||
const i = test_initial_state(
|
||||
`
|
||||
import './test/run.js'
|
||||
`,
|
||||
{project_dir: dir}
|
||||
{}, // files
|
||||
{project_dir: dir, entrypoint: 'test/run.js'}
|
||||
)
|
||||
assert_equal(i.loading_external_imports_state != null, true)
|
||||
|
||||
@@ -81,6 +79,8 @@ assert_equal(loaded.eval_modules_state != null, true)
|
||||
const s = loaded.eval_modules_state
|
||||
const result = await s.promise
|
||||
const state = COMMANDS.eval_modules_finished(loaded , result, s.node, s.toplevel)
|
||||
const root = root_calltree_node(state)
|
||||
const run = root.children[0]
|
||||
|
||||
assert_equal(root_calltree_node(state).ok, true)
|
||||
|
||||
|
||||
34
test/test.js
34
test/test.js
@@ -2779,18 +2779,38 @@ const y = x()`
|
||||
)
|
||||
}),
|
||||
|
||||
// TODO
|
||||
/*
|
||||
test('async/await Promise.then creates subcall', async () => {
|
||||
const i = await test_initial_state_async(`
|
||||
await Promise.resolve(1).then(x => {
|
||||
})
|
||||
const x = () => 1
|
||||
await Promise.resolve(1).then(x)
|
||||
`)
|
||||
console.log('i', root_calltree_node(i))
|
||||
|
||||
const root = root_calltree_node(i)
|
||||
assert_equal(root.children.at(-1).children[0].fn.name, 'x')
|
||||
}),
|
||||
|
||||
test('async/await bug', async () => {
|
||||
test('async/await Promise.catch creates subcall', async () => {
|
||||
const i = await test_initial_state_async(`
|
||||
const x = () => 1
|
||||
await Promise.reject(1).catch(x)
|
||||
`)
|
||||
const root = root_calltree_node(i)
|
||||
assert_equal(root.children.at(-1).children[0].fn.name, 'x')
|
||||
}),
|
||||
|
||||
|
||||
test_only('async/await native Promise.then creates subcall', async () => {
|
||||
const i = await test_initial_state_async(`
|
||||
const x = () => 1
|
||||
const async_fn = async () => 1
|
||||
await async_fn().then(x)
|
||||
`)
|
||||
const root = root_calltree_node(i)
|
||||
assert_equal(root.children.at(-1).children[0].fn.name, 'x')
|
||||
}),
|
||||
|
||||
/*
|
||||
// TODO
|
||||
test('async/await move_cursor', async () => {
|
||||
const code = `
|
||||
const f = async () => {
|
||||
console.log('f')
|
||||
|
||||
@@ -151,21 +151,20 @@ export const test_only = (message, t) => test(message, t, true)
|
||||
// TODO in calltree view, hide fn which has special flag set (see
|
||||
// filter_calltree)
|
||||
|
||||
const AsyncFunction = new Function(`return (async () => {}).constructor`)()
|
||||
|
||||
export const run = Object.defineProperty(new AsyncFunction('tests', `
|
||||
const run_test = async t => {
|
||||
try {
|
||||
await t.test()
|
||||
} catch(e) {
|
||||
if(globalThis.process != null) {
|
||||
// In node.js runner, fail fast
|
||||
console.error('Failed: ' + t.message)
|
||||
throw e
|
||||
} else {
|
||||
return e
|
||||
}
|
||||
}
|
||||
export const run = Object.defineProperty(new Function('tests', `
|
||||
// Runs test, return failure or null if not failed
|
||||
const run_test = t => {
|
||||
return Promise.resolve(t.test())
|
||||
.then(() => null)
|
||||
.catch(e => {
|
||||
if(globalThis.process != null) {
|
||||
// In node.js runner, fail fast
|
||||
console.error('Failed: ' + t.message)
|
||||
throw e
|
||||
} else {
|
||||
return e
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// If not run in node, then dont apply filter
|
||||
@@ -178,32 +177,35 @@ export const run = Object.defineProperty(new AsyncFunction('tests', `
|
||||
|
||||
// Exec each test. After all tests are done, we rethrow first error if
|
||||
// any. So we will mark root calltree node if one of tests failed
|
||||
const failure = await tests_to_run.reduce(
|
||||
async (failureP, t) => {
|
||||
const failure = await failureP
|
||||
const next_failure = await run_test(t)
|
||||
return failure ?? next_failure
|
||||
},
|
||||
return tests_to_run.reduce(
|
||||
(failureP, t) =>
|
||||
Promise.resolve(failureP).then(failure =>
|
||||
run_test(t).then(next_failure => failure ?? next_failure)
|
||||
)
|
||||
,
|
||||
null
|
||||
)
|
||||
).then(failure => {
|
||||
|
||||
if(failure != null) {
|
||||
throw failure
|
||||
} else {
|
||||
if(globalThis.process != null) {
|
||||
console.log('Ok')
|
||||
if(failure != null) {
|
||||
throw failure
|
||||
} else {
|
||||
if(globalThis.process != null) {
|
||||
console.log('Ok')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
} else {
|
||||
const test = tests.find(t => t.message.includes(filter))
|
||||
if(test == null) {
|
||||
throw new Error('test not found')
|
||||
} else {
|
||||
await run_test(test)
|
||||
if(globalThis.process != null) {
|
||||
console.log('Ok')
|
||||
}
|
||||
return run_test(test).then(() => {
|
||||
if(globalThis.process != null) {
|
||||
console.log('Ok')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
`), 'name', {value: 'run'})
|
||||
|
||||
Reference in New Issue
Block a user