update tests

entangle-batches
Simon Holthausen 2 months ago
parent 0fe8256acc
commit cec3ebc013

@ -23,12 +23,10 @@ export default test({
pop.click();
await tick();
assert.htmlEqual(p.innerHTML, `1 + 0 = 1 | 1 0`);
assert.htmlEqual(p.innerHTML, `0 + 0 = 0 | 0 0`);
shift.click();
await tick();
pop.click();
await tick();
assert.htmlEqual(p.innerHTML, `1 + 2 = 3 | 1 1`);
}
});

@ -19,11 +19,12 @@ export default test({
await tick();
assert.htmlEqual(p.innerHTML, `0 + 0 = 0 | 0 0`);
// Check that the first batch can still resolve before the second even if one of its async values
// is already superseeded (but the subsequent batch as a whole is still pending).
// Previously check that the first batch can still resolve before the second even if one of its async values
// is already superseeded (but the subsequent batch as a whole is still pending) - now that batches are
// entangled this no longer happens and instead everything is waited on.
shift_1.click();
await tick();
assert.htmlEqual(p.innerHTML, `1 + 0 = 1 | 1 0`);
assert.htmlEqual(p.innerHTML, `0 + 0 = 0 | 0 0`);
shift_1.click();
await tick();

@ -7,29 +7,23 @@ export default test({
x.click();
await tick();
assert.deepEqual(logs, ['universe']);
y.click();
await tick();
assert.deepEqual(logs, ['universe', 'universe']);
assert.htmlEqual(
target.innerHTML,
`
<button>x</button>
<button>y++</button>
<button>resolve</button>
world
` // if this does not show world - that would also be ok
`
);
resolve.click();
await tick();
assert.deepEqual(logs, [
'universe',
'world',
'$effect: world',
'$effect: universe',
'$effect: universe'
]);
// assert.deepEqual(logs, ['universe', 'universe', '$effect: universe', '$effect: universe']); // this would also be ok
assert.deepEqual(logs, ['universe', 'universe', '$effect: universe', '$effect: universe']);
assert.htmlEqual(
target.innerHTML,
`

@ -17,13 +17,7 @@ export default test({
<button>y++</button>
<button>resolve</button>
<hr>
world
"world"
world
world
world
"world"
` // if this does not show world "world" world world world "world" - then this would also be ok
`
);
resolve.click();

@ -29,17 +29,9 @@ export default test({
<button>y++</button>
<button>resolve</button>
<hr>
world
"world"
world
world
world
"world"
` // if this does not show world "world" world world world "world" - then this would also be ok
`
);
resolve.click();
await tick();
resolve.click();
await tick();
assert.htmlEqual(

@ -1,7 +0,0 @@
<script>
let { x } = $props();
console.log(x);
$effect(() => console.log('$effect: '+ x))
</script>
{x}

@ -1,46 +0,0 @@
import { tick } from 'svelte';
import { test } from '../../test';
export default test({
async test({ assert, target, logs }) {
const [x, y, resolve] = target.querySelectorAll('button');
x.click();
await tick();
assert.deepEqual(logs, ['universe']);
y.click();
await tick();
assert.deepEqual(logs, ['universe', 'world', '$effect: world']);
assert.htmlEqual(
target.innerHTML,
`
<button>x</button>
<button>y++</button>
<button>resolve</button>
world
`
);
resolve.click();
await tick();
assert.deepEqual(logs, [
'universe',
'world',
'$effect: world',
'$effect: universe',
'$effect: universe'
]);
assert.htmlEqual(
target.innerHTML,
`
<button>x</button>
<button>y++</button>
<button>resolve</button>
universe
universe
universe
`
);
}
});

@ -1,28 +0,0 @@
<script>
import Child from './Child.svelte';
let x = $state('world');
let y = $state(0);
let deferred = [];
function delay(s) {
const d = Promise.withResolvers();
deferred.push(() => d.resolve(s))
return d.promise;
}
</script>
<button onclick={() => x = 'universe'}>x</button>
<button onclick={() => y++}>y++</button>
<button onclick={() => deferred.shift()()}>resolve</button>
{#if x === 'universe'}
{await delay(x)}
<Child {x} />
{/if}
{#if y > 0}
<Child {x} />
{/if}
Loading…
Cancel
Save