-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: export
metadata
object in stage 2 (#122)
* feat: export `metadata` object in stage 2 * refactor: simplify metadata generation Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
937bd22
commit 99214c7
Showing
18 changed files
with
97 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { assertEquals, assertStringIncludes } from 'https://deno.land/std@0.127.0/testing/asserts.ts' | ||
|
||
import { join } from 'https://deno.land/std@0.155.0/path/mod.ts' | ||
import { pathToFileURL } from 'https://deno.land/std@0.155.0/node/url.ts' | ||
|
||
import { getStage2Entry } from '../../deno/lib/stage2.ts' | ||
import { virtualRoot } from '../../deno/lib/consts.ts' | ||
|
||
Deno.test('`getStage2Entry` returns a valid stage 2 file', async () => { | ||
const directory = await Deno.makeTempDir() | ||
const functions = [ | ||
{ | ||
name: 'func1', | ||
path: join(directory, 'func1.ts'), | ||
response: 'Hello from function 1', | ||
}, | ||
{ | ||
name: 'func2', | ||
path: join(directory, 'func2.ts'), | ||
response: 'Hello from function 2', | ||
}, | ||
] | ||
|
||
for (const func of functions) { | ||
const contents = `export default async () => new Response(${JSON.stringify(func.response)})` | ||
|
||
await Deno.writeTextFile(func.path, contents) | ||
} | ||
|
||
const baseURL = pathToFileURL(directory) | ||
const stage2 = getStage2Entry( | ||
directory, | ||
functions.map(({ name, path }) => ({ name, path })), | ||
) | ||
|
||
// Ensuring that the stage 2 paths have the virtual root before we strip it. | ||
assertStringIncludes(stage2, virtualRoot) | ||
|
||
// Replacing the virtual root with the URL of the temporary directory so that | ||
// we can actually import the module. | ||
const normalizedStage2 = stage2.replaceAll(virtualRoot, `${baseURL.href}/`) | ||
|
||
const stage2Path = join(directory, 'stage2.ts') | ||
|
||
await Deno.writeTextFile(stage2Path, normalizedStage2) | ||
|
||
const mod = await import(stage2Path) | ||
|
||
await Deno.remove(directory, { recursive: true }) | ||
|
||
for (const func of functions) { | ||
const result = await mod.functions[func.name]() | ||
|
||
assertEquals(await result.text(), func.response) | ||
assertEquals(mod.metadata[func.name].url, pathToFileURL(func.path).toString()) | ||
} | ||
}) |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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