Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Feb 14, 2025
1 parent 662ee1e commit bbb5db1
Show file tree
Hide file tree
Showing 36 changed files with 128 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,57 @@ import { test } from '../../test';

export default test({
test({ assert, target, variant }) {
const ps = [...target.querySelectorAll('p')].map((p) => p.innerHTML);
const unique = new Set(ps);
assert.equal(ps.length, unique.size);

if (variant === 'hydrate') {
const start = ps.map((p) => p.substring(0, 1));
assert.deepEqual(start, ['s', 's', 's', 's']);
if (variant === 'dom') {
assert.htmlEqual(
target.innerHTML,
`
<button>toggle</button>
<h1>c1</h1>
<p>c2</p>
<p>c3</p>
<p>c4</p>
`
);
} else {
assert.htmlEqual(
target.innerHTML,
`
<button>toggle</button>
<h1>s1</h1>
<p>s2</p>
<p>s3</p>
<p>s4</p>
`
);
}

let button = target.querySelector('button');
flushSync(() => button?.click());

const ps_after = [...target.querySelectorAll('p')].map((p) => p.innerHTML);
const unique_after = new Set(ps_after);
assert.equal(ps_after.length, unique_after.size);

if (variant === 'hydrate') {
const start = ps_after.map((p) => p.substring(0, 1));
assert.deepEqual(start, ['s', 's', 's', 's', 'c']);
if (variant === 'dom') {
assert.htmlEqual(
target.innerHTML,
`
<button>toggle</button>
<h1>c1</h1>
<p>c2</p>
<p>c3</p>
<p>c4</p>
<p>c5</p>
`
);
} else {
assert.htmlEqual(
target.innerHTML,
`
<button>toggle</button>
<h1>s1</h1>
<p>s2</p>
<p>s3</p>
<p>s4</p>
<p>c1</p>
`
);
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<button onclick={() => show = !show}>toggle</button>

<p>{id}</p>
<h1>{id}</h1>

<Child />
<Child />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function increment(_, counter) {
var root = $.template(`<button> </button> <!> `, 1);

export default function Await_block_scope($$anchor) {
const $$cleanup = $.setup();
let counter = $.proxy({ count: 0 });
const promise = $.derived(() => Promise.resolve(counter));
var fragment = root();
Expand All @@ -31,6 +32,7 @@ export default function Await_block_scope($$anchor) {
});

$.append($$anchor, fragment);
$$cleanup();
}

$.delegate(['click']);
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as $ from 'svelte/internal/server';

export default function Await_block_scope($$payload) {
const $$cleanup = $.setup($$payload);
let counter = { count: 0 };
const promise = Promise.resolve(counter);

Expand All @@ -11,4 +12,5 @@ export default function Await_block_scope($$payload) {
$$payload.out += `<button>clicks: ${$.escape(counter.count)}</button> <!---->`;
$.await(promise, () => {}, (counter) => {}, () => {});
$$payload.out += `<!----> ${$.escape(counter.count)}`;
$$cleanup($$payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const snippet = ($$anchor) => {
var root = $.template(`<!> `, 1);

export default function Bind_component_snippet($$anchor) {
const $$cleanup = $.setup();
let value = $.state('');
const _snippet = snippet;
var fragment = root();
Expand All @@ -31,4 +32,5 @@ export default function Bind_component_snippet($$anchor) {

$.template_effect(() => $.set_text(text_1, ` value: ${$.get(value) ?? ''}`));
$.append($$anchor, fragment);
$$cleanup();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function snippet($$payload) {
}

export default function Bind_component_snippet($$payload) {
const $$cleanup = $.setup($$payload);
let value = '';
const _snippet = snippet;
let $$settled = true;
Expand All @@ -32,4 +33,5 @@ export default function Bind_component_snippet($$payload) {
} while (!$$settled);

$.assign_payload($$payload, $$inner_payload);
$$cleanup($$payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

export default function Bind_this($$anchor) {
const $$cleanup = $.setup();

$.bind_this(Foo($$anchor, { $$legacy: true }), ($$value) => foo = $$value, () => foo);
$$cleanup();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import * as $ from 'svelte/internal/server';

export default function Bind_this($$payload) {
const $$cleanup = $.setup($$payload);

Foo($$payload, {});
$$cleanup($$payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'svelte/internal/disclose-version';
import * as $ from 'svelte/internal/client';

export default function Class_state_field_constructor_assignment($$anchor, $$props) {
const $$cleanup = $.setup();

$.push($$props, true);

class Foo {
Expand All @@ -24,4 +26,5 @@ export default function Class_state_field_constructor_assignment($$anchor, $$pro
}

$.pop();
$$cleanup();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as $ from 'svelte/internal/server';

export default function Class_state_field_constructor_assignment($$payload, $$props) {
const $$cleanup = $.setup($$payload);

$.push();

class Foo {
Expand All @@ -14,4 +16,5 @@ export default function Class_state_field_constructor_assignment($$payload, $$pr
}

$.pop();
$$cleanup($$payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as $ from 'svelte/internal/client';
var root = $.template(`<div></div> <svg></svg> <custom-element></custom-element> <div></div> <svg></svg> <custom-element></custom-element>`, 3);

export default function Main($$anchor) {
const $$cleanup = $.setup();
// needs to be a snapshot test because jsdom does auto-correct the attribute casing
let x = 'test';
let y = () => 'test';
Expand Down Expand Up @@ -31,4 +32,5 @@ export default function Main($$anchor) {
);

$.append($$anchor, fragment);
$$cleanup();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as $ from 'svelte/internal/server';

export default function Main($$payload) {
const $$cleanup = $.setup($$payload);
// needs to be a snapshot test because jsdom does auto-correct the attribute casing
let x = 'test';
let y = () => 'test';

$$payload.out += `<div${$.attr('foobar', x)}></div> <svg${$.attr('viewBox', x)}></svg> <custom-element${$.attr('foobar', x)}></custom-element> <div${$.attr('foobar', y())}></div> <svg${$.attr('viewBox', y())}></svg> <custom-element${$.attr('foobar', y())}></custom-element>`;
$$cleanup($$payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

export default function Each_string_template($$anchor) {
const $$cleanup = $.setup();
var fragment = $.comment();
var node = $.first_child(fragment);

Expand All @@ -16,4 +17,5 @@ export default function Each_string_template($$anchor) {
});

$.append($$anchor, fragment);
$$cleanup();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as $ from 'svelte/internal/server';

export default function Each_string_template($$payload) {
const $$cleanup = $.setup($$payload);
const each_array = $.ensure_array_like(['foo', 'bar', 'baz']);

$$payload.out += `<!--[-->`;
Expand All @@ -12,4 +13,5 @@ export default function Each_string_template($$payload) {
}

$$payload.out += `<!--]-->`;
$$cleanup($$payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'svelte/internal/disclose-version';
import * as $ from 'svelte/internal/client';

export default function Function_prop_no_getter($$anchor) {
const $$cleanup = $.setup();
let count = $.state(0);

function onmouseup() {
Expand All @@ -24,4 +25,6 @@ export default function Function_prop_no_getter($$anchor) {
},
$$slots: { default: true }
});

$$cleanup();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as $ from 'svelte/internal/server';

export default function Function_prop_no_getter($$payload) {
const $$cleanup = $.setup($$payload);
let count = 0;

function onmouseup() {
Expand All @@ -18,4 +19,6 @@ export default function Function_prop_no_getter($$payload) {
},
$$slots: { default: true }
});

$$cleanup($$payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import * as $ from 'svelte/internal/client';
var root = $.template(`<h1>hello world</h1>`);

export default function Hello_world($$anchor) {
const $$cleanup = $.setup();
var h1 = root();

$.append($$anchor, h1);
$$cleanup();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import * as $ from 'svelte/internal/server';

export default function Hello_world($$payload) {
const $$cleanup = $.setup($$payload);

$$payload.out += `<h1>hello world</h1>`;
$$cleanup($$payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import * as $ from 'svelte/internal/client';
var root = $.template(`<h1>hello world</h1>`);

function Hmr($$anchor) {
const $$cleanup = $.setup();
var h1 = root();

$.append($$anchor, h1);
$$cleanup();
}

if (import.meta.hot) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import * as $ from 'svelte/internal/server';

export default function Hmr($$payload) {
const $$cleanup = $.setup($$payload);

$$payload.out += `<h1>hello world</h1>`;
$$cleanup($$payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ import * as $ from 'svelte/internal/client';
import { random } from './module.svelte';

export default function Imports_in_modules($$anchor) {

const $$cleanup = $.setup();

$$cleanup();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import * as $ from 'svelte/internal/server';
import { random } from './module.svelte';

export default function Imports_in_modules($$payload) {

const $$cleanup = $.setup($$payload);

$$cleanup($$payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var on_click = (_, count) => $.update(count);
var root = $.template(`<h1></h1> <b></b> <button> </button> <h1></h1>`, 1);

export default function Nullish_coallescence_omittance($$anchor) {
const $$cleanup = $.setup();
let name = 'world';
let count = $.state(0);
var fragment = root();
Expand All @@ -29,6 +30,7 @@ export default function Nullish_coallescence_omittance($$anchor) {
h1_1.textContent = `Hello, ${name ?? 'earth' ?? ''}`;
$.template_effect(() => $.set_text(text, `Count is ${$.get(count) ?? ''}`));
$.append($$anchor, fragment);
$$cleanup();
}

$.delegate(['click']);
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as $ from 'svelte/internal/server';

export default function Nullish_coallescence_omittance($$payload) {
const $$cleanup = $.setup($$payload);
let name = 'world';
let count = 0;

$$payload.out += `<h1>Hello, ${$.escape(name)}!</h1> <b>${$.escape(1 ?? 'stuff')}${$.escape(2 ?? 'more stuff')}${$.escape(3 ?? 'even more stuff')}</b> <button>Count is ${$.escape(count)}</button> <h1>Hello, ${$.escape(name ?? 'earth' ?? null)}</h1>`;
$$cleanup($$payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'svelte/internal/disclose-version';
import * as $ from 'svelte/internal/client';

export default function Props_identifier($$anchor, $$props) {
const $$cleanup = $.setup();

$.push($$props, true);

let props = $.rest_props($$props, ['$$slots', '$$events', '$$legacy']);
Expand All @@ -14,4 +16,5 @@ export default function Props_identifier($$anchor, $$props) {
props[a] = true;
props;
$.pop();
$$cleanup();
}
Loading

0 comments on commit bbb5db1

Please sign in to comment.