Skip to content

Commit

Permalink
chore: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Jun 22, 2024
1 parent 37c5e5c commit c203a33
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/svelte2tsx/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ const enum TestError {

const isSvelte5Plus = Number(VERSION[0]) >= 5;

console.log('IS SVELTE 5 +', isSvelte5Plus);

export function test_samples(dir: string, transform: TransformSampleFn, js: 'js' | 'ts') {
for (const sample of each_sample(dir)) {
if (sample.name.endsWith('.v5') && !isSvelte5Plus) continue;
Expand Down Expand Up @@ -320,12 +322,16 @@ export function test_samples(dir: string, transform: TransformSampleFn, js: 'js'
try {
assert.strictEqual(actual, expected, TestError.WrongExpected);
} catch (e) {
// html2jsx tests don't have the default export
const expectDefaultExportPosition = expected.lastIndexOf(
'\n\nexport default class'
);
if (expectDefaultExportPosition === -1) {
throw e;
}
// retry with the last part (the returned default export) stripped because it's always differing between old and new,
// and if that fails then we're going to rethrow the original error
const expectedModified = expected.substring(
0,
expected.lastIndexOf('\n\nexport default class')
);
const expectedModified = expected.substring(0, expectDefaultExportPosition);
const actualModified = actual.substring(0, actual.lastIndexOf('\nconst '));
try {
assert.strictEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ item as string;

var foo3/*Ωignore_startΩ*/: import('svelte').Snippet<[string | number, (str: string)=>void]>/*Ωignore_endΩ*/ = (bar : string | number, baz : (str: string)=>void) => {async () => { };return __sveltets_2_any(0)};

var foo3/*Ωignore_startΩ*/: import('svelte').Snippet<[{baz: string}]>/*Ωignore_endΩ*/ = (bar: {baz: string}) => {async () => { };return __sveltets_2_any(0)};

;__sveltets_2_ensureSnippet(foo(bar as string));

{ svelteHTML.createElement("button", { "onclick":(e: Event) => {e as any},}); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
snippet
{/snippet}

{#snippet foo3(bar: {baz: string})}
snippet
{/snippet}

{@render foo(bar as string)}

<button onclick={(e: Event) => {e as any}}>click</button>
Expand Down

0 comments on commit c203a33

Please sign in to comment.