mirror of https://github.com/sveltejs/svelte
parent
5af28fe91b
commit
923b086215
@ -0,0 +1,26 @@
|
||||
import { define_property } from './utils';
|
||||
|
||||
/**
|
||||
* @param {string} label
|
||||
* @param {(stack: string | undefined) => string | undefined} fn
|
||||
* @returns {Error & { stack: string } | null}
|
||||
*/
|
||||
export function get_infinite_stack(label, fn) {
|
||||
const limit = Error.stackTraceLimit;
|
||||
Error.stackTraceLimit = Infinity;
|
||||
let error = Error();
|
||||
Error.stackTraceLimit = limit;
|
||||
const stack = fn(error.stack);
|
||||
|
||||
if (!stack) return null;
|
||||
|
||||
define_property(error, 'stack', {
|
||||
value: stack
|
||||
});
|
||||
|
||||
define_property(error, 'name', {
|
||||
value: label
|
||||
});
|
||||
|
||||
return /** @type {Error & { stack: string }} */ (error);
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
import { ok, test } from '../../test';
|
||||
|
||||
export default test({
|
||||
skip_no_async: true,
|
||||
skip_mode: ['server'],
|
||||
|
||||
server_props: { environment: 'server' },
|
||||
ssrHtml: '<p>The current environment is: server</p>',
|
||||
|
||||
props: { environment: 'browser' },
|
||||
|
||||
async test({ assert, target, variant }) {
|
||||
const p = target.querySelector('p');
|
||||
ok(p);
|
||||
if (variant === 'hydrate') {
|
||||
assert.htmlEqual(p.outerHTML, '<p>The current environment is: server</p>');
|
||||
} else {
|
||||
assert.htmlEqual(p.outerHTML, '<p>The current environment is: browser</p>');
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -1,15 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { hydratable } from "svelte";
|
||||
|
||||
let { environment }: { environment: 'server' | 'browser' } = $props();
|
||||
|
||||
const value = hydratable("environment", () => environment, {
|
||||
transport: environment === 'server' ? {
|
||||
encode: (val: string) => JSON.stringify([val])
|
||||
} : {
|
||||
decode: (val: [string]) => val[0]
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<p>The current environment is: {value}</p>
|
||||
Loading…
Reference in new issue