update some tests

This commit is contained in:
Rich Harris
2019-01-30 10:21:55 -05:00
parent c00af6dad0
commit da540ef15f
23 changed files with 255 additions and 251 deletions

View File

@@ -1,11 +1,13 @@
<h1>{letter}</h1> <script context="module">
export function preload() {
return this.fetch('b.json').then(r => r.json()).then(letter => {
return { letter };
});
}
</script>
<script> <script>
export default { export let letter;
preload() { </script>
return this.fetch('b.json').then(r => r.json()).then(letter => {
return { letter }; <h1>{letter}</h1>
});
}
};
</script>

View File

@@ -1,19 +1,17 @@
<button class='del' on:click='del()'>delete</button>
<script> <script>
export default { import { onMount } from 'svelte';
oncreate() {
window.deleted = null;
},
methods: { onMount(() => {
del() { window.deleted = null;
fetch(`delete-test/42.json`, { method: 'DELETE' }) });
.then(r => r.json())
.then(data => { function del() {
window.deleted = data; fetch(`delete-test/42.json`, { method: 'DELETE' })
}); .then(r => r.json())
} .then(data => {
} window.deleted = data;
}; });
</script> }
</script>
<button class="del" on:click={del}>delete</button>

View File

@@ -1,9 +1,7 @@
$& <script context="module">
export function preload() {
return '$&';
}
</script>
<script> $&
export default {
preload() {
return '$&';
}
};
</script>

View File

@@ -1,11 +1,13 @@
<h1>{message}</h1> <script context="module">
export function preload({ query }) {
return this.fetch(`credentials/test.json`, {
credentials: query.creds
}).then(r => r.json());
}
</script>
<script> <script>
export default { export let message;
preload({ query }) { </script>
return this.fetch(`credentials/test.json`, {
credentials: query.creds <h1>{message}</h1>
}).then(r => r.json());
}
};
</script>

View File

@@ -1,11 +1,13 @@
<svelte:component this={Title}/>
<script> <script>
export default { import { onMount } from 'svelte';
oncreate() {
import('./_components/Title.html').then(({ default: Title }) => { export let Title;
this.set({ Title });
}); onMount(() => {
} import('./_components/Title.html').then(mod => {
}; Title = mod.default;
</script> });
});
</script>
<svelte:component this={Title}/>

View File

@@ -1,11 +1,14 @@
<h1>{slug} {JSON.stringify(query)}</h1> <script context="module">
export function preload({ params }) {
return {
slug: params.slug
};
}
</script>
<script> <script>
export default { export let slug;
preload({ params }) { export let query;
return { </script>
slug: params.slug
}; <h1>{slug} {JSON.stringify(query)}</h1>
}
};
</script>

View File

@@ -1,11 +1,13 @@
<h1>{phrase}</h1> <script context="module">
export function preload() {
return this.fetch('fünke.json').then(r => r.json()).then(phrase => {
return { phrase };
});
}
</script>
<script> <script>
export default { export let phrase;
preload() { </script>
return this.fetch('fünke.json').then(r => r.json()).then(phrase => {
return { phrase }; <h1>{phrase}</h1>
});
}
};
</script>

View File

@@ -1,19 +1,21 @@
<h1>{post.title}</h1> <script context="module">
export function preload({ params }) {
const { slug } = params;
return this.fetch(`blog/${slug}.json`).then(r => {
return r.json().then(data => {
if (r.status !== 200) {
this.error(r.status, data);
}
return data;
});
});
}
</script>
<script> <script>
export default { export let post;
preload({ params }) { </script>
const { slug } = params;
return this.fetch(`blog/${slug}.json`).then(r => { <h1>{post.title}</h1>
return r.json().then(data => {
if (r.status !== 200) {
this.error(r.status, data);
}
return data;
});
});
}
};
</script>

View File

@@ -1,7 +1,5 @@
<script> <script context="module">
export default { export function preload() {
preload() { this.error(420, 'Enhance your calm');
this.error(420, 'Enhance your calm'); }
}
};
</script> </script>

View File

@@ -1,7 +1,5 @@
<script> <script context="module">
export default { export function preload() {
preload() { throw new Error('nope');
throw new Error('nope'); }
}
};
</script> </script>

View File

@@ -1,11 +1,13 @@
<h1>{post.title}</h1> <script context="module">
export function preload({ params }) {
return this.fetch(`blog/${params.slug}.json`).then(r => r.json()).then(post => {
return { post };
});
}
</script>
<script> <script>
export default { export let post;
preload({ params }) { </script>
return this.fetch(`blog/${params.slug}.json`).then(r => r.json()).then(post => {
return { post }; <h1>{post.title}</h1>
});
}
};
</script>

View File

@@ -1,15 +1,17 @@
<script context="module">
export function preload() {
return this.fetch('blog.json').then(r => r.json()).then(posts => {
return { posts };
});
}
</script>
<script>
export let posts;
</script>
<h1>blog</h1> <h1>blog</h1>
{#each posts as post} {#each posts as post}
<p><a href="blog/{post.slug}">{post.title}</a></p> <p><a href="blog/{post.slug}">{post.title}</a></p>
{/each} {/each}
<script>
export default {
preload() {
return this.fetch('blog.json').then(r => r.json()).then(posts => {
return { posts };
});
}
};
</script>

View File

@@ -1,11 +1,13 @@
<h1>{letter}</h1> <script context="module">
export function preload() {
return this.fetch('b.json').then(r => r.json()).then(letter => {
return { letter };
});
}
</script>
<script> <script>
export default { export let letter;
preload() { </script>
return this.fetch('b.json').then(r => r.json()).then(letter => {
return { letter }; <h1>{letter}</h1>
});
}
};
</script>

View File

@@ -1,20 +1,18 @@
<span>z: {segment} {count}</span> <script context="module">
<a href="foo/bar/qux">click me</a>
<script>
import counts from '../_counts.js'; import counts from '../_counts.js';
export default { export function preload() {
preload() { return {
return { count: counts.z += 1
count: counts.z += 1 };
}; }
}, </script>
oncreate() { <script>
this.set({ export let params;
segment: this.get().params.z export let count;
}); export let segment = params.z;
} </script>
};
</script> <span>z: {segment} {count}</span>
<a href="foo/bar/qux">click me</a>

View File

@@ -1,22 +1,21 @@
<script context="module">
import counts from '../_counts.js';
export function preload() {
return {
count: counts.y += 1
};
}
</script>
<script>
export let params;
export let count;
export let child;
export let segment = params.y;
</script>
<span>y: {segment} {count}</span> <span>y: {segment} {count}</span>
<svelte:component this={child.component} {...child.props}/> <svelte:component this={child.component} {...child.props}/>
<span>child segment: {child.segment}</span> <span>child segment: {child.segment}</span>
<script>
import counts from '../_counts.js';
export default {
preload() {
return {
count: counts.y += 1
};
},
oncreate() {
this.set({
segment: this.get().params.y
});
}
};
</script>

View File

@@ -1,15 +1,19 @@
<script context="module">
export function preload() {
return {
rootPreloadFunctionRan: true
};
}
</script>
<script>
export let preloading;
export let child;
export let rootPreloadFunctionRan;
</script>
{#if preloading} {#if preloading}
<progress class='preloading-progress' value=0.5/> <progress class='preloading-progress' value=0.5/>
{/if} {/if}
<svelte:component this={child.component} {rootPreloadFunctionRan} {...child.props}/> <svelte:component this={child.component} {rootPreloadFunctionRan} {...child.props}/>
<script>
export default {
preload() {
return {
rootPreloadFunctionRan: true
};
}
};
</script>

View File

@@ -1,17 +1,19 @@
<h1>{foo.bar()}</h1> <script context="module">
export function preload() {
class Foo {
bar() {
return 42;
}
}
return {
foo: new Foo()
};
}
</script>
<script> <script>
export default { export let foo;
preload() { </script>
class Foo {
bar() {
return 42;
}
}
return { <h1>{foo.bar()}</h1>
foo: new Foo()
};
}
};
</script>

View File

@@ -1,11 +1,13 @@
<h1>{set.has('x')}</h1> <script context="module">
export function preload() {
return {
set: new Set(['x'])
};
}
</script>
<script> <script>
export default { export let set;
preload() { </script>
return {
set: new Set(['x']) <h1>{set.has('x')}</h1>
};
}
};
</script>

View File

@@ -1,15 +1,13 @@
<h1>This page should never render</h1> <script context="module">
export function preload() {
return new Promise(fulfil => {
if (typeof window !== 'undefined') {
window.fulfil = fulfil;
} else {
fulfil({});
}
});
}
</script>
<script> <h1>This page should never render</h1>
export default {
preload() {
return new Promise(fulfil => {
if (typeof window !== 'undefined') {
window.fulfil = fulfil;
} else {
fulfil({});
}
});
}
};
</script>

View File

@@ -1,9 +1,7 @@
<h1>unredirected</h1> <script context="module">
export function preload() {
this.redirect(301, 'redirect-to');
}
</script>
<script> <h1>unredirected</h1>
export default {
preload() {
this.redirect(301, 'redirect-to');
}
};
</script>

View File

@@ -1,9 +1,7 @@
<h1>unredirected</h1> <script context="module">
export function preload() {
this.redirect(301, 'https://example.com');
}
</script>
<script> <h1>unredirected</h1>
export default {
preload() {
this.redirect(301, 'https://example.com');
}
};
</script>

View File

@@ -1,9 +1,7 @@
<h1>unredirected</h1> <script context="module">
export function preload() {
this.redirect(301, '/');
}
</script>
<script> <h1>unredirected</h1>
export default {
preload() {
this.redirect(301, '/');
}
};
</script>

View File

@@ -1,3 +1,13 @@
<script>
import { onMount } from 'svelte';
export let barLink = false;
onMount(() => {
barLink = true
});
</script>
<a href="tall-page#foo">scroll to foo</a> <a href="tall-page#foo">scroll to foo</a>
<div style="height: 9999px"></div> <div style="height: 9999px"></div>
@@ -7,18 +17,4 @@
{#if barLink} {#if barLink}
<a href="another-tall-page#bar">link</a> <a href="another-tall-page#bar">link</a>
{/if} {/if}
</div> </div>
<script>
export default {
data() {
return {
barLink: false
};
},
oncreate() {
this.set({ barLink: true })
}
}
</script>