From 36ef59df1f35635d53947b357d4211f3bf1f713a Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 13 Jan 2025 21:14:07 +0000 Subject: [PATCH] chore: improve test cases (#14984) * chore: improve test cases * lint --- .../camel-case-attribute/_config.js | 7 ++-- .../custom-method/_config.js | 4 ++- .../element-effect-context/_config.js | 3 +- .../_config.js | 6 ++-- .../_config.js | 6 ++-- .../_config.js | 6 ++-- .../_config.js | 6 ++-- .../action-custom-event-handler/_config.js | 6 ++-- .../samples/action-this/_config.js | 4 ++- .../samples/await-mutate-array/_config.js | 5 ++- .../await-then-destruct-object-if/_config.js | 3 ++ .../samples/before-render-chain/_config.js | 6 ++-- .../_config.js | 6 ++-- .../binding-contenteditable-text/_config.js | 6 ++-- .../_config.js | 6 ++-- .../binding-select-in-yield/_config.js | 15 +++++---- .../samples/bindings-coalesced/_config.js | 6 ++-- .../component-props-mutated/_config.js | 6 ++-- .../samples/component-slot-let-g/_config.js | 6 ++-- .../samples/destructured-props-2/_config.js | 3 +- .../samples/destructured-props-3/_config.js | 4 ++- .../samples/destructured-props-5/_config.js | 3 +- .../destructuring-assignment-array/_config.js | 7 ++-- .../samples/key-block-expression-2/_config.js | 15 ++++++--- .../samples/prop-const/_config.js | 6 ++-- .../samples/props-reactive-b/_config.js | 9 +++-- .../_config.js | 6 ++-- .../_config.js | 33 +++++++++++-------- .../reactive-value-function/_config.js | 6 ++-- .../reactive-values-text-node/_config.js | 3 ++ .../samples/spread-own-props/_config.js | 6 ++-- .../_config.js | 8 ++--- .../_config.js | 7 ++-- .../samples/store-unreferenced/_config.js | 6 ++-- .../samples/window-event-custom/_config.js | 6 ++-- .../samples/derived-unowned-2/_config.js | 3 +- .../samples/derived-unowned-5/_config.js | 3 +- .../samples/runes-from-func/_config.js | 3 +- 38 files changed, 164 insertions(+), 86 deletions(-) diff --git a/packages/svelte/tests/runtime-browser/custom-elements-samples/camel-case-attribute/_config.js b/packages/svelte/tests/runtime-browser/custom-elements-samples/camel-case-attribute/_config.js index ba3be3c25b..b9bfdd7782 100644 --- a/packages/svelte/tests/runtime-browser/custom-elements-samples/camel-case-attribute/_config.js +++ b/packages/svelte/tests/runtime-browser/custom-elements-samples/camel-case-attribute/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../assert'; const tick = () => Promise.resolve(); @@ -14,8 +15,7 @@ export default test({ el.setAttribute('camel-case', 'universe'); el.setAttribute('an-array', '[3,4]'); el.setAttribute('camelcase2', 'Hi'); - await tick(); - await tick(); + flushSync(); assert.htmlEqual(el.shadowRoot.innerHTML, '

Hi universe!

3

4

'); assert.htmlEqual( target.innerHTML, @@ -25,8 +25,7 @@ export default test({ el.camelCase = 'galaxy'; el.camelCase2 = 'Hey'; el.anArray = [5, 6]; - await tick(); - await tick(); + flushSync(); assert.htmlEqual(el.shadowRoot.innerHTML, '

Hey galaxy!

5

6

'); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-browser/custom-elements-samples/custom-method/_config.js b/packages/svelte/tests/runtime-browser/custom-elements-samples/custom-method/_config.js index dbdf006be5..4314926a94 100644 --- a/packages/svelte/tests/runtime-browser/custom-elements-samples/custom-method/_config.js +++ b/packages/svelte/tests/runtime-browser/custom-elements-samples/custom-method/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../assert'; const tick = () => Promise.resolve(); @@ -8,7 +9,8 @@ export default test({ /** @type {any} */ const el = target.querySelector('custom-element'); - await el.updateFoo(42); + el.updateFoo(42); + flushSync(); const p = el.shadowRoot.querySelector('p'); assert.equal(p.textContent, '42'); diff --git a/packages/svelte/tests/runtime-browser/custom-elements-samples/element-effect-context/_config.js b/packages/svelte/tests/runtime-browser/custom-elements-samples/element-effect-context/_config.js index 3cf7a66df1..7f2ba9f331 100644 --- a/packages/svelte/tests/runtime-browser/custom-elements-samples/element-effect-context/_config.js +++ b/packages/svelte/tests/runtime-browser/custom-elements-samples/element-effect-context/_config.js @@ -1,4 +1,5 @@ import { test } from '../../assert'; +import { flushSync } from 'svelte'; const tick = () => Promise.resolve(); export default test({ @@ -16,7 +17,7 @@ export default test({ assert.equal(p.innerHTML, 'false'); button.click(); - await tick(); + flushSync(); assert.equal(button.innerHTML, '1'); assert.equal(p.innerHTML, 'false'); diff --git a/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-in-each-destructured/_config.js b/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-in-each-destructured/_config.js index 650d0ec360..fe13d43bc8 100644 --- a/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-in-each-destructured/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-in-each-destructured/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -10,12 +11,13 @@ export default test({

second:

`, - async test({ assert, component, target, window }) { + test({ assert, component, target, window }) { const event = new window.MouseEvent('click'); const buttons = target.querySelectorAll('button'); - await buttons[1].dispatchEvent(event); + buttons[1].dispatchEvent(event); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-in-each/_config.js b/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-in-each/_config.js index 21fb167873..83b14cb8a3 100644 --- a/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-in-each/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-in-each/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -10,12 +11,13 @@ export default test({

fromState:

`, - async test({ assert, component, target, window }) { + test({ assert, component, target, window }) { const event = new window.MouseEvent('click'); const buttons = target.querySelectorAll('button'); - await buttons[1].dispatchEvent(event); + buttons[1].dispatchEvent(event); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-node-context/_config.js b/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-node-context/_config.js index a2edd90f8b..9276ca8a59 100644 --- a/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-node-context/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-node-context/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { ok, test } from '../../test'; export default test({ @@ -5,13 +6,14 @@ export default test({ html: '', - async test({ assert, target, window }) { + test({ assert, target, window }) { const event = new window.MouseEvent('click'); const button = target.querySelector('button'); ok(button); - await button.dispatchEvent(event); + button.dispatchEvent(event); + flushSync(); assert.htmlEqual(target.innerHTML, ''); } diff --git a/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-with-context/_config.js b/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-with-context/_config.js index c4d84fc2b3..2e6aa4dfee 100644 --- a/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-with-context/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler-with-context/_config.js @@ -1,9 +1,10 @@ +import { flushSync } from 'svelte'; import { ok, test } from '../../test'; export default test({ html: '', - async test({ assert, target, window }) { + test({ assert, target, window }) { const event = new window.MouseEvent('click', { clientX: 42, clientY: 42 @@ -12,7 +13,8 @@ export default test({ const button = target.querySelector('button'); ok(button); - await button.dispatchEvent(event); + button.dispatchEvent(event); + flushSync(); assert.htmlEqual(target.innerHTML, ''); } diff --git a/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler/_config.js b/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler/_config.js index 279171692d..3769a8bd81 100644 --- a/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/action-custom-event-handler/_config.js @@ -1,9 +1,10 @@ +import { flushSync } from 'svelte'; import { ok, test } from '../../test'; export default test({ html: '', - async test({ assert, target, window }) { + test({ assert, target, window }) { const event = new window.MouseEvent('click', { clientX: 42, clientY: 42 @@ -12,7 +13,8 @@ export default test({ const button = target.querySelector('button'); ok(button); - await button.dispatchEvent(event); + button.dispatchEvent(event); + flushSync(); assert.htmlEqual(target.innerHTML, ''); } diff --git a/packages/svelte/tests/runtime-legacy/samples/action-this/_config.js b/packages/svelte/tests/runtime-legacy/samples/action-this/_config.js index d296fc5a28..0ab9305ade 100644 --- a/packages/svelte/tests/runtime-legacy/samples/action-this/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/action-this/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { ok, test } from '../../test'; export default test({ @@ -8,7 +9,8 @@ export default test({ const click = new window.MouseEvent('click'); assert.htmlEqual(target.innerHTML, ''); - await button.dispatchEvent(click); + button.dispatchEvent(click); + flushSync(); assert.htmlEqual(target.innerHTML, ''); } }); diff --git a/packages/svelte/tests/runtime-legacy/samples/await-mutate-array/_config.js b/packages/svelte/tests/runtime-legacy/samples/await-mutate-array/_config.js index 67ea2cb0a3..70268a0e1d 100644 --- a/packages/svelte/tests/runtime-legacy/samples/await-mutate-array/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/await-mutate-array/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -11,7 +12,9 @@ export default test({ const [b1] = target.querySelectorAll('button'); b1.click(); - await Promise.resolve(); + Promise.resolve(); + flushSync(); + assert.htmlEqual( target.innerHTML, `\n-------\n` diff --git a/packages/svelte/tests/runtime-legacy/samples/await-then-destruct-object-if/_config.js b/packages/svelte/tests/runtime-legacy/samples/await-then-destruct-object-if/_config.js index e823c21c9a..af04467749 100644 --- a/packages/svelte/tests/runtime-legacy/samples/await-then-destruct-object-if/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/await-then-destruct-object-if/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -11,6 +12,7 @@ export default test({ async test({ assert, component, target }) { await (component.thePromise = Promise.resolve({ result: 1 })); + flushSync(); assert.htmlEqual( target.innerHTML, @@ -21,6 +23,7 @@ export default test({ ); await new Promise((resolve) => setTimeout(resolve, 1)); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/before-render-chain/_config.js b/packages/svelte/tests/runtime-legacy/samples/before-render-chain/_config.js index 9364bd9f9e..580df5ca81 100644 --- a/packages/svelte/tests/runtime-legacy/samples/before-render-chain/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/before-render-chain/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -9,8 +10,9 @@ export default test({ 1 `, - async test({ assert, component, target }) { - await component.list.update(); + test({ assert, component, target }) { + component.list.update(); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-text-initial/_config.js b/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-text-initial/_config.js index e2a28e8dd9..83ad9c2558 100644 --- a/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-text-initial/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-text-initial/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { ok, test } from '../../test'; export default test({ @@ -18,7 +19,7 @@ export default test({

hello

`, - async test({ assert, component, target, window }) { + test({ assert, component, target, window }) { assert.equal(component.name, 'world'); const el = target.querySelector('editor'); @@ -27,7 +28,8 @@ export default test({ const event = new window.Event('input'); el.textContent = 'everybody'; - await el.dispatchEvent(event); + el.dispatchEvent(event); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-text/_config.js b/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-text/_config.js index afecc5b3cd..494c338bfe 100644 --- a/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-text/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-text/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { ok, test } from '../../test'; export default test({ @@ -10,7 +11,7 @@ export default test({

hello world

`, - async test({ assert, component, target, window }) { + test({ assert, component, target, window }) { const el = target.querySelector('editor'); ok(el); assert.equal(el.textContent, 'world'); @@ -18,7 +19,8 @@ export default test({ const event = new window.Event('input'); el.textContent = 'everybody'; - await el.dispatchEvent(event); + el.dispatchEvent(event); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/binding-input-checkbox-indeterminate/_config.js b/packages/svelte/tests/runtime-legacy/samples/binding-input-checkbox-indeterminate/_config.js index 631423feaf..eba77322a1 100644 --- a/packages/svelte/tests/runtime-legacy/samples/binding-input-checkbox-indeterminate/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/binding-input-checkbox-indeterminate/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { ok, test } from '../../test'; export default test({ @@ -17,7 +18,7 @@ export default test({

indeterminate? true

`, - async test({ assert, component, target, window }) { + test({ assert, component, target, window }) { const input = target.querySelector('input'); ok(input); @@ -28,7 +29,8 @@ export default test({ input.checked = true; input.indeterminate = false; - await input.dispatchEvent(event); + input.dispatchEvent(event); + flushSync(); assert.equal(component.indeterminate, false); assert.equal(component.checked, true); diff --git a/packages/svelte/tests/runtime-legacy/samples/binding-select-in-yield/_config.js b/packages/svelte/tests/runtime-legacy/samples/binding-select-in-yield/_config.js index f7e5445072..b8f6a9a74a 100644 --- a/packages/svelte/tests/runtime-legacy/samples/binding-select-in-yield/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/binding-select-in-yield/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { ok, test } from '../../test'; export default test({ @@ -7,8 +8,9 @@ export default test({ return { letter: 'b' }; }, - async test({ assert, component, target, window }) { - await component.modal.toggle(); + test({ assert, component, target, window }) { + component.modal.toggle(); + flushSync(); assert.htmlEqual( target.innerHTML, @@ -28,7 +30,8 @@ export default test({ const change = new window.MouseEvent('change'); select.options[2].selected = true; - await select.dispatchEvent(change); + select.dispatchEvent(change); + flushSync(); assert.equal(component.letter, 'c'); assert.deepEqual( @@ -49,9 +52,9 @@ export default test({ ` ); - await component.modal.toggle(); - await component.modal.toggle(); - await Promise.resolve(); + component.modal.toggle(); + component.modal.toggle(); + flushSync(); select = target.querySelector('select'); ok(select); diff --git a/packages/svelte/tests/runtime-legacy/samples/bindings-coalesced/_config.js b/packages/svelte/tests/runtime-legacy/samples/bindings-coalesced/_config.js index 85e1faeb73..3bc5d845a1 100644 --- a/packages/svelte/tests/runtime-legacy/samples/bindings-coalesced/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/bindings-coalesced/_config.js @@ -1,7 +1,8 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ - async test({ assert, component }) { + test({ assert, component }) { const { foo, p } = component; /** @type {string[]} */ @@ -13,7 +14,8 @@ export default test({ } }); - await foo.double(); + foo.double(); + flushSync(); assert.deepEqual(values, ['6']); } diff --git a/packages/svelte/tests/runtime-legacy/samples/component-props-mutated/_config.js b/packages/svelte/tests/runtime-legacy/samples/component-props-mutated/_config.js index 91d0aaa0d3..4a5c102ba2 100644 --- a/packages/svelte/tests/runtime-legacy/samples/component-props-mutated/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/component-props-mutated/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; const data = { @@ -15,9 +16,10 @@ export default test({ html: '

hello

', - async test({ assert, component, target }) { + test({ assert, component, target }) { data.message = 'goodbye'; - await component.$set({ data }); + component.$set({ data }); + flushSync(); assert.htmlEqual(target.innerHTML, '

goodbye

'); } diff --git a/packages/svelte/tests/runtime-legacy/samples/component-slot-let-g/_config.js b/packages/svelte/tests/runtime-legacy/samples/component-slot-let-g/_config.js index db9afae1b0..f3f5e04be1 100644 --- a/packages/svelte/tests/runtime-legacy/samples/component-slot-let-g/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/component-slot-let-g/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -5,7 +6,7 @@ export default test({ 1 0 `, - async test({ assert, target, component, window }) { + test({ assert, target, component, window }) { component.x = 2; assert.htmlEqual( @@ -17,7 +18,8 @@ export default test({ ); const span = target.querySelector('span'); - await span?.dispatchEvent(new window.MouseEvent('click', { bubbles: true })); + span?.dispatchEvent(new window.MouseEvent('click', { bubbles: true })); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/destructured-props-2/_config.js b/packages/svelte/tests/runtime-legacy/samples/destructured-props-2/_config.js index 950ee4f1ff..0f3fcedce5 100644 --- a/packages/svelte/tests/runtime-legacy/samples/destructured-props-2/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/destructured-props-2/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -10,7 +11,7 @@ export default test({ async test({ component, assert, target }) { await component.update(); - await Promise.resolve(); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/destructured-props-3/_config.js b/packages/svelte/tests/runtime-legacy/samples/destructured-props-3/_config.js index 9ec2810e71..c78b84ec8c 100644 --- a/packages/svelte/tests/runtime-legacy/samples/destructured-props-3/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/destructured-props-3/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -8,7 +9,8 @@ export default test({ `, async test({ component, target, assert }) { await component.update(); - await Promise.resolve(); + flushSync(); + assert.htmlEqual( target.innerHTML, ` diff --git a/packages/svelte/tests/runtime-legacy/samples/destructured-props-5/_config.js b/packages/svelte/tests/runtime-legacy/samples/destructured-props-5/_config.js index 8f7a544bfe..103ce64d7c 100644 --- a/packages/svelte/tests/runtime-legacy/samples/destructured-props-5/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/destructured-props-5/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -10,7 +11,7 @@ export default test({ async test({ component, assert, target }) { await component.update(); - await Promise.resolve(); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/destructuring-assignment-array/_config.js b/packages/svelte/tests/runtime-legacy/samples/destructuring-assignment-array/_config.js index 2df8753114..9c09581097 100644 --- a/packages/svelte/tests/runtime-legacy/samples/destructuring-assignment-array/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/destructuring-assignment-array/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -10,9 +11,9 @@ export default test({ `, - async test({ assert, component, target }) { - await component.swap(0, 1); - await Promise.resolve(); + test({ assert, component, target }) { + component.swap(0, 1); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/key-block-expression-2/_config.js b/packages/svelte/tests/runtime-legacy/samples/key-block-expression-2/_config.js index a661ec2596..99fa84e2a9 100644 --- a/packages/svelte/tests/runtime-legacy/samples/key-block-expression-2/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/key-block-expression-2/_config.js @@ -1,19 +1,26 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ html: '
3
', - async test({ assert, component, target }) { + test({ assert, component, target }) { const div = target.querySelector('div'); - await component.mutate(); + component.mutate(); + flushSync(); + assert.htmlEqual(target.innerHTML, '
5
'); assert.strictEqual(div, target.querySelector('div')); - await component.reassign(); + component.reassign(); + flushSync(); + assert.htmlEqual(target.innerHTML, '
7
'); assert.strictEqual(div, target.querySelector('div')); - await component.changeKey(); + component.changeKey(); + flushSync(); + assert.htmlEqual(target.innerHTML, '
7
'); assert.notStrictEqual(div, target.querySelector('div')); } diff --git a/packages/svelte/tests/runtime-legacy/samples/prop-const/_config.js b/packages/svelte/tests/runtime-legacy/samples/prop-const/_config.js index 040b911cc6..804ee53342 100644 --- a/packages/svelte/tests/runtime-legacy/samples/prop-const/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/prop-const/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -10,11 +11,12 @@ export default test({

b: 2

`, - async test({ assert, component, target }) { - await component.$set({ + test({ assert, component, target }) { + component.$set({ a: 5, b: 6 }); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/props-reactive-b/_config.js b/packages/svelte/tests/runtime-legacy/samples/props-reactive-b/_config.js index b92d81bd53..91133f0bf4 100644 --- a/packages/svelte/tests/runtime-legacy/samples/props-reactive-b/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/props-reactive-b/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -11,8 +12,9 @@ export default test({

c: 3

`, - async test({ assert, component, target }) { - await component.$set({ a: 4 }); + test({ assert, component, target }) { + component.$set({ a: 4 }); + flushSync(); assert.htmlEqual( target.innerHTML, @@ -23,7 +25,8 @@ export default test({ ` ); - await component.$set({ b: 5 }); + component.$set({ b: 5 }); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/reactive-assignment-in-complex-declaration-with-store-3/_config.js b/packages/svelte/tests/runtime-legacy/samples/reactive-assignment-in-complex-declaration-with-store-3/_config.js index 2325d17cd5..1a67e46b38 100644 --- a/packages/svelte/tests/runtime-legacy/samples/reactive-assignment-in-complex-declaration-with-store-3/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/reactive-assignment-in-complex-declaration-with-store-3/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; import { store } from './store.js'; @@ -6,10 +7,9 @@ export default test({ before_test() { store.reset(); }, - async test({ assert, target }) { + test({ assert, target }) { store.set(42); - - await Promise.resolve(); + flushSync(); assert.htmlEqual(target.innerHTML, '

42

'); diff --git a/packages/svelte/tests/runtime-legacy/samples/reactive-value-dependency-not-referenced/_config.js b/packages/svelte/tests/runtime-legacy/samples/reactive-value-dependency-not-referenced/_config.js index f2f7fe92b1..3b31ee766e 100644 --- a/packages/svelte/tests/runtime-legacy/samples/reactive-value-dependency-not-referenced/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/reactive-value-dependency-not-referenced/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -6,29 +7,35 @@ export default test({

42

`, - async test({ assert, component, target }) { - await component.updateStore(undefined); - await Promise.resolve(); + test({ assert, component, target }) { + component.updateStore(undefined); + flushSync(); + assert.htmlEqual(target.innerHTML, '

42

'); - await component.updateStore(33); - await Promise.resolve(); + component.updateStore(33); + flushSync(); + assert.htmlEqual(target.innerHTML, '

33

42

'); - await component.updateStore(undefined); - await Promise.resolve(); + component.updateStore(undefined); + flushSync(); + assert.htmlEqual(target.innerHTML, '

42

'); - await component.updateVar(undefined); - await Promise.resolve(); + component.updateVar(undefined); + flushSync(); + assert.htmlEqual(target.innerHTML, '

'); - await component.updateVar(33); - await Promise.resolve(); + component.updateVar(33); + flushSync(); + assert.htmlEqual(target.innerHTML, '

33

'); - await component.updateVar(undefined); - await Promise.resolve(); + component.updateVar(undefined); + flushSync(); + assert.htmlEqual(target.innerHTML, '

'); } }); diff --git a/packages/svelte/tests/runtime-legacy/samples/reactive-value-function/_config.js b/packages/svelte/tests/runtime-legacy/samples/reactive-value-function/_config.js index cbcb19d95e..5317ab496f 100644 --- a/packages/svelte/tests/runtime-legacy/samples/reactive-value-function/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/reactive-value-function/_config.js @@ -1,10 +1,12 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ html: '1-2', - async test({ assert, component, target }) { - await component.update(); + test({ assert, component, target }) { + component.update(); + flushSync(); assert.htmlEqual(target.innerHTML, '3-4'); } diff --git a/packages/svelte/tests/runtime-legacy/samples/reactive-values-text-node/_config.js b/packages/svelte/tests/runtime-legacy/samples/reactive-values-text-node/_config.js index e05c8c80dd..e97a046f68 100644 --- a/packages/svelte/tests/runtime-legacy/samples/reactive-values-text-node/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/reactive-values-text-node/_config.js @@ -1,5 +1,6 @@ import { test } from '../../test'; import { create_deferred } from '../../../helpers'; +import { flushSync } from 'svelte'; /** @type {ReturnType} */ let deferred; @@ -17,6 +18,8 @@ export default test({ async test({ assert, target }) { await deferred.promise; + flushSync(); + assert.htmlEqual( target.innerHTML, ` diff --git a/packages/svelte/tests/runtime-legacy/samples/spread-own-props/_config.js b/packages/svelte/tests/runtime-legacy/samples/spread-own-props/_config.js index 708e3615f1..7486055440 100644 --- a/packages/svelte/tests/runtime-legacy/samples/spread-own-props/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/spread-own-props/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -17,13 +18,14 @@ export default test({

quux: core

`, - async test({ assert, component, target }) { - await component.$set({ + test({ assert, component, target }) { + component.$set({ foo: 'wut', baz: 40 + 3, qux: `this is a ${'rather boring'} string`, quux: 'heart' }); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/store-auto-subscribe-in-reactive-declaration-2/_config.js b/packages/svelte/tests/runtime-legacy/samples/store-auto-subscribe-in-reactive-declaration-2/_config.js index 8e0886c668..d380150e55 100644 --- a/packages/svelte/tests/runtime-legacy/samples/store-auto-subscribe-in-reactive-declaration-2/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/store-auto-subscribe-in-reactive-declaration-2/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -6,10 +7,9 @@ export default test({
Hello World
`, - async test({ assert, component, target }) { - await component.update_value('Hi Svelte'); - await Promise.resolve(); - await Promise.resolve(); + test({ assert, component, target }) { + component.update_value('Hi Svelte'); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-legacy/samples/store-increment-updates-reactive/_config.js b/packages/svelte/tests/runtime-legacy/samples/store-increment-updates-reactive/_config.js index 1c81f7c4e8..89ff695d9d 100644 --- a/packages/svelte/tests/runtime-legacy/samples/store-increment-updates-reactive/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/store-increment-updates-reactive/_config.js @@ -1,10 +1,13 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ html: '0', - async test({ assert, component, target }) { - await component.increment(); + test({ assert, component, target }) { + component.increment(); + flushSync(); + assert.htmlEqual(target.innerHTML, '1'); } }); diff --git a/packages/svelte/tests/runtime-legacy/samples/store-unreferenced/_config.js b/packages/svelte/tests/runtime-legacy/samples/store-unreferenced/_config.js index 808ed899d3..7096f5d1fe 100644 --- a/packages/svelte/tests/runtime-legacy/samples/store-unreferenced/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/store-unreferenced/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; import { count } from './store.js'; @@ -8,8 +9,9 @@ export default test({ count.set(0); }, - async test({ assert, component, target }) { - await component.increment(); + test({ assert, component, target }) { + component.increment(); + flushSync(); assert.htmlEqual(target.innerHTML, '

count: 1

'); } diff --git a/packages/svelte/tests/runtime-legacy/samples/window-event-custom/_config.js b/packages/svelte/tests/runtime-legacy/samples/window-event-custom/_config.js index 32b1c65154..f6b7a8af42 100644 --- a/packages/svelte/tests/runtime-legacy/samples/window-event-custom/_config.js +++ b/packages/svelte/tests/runtime-legacy/samples/window-event-custom/_config.js @@ -1,14 +1,16 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ html: '

escaped: false

', - async test({ assert, target, window }) { + test({ assert, target, window }) { const event = new window.KeyboardEvent('keydown', { key: 'Escape' }); - await window.dispatchEvent(event); + window.dispatchEvent(event); + flushSync(); assert.htmlEqual( target.innerHTML, diff --git a/packages/svelte/tests/runtime-runes/samples/derived-unowned-2/_config.js b/packages/svelte/tests/runtime-runes/samples/derived-unowned-2/_config.js index 3604000543..3ca98bb0c6 100644 --- a/packages/svelte/tests/runtime-runes/samples/derived-unowned-2/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/derived-unowned-2/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -7,7 +8,7 @@ export default test({ async test({ assert, target }) { await Promise.resolve(); - await Promise.resolve(); + flushSync(); assert.htmlEqual( target.innerHTML, '
d2: 3,4,5
d3: 3,4,5
d4: 3,4,5
' diff --git a/packages/svelte/tests/runtime-runes/samples/derived-unowned-5/_config.js b/packages/svelte/tests/runtime-runes/samples/derived-unowned-5/_config.js index 20c3cc112e..5f38394d06 100644 --- a/packages/svelte/tests/runtime-runes/samples/derived-unowned-5/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/derived-unowned-5/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -5,7 +6,7 @@ export default test({ // The test has a bunch of queueMicrotasks await Promise.resolve(); await Promise.resolve(); - await Promise.resolve(); + flushSync(); assert.htmlEqual(target.innerHTML, `
Zeeba Neighba
`); } diff --git a/packages/svelte/tests/runtime-runes/samples/runes-from-func/_config.js b/packages/svelte/tests/runtime-runes/samples/runes-from-func/_config.js index 7d3dd9993f..5ed7579c62 100644 --- a/packages/svelte/tests/runtime-runes/samples/runes-from-func/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/runes-from-func/_config.js @@ -1,3 +1,4 @@ +import { flushSync } from 'svelte'; import { test } from '../../test'; export default test({ @@ -5,7 +6,7 @@ export default test({ async test({ assert, target }) { await Promise.resolve(); - await Promise.resolve(); + flushSync(); assert.htmlEqual(target.innerHTML, `1`); } });