Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix) take arrow function into account when adding return type (#1934)
#1932 also make ts a param
- Loading branch information
1 parent
0f813a3
commit 6ff486a
Showing
10 changed files
with
91 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as assert from 'assert'; | ||
import ts from 'typescript'; | ||
import { internalHelpers } from '../../src'; | ||
|
||
describe('Internal Helpers - upsertKitFile', () => { | ||
function upsert(file: string, source: string, expected: string) { | ||
const sourceFile = ts.createSourceFile('d', source, ts.ScriptTarget.Latest, true); | ||
const result = internalHelpers.upsertKitFile( | ||
ts, | ||
file, | ||
{ | ||
clientHooksPath: 'hooks.client', | ||
paramsPath: 'params', | ||
serverHooksPath: 'hooks.server' | ||
}, | ||
() => sourceFile | ||
); | ||
assert.strictEqual(result?.text, expected); | ||
} | ||
|
||
it('upserts +page.ts function', () => { | ||
upsert( | ||
'+page.ts', | ||
`export function load(e) { return e; }`, | ||
`export function load(e: import('./$types').PageLoadEvent) { return e; }` | ||
); | ||
}); | ||
|
||
it('upserts handle hook const', () => { | ||
upsert( | ||
'hooks.server.ts', | ||
`export const handle = async ({ event, resolve }) => {};`, | ||
`export const handle = async ({ event, resolve }: Parameters<import('@sveltejs/kit').Handle>[0]) : ReturnType<import('@sveltejs/kit').Handle> => {};` | ||
); | ||
}); | ||
|
||
it('upserts GET async function', () => { | ||
upsert( | ||
'+server.ts', | ||
`export async function GET(e) {}`, | ||
`export async function GET(e: import('./$types').RequestEvent) : Response | Promise<Response> {}` | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters