Skip to content

replace skip_if_ssr and skip_if_hydrate with modes #10956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/svelte/tests/runtime-browser/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ function normalize_children(node) {
* @template Props
* @param {{
* skip?: boolean;
* skip_if_ssr?: boolean | 'permanent';
* skip_if_hydrate?: boolean | 'permanent';
* solo?: boolean;
* mode?: Array<'server' | 'client' | 'hydrate'>;
* skip_mode?: Array<'server' | 'client' | 'hydrate'>;
* html?: string;
* ssrHtml?: string;
* props?: Props;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test } from '../../assert';

export default test({
skip_if_ssr: 'permanent',
skip_if_hydrate: 'permanent',
mode: ['client'],

props: {
tag: /** @type {string | null} */ ('my-custom-element'),
name: /** @type {string | null | undefined} */ (null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ export default test({
// Test that @html does not execute scripts when instantiated in the client.
// Needs to be in this test suite because JSDOM does not quite get this right.
html: `<div></div><script>document.body.innerHTML = 'this should not be executed'</script>`,
skip_if_ssr: 'permanent',
skip_if_hydrate: 'permanent'
mode: ['client']
});
3 changes: 2 additions & 1 deletion packages/svelte/tests/runtime-browser/test-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export async function run_ssr_test(
}

const { run } = suite<ReturnType<typeof import('./assert').test>>(async (config, test_dir) => {
if (config.skip_if_ssr) return;
if (config.mode && !config.mode.includes('server')) return;
if (config.skip_mode?.includes('server')) return;
await run_ssr_test(config, test_dir);
});

Expand Down
6 changes: 5 additions & 1 deletion packages/svelte/tests/runtime-browser/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ const { run: run_browser_tests } = suite_with_variants<
>(
['dom', 'hydrate'],
(variant, config) => {
if (variant === 'hydrate' && config.skip_if_hydrate) return true;
if (variant === 'hydrate') {
if (config.mode && !config.mode.includes('hydrate')) return 'no-test';
if (config.skip_mode?.includes('hydrate')) return true;
}

return false;
},
() => {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ok, test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // unnecessary to test this in ssr mode
mode: ['client', 'hydrate'],

html: '<button>10</button>',

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: true,
skip_mode: ['server'],

get props() {
return { value: 'hello!' };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: true,
skip_mode: ['server'],

get props() {
return { value: 'hello!' };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent',
skip_if_hydrate: 'permanent',
mode: ['client'],
html: `
<my-custom-element>Hello World!</my-custom-element>
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export default test({
<text wordWrap="true"></text>
</page>
`,
skip_if_hydrate: true,

compileOptions: {
namespace: 'foreign'
},

test({ assert, target }) {
// @ts-ignore
const attr = (/** @type {string} */ sel) => target.querySelector(sel).attributes[0].name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default test({
<button textWrap="true" text="button">
</page>
`,
skip_if_hydrate: true,

test({ assert, target }) {
// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { test } from '../../test';
export default test({
skip: true, // TODO: needs fixing

skip_if_ssr: true,
skip_if_hydrate: true,
html: `
<my-custom-inheritance-element>Hello World!</my-custom-inheritance-element>
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { test } from '../../test';
export default test({
skip: true, // TODO: needs fixing

skip_if_ssr: true,

html: `
<span>3</span>
<span>2</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: true,
skip_mode: ['server'],

get props() {
return { value: 'hello!' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { flushSync } from 'svelte';
let tasks = [];

export default test({
skip_if_ssr: 'permanent', // unnecessary to test this in ssr mode
mode: ['client', 'hydrate'], // unnecessary to test this in ssr mode

get props() {
tasks = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ok, test } from '../../test';

export default test({
skip_if_ssr: 'permanent',
mode: ['client', 'hydrate'],

html: `
<p>selected: b</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ok, test } from '../../test';

export default test({
skip_if_ssr: 'permanent',
mode: ['client', 'hydrate'],

html: `
<p>selected: a</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ok, test } from '../../test';

export default test({
skip_if_ssr: 'permanent',
mode: ['client', 'hydrate'],

html: `
<p>selected: a</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ok, test } from '../../test';

// test select binding behavior when a selected option is removed
export default test({
skip_if_ssr: 'permanent',
mode: ['client', 'hydrate'],

html: `<p>selected: a</p><select><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>`,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ok, test } from '../../test';

export default test({
skip_if_ssr: 'permanent',
mode: ['client', 'hydrate'],
html: `
<input type="checkbox">
<input type="checkbox">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // there's no class instance to retrieve in SSR mode
mode: ['client', 'hydrate'], // there's no class instance to retrieve in SSR mode

html: `
<div>foo</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // there's no class instance to retrieve in SSR mode
mode: ['client', 'hydrate'], // there's no class instance to retrieve in SSR mode
html: `
<div>foo</div>
<div>first has foo: true</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // there's no class instance to retrieve in SSR mode
mode: ['client', 'hydrate'], // there's no class instance to retrieve in SSR mode

html: `
<div>foo</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // there's no class instance to retrieve in SSR mode
mode: ['client', 'hydrate'], // there's no class instance to retrieve in SSR mode

html: `
<div>foo</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // there's no class instance to retrieve in SSR mode
mode: ['client', 'hydrate'], // there's no class instance to retrieve in SSR mode
get props() {
return { visible: true };
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // there's no class instance to retrieve in SSR mode
mode: ['client', 'hydrate'], // there's no class instance to retrieve in SSR mode

html: '<div>has div: true</div>'
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // doesn't work in SSR
mode: ['client', 'hydrate'], // doesn't work in SSR
html: '<div>object</div>'
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ok, test } from '../../test';
import { flushSync } from 'svelte';

export default test({
skip_if_ssr: 'permanent', // relies on onMount firing, which does not happen in SSR mode
mode: ['client', 'hydrate'], // relies on onMount firing, which does not happen in SSR mode

get props() {
return { count: 3 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ok, test } from '../../test';
import { flushSync } from 'svelte';

export default test({
skip_if_ssr: 'permanent', // relies on onMount firing, which does not happen in SSR mode
mode: ['client', 'hydrate'], // relies on onMount firing, which does not happen in SSR mode

get props() {
return { count: 3 };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent',
skip_if_hydrate: 'permanent',
mode: ['client'],

compileOptions: {
dev: true
},

error: 'this={...} of <svelte:component> should specify a Svelte component.'
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent',
skip_if_hydrate: 'permanent',
mode: ['client'],

get props() {
return { selected: false };
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { test } from '../../test';

export default test({
skip_if_ssr: true,
skip_mode: ['server'],

html: `
<div><div>Value in child component: </div></div>
`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent',
mode: ['client', 'hydrate'],

html: `
<p>Reactive: foo</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let originalSpanGetBoundingClientRect;
let originalParagraphGetBoundingClientRect;

export default test({
skip_if_ssr: 'permanent', // no animations in SSR
mode: ['client', 'hydrate'], // no animations in SSR
get props() {
return {
things: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { test } from '../../test';

export default test({
skip_if_hydrate: 'permanent', // SSR errors on render already
mode: ['client', 'server'], // SSR errors on render already

compileOptions: {
dev: true
},

get props() {
return { tag: 123 };
},

error: '<svelte:element> expects "this" attribute to be a string.'
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent',
mode: ['client', 'hydrate'],
html: '<div>object</div>'
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // uses oncreate
mode: ['client', 'hydrate'], // uses oncreate

html: '<div><p>true</p>\n<p>true</p></div>'
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // uses oncreate
mode: ['client', 'hydrate'], // uses oncreate

html: '<div><p>true</p></div>',

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_hydrate: 'permanent', // output is correct, but test suite chokes on the extra ssr comment which is harmless
mode: ['client', 'server'], // output is correct, but test suite chokes on the extra ssr comment which is harmless
withoutNormalizeHtml: true,
html: get_html(false),
ssrHtml: get_html(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // a separate SSR test exists
mode: ['client', 'hydrate'], // a separate SSR test exists

compileOptions: {
preserveComments: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '../../test';

export default test({
skip_if_ssr: 'permanent', // uses oncreate
mode: ['client', 'hydrate'], // uses oncreate

html: '<p>2</p>'
});
Loading