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() {
<script>
export default {
preload() {
return this.fetch('b.json').then(r => r.json()).then(letter => { return this.fetch('b.json').then(r => r.json()).then(letter => {
return { letter }; return { letter };
}); });
} }
};
</script> </script>
<script>
export let letter;
</script>
<h1>{letter}</h1>

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;
});
function del() {
fetch(`delete-test/42.json`, { method: 'DELETE' }) fetch(`delete-test/42.json`, { method: 'DELETE' })
.then(r => r.json()) .then(r => r.json())
.then(data => { .then(data => {
window.deleted = 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() {
<script>
export default {
preload() {
return '$&'; return '$&';
} }
};
</script> </script>
$&

View File

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

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 }) {
<script>
export default {
preload({ params }) {
return { return {
slug: params.slug slug: params.slug
}; };
} }
};
</script> </script>
<script>
export let slug;
export let query;
</script>
<h1>{slug} {JSON.stringify(query)}</h1>

View File

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

View File

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

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 }) {
<script>
export default {
preload({ params }) {
return this.fetch(`blog/${params.slug}.json`).then(r => r.json()).then(post => { return this.fetch(`blog/${params.slug}.json`).then(r => r.json()).then(post => {
return { post }; return { post };
}); });
} }
};
</script> </script>
<script>
export let post;
</script>
<h1>{post.title}</h1>

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() {
<script>
export default {
preload() {
return this.fetch('b.json').then(r => r.json()).then(letter => { return this.fetch('b.json').then(r => r.json()).then(letter => {
return { letter }; return { letter };
}); });
} }
};
</script> </script>
<script>
export let letter;
</script>
<h1>{letter}</h1>

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
}; };
},
oncreate() {
this.set({
segment: this.get().params.z
});
} }
};
</script> </script>
<script>
export let params;
export let count;
export let segment = params.z;
</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,8 +1,5 @@
<h1>{foo.bar()}</h1> <script context="module">
export function preload() {
<script>
export default {
preload() {
class Foo { class Foo {
bar() { bar() {
return 42; return 42;
@@ -13,5 +10,10 @@
foo: new Foo() foo: new Foo()
}; };
} }
};
</script> </script>
<script>
export let foo;
</script>
<h1>{foo.bar()}</h1>

View File

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

View File

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

View File

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

View File

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

View File

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

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>
@@ -8,17 +18,3 @@
<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>