Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tests for serve functionality #116

Merged
merged 8 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const serve = async ({
}
}

const server = await prepareServer({
const server = prepareServer({
deno,
distDirectory,
flags,
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"del": "^6.0.0",
"env-paths": "^3.0.0",
"execa": "^6.0.0",
"get-port": "^6.1.2",
"find-up": "^6.3.0",
"glob-to-regexp": "^0.4.1",
"node-fetch": "^3.1.1",
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/serve_test/echo_env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default async () => new Response(JSON.stringify(Deno.env.toObject()))
45 changes: 45 additions & 0 deletions test/serving.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { join, resolve } from 'path'
import { fileURLToPath } from 'url'

import test from 'ava'
import getPort from 'get-port'
import fetch from 'node-fetch'

import { serve } from '../src/index.js'

const url = new URL(import.meta.url)
const dirname = fileURLToPath(url)
const fixturesDir = resolve(dirname, '..', 'fixtures')

test.serial('bundler serving functionality', async (t) => {
const port = await getPort()
const server = await serve({
port,
})

const { success } = await server(
[
{
name: 'echo_env',
path: join(fixturesDir, 'serve_test', 'echo_env.ts'),
},
],
{
very_secret_secret: 'i love netlify',
},
)

t.true(success)

const response = await fetch(`http://0.0.0.0:${port}/foo`, {
headers: {
'x-deno-functions': 'echo_env',
'x-deno-pass': 'passthrough',
'X-NF-Request-ID': 'foo',
},
})
t.is(response.status, 200)

const body = (await response.json()) as Record<string, string>
t.is(body.very_secret_secret, 'i love netlify')
})