Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Sep 1, 2024
1 parent 1bdb4c9 commit a25b8a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions server/test/assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ test('serves static pages', async () => {

await writeFile(join(assets, 'index.html'), '<html>Hi</html>')
await writeFile(join(assets, 'favicon.ico'), 'A')
await mkdir(join(assets, 'ui'))
await writeFile(join(assets, 'ui', 'index.html'), '<html>Storybook</html>')
await writeFile(join(assets, 'data'), 'D')

let index1 = await server.fetch('/')
equal(index1.headers.get('Content-Type'), 'text/html')
Expand All @@ -51,6 +54,24 @@ test('serves static pages', async () => {
let icon2 = await server.fetch('/favicon.ico')
equal(icon2.headers.get('Content-Type'), 'image/x-icon')
equal(await icon2.text(), 'A')

let story1 = await server.fetch('/ui/')
equal(story1.headers.get('Content-Type'), 'text/html')
equal(await story1.text(), '<html>Storybook</html>')

let story2 = await server.fetch('/ui/')
equal(story2.headers.get('Content-Type'), 'text/html')
equal(await story2.text(), '<html>Storybook</html>')

let data = await server.fetch('/data')
equal(data.headers.get('Content-Type'), 'application/octet-stream')
equal(await data.text(), 'D')

let post = await server.fetch('/', { method: 'POST' })
equal(post.status, 404)

let unknown = await server.fetch('/unknown')
equal(unknown.status, 404)
})

test('ignores on missed environment variable', async () => {
Expand Down
2 changes: 2 additions & 0 deletions server/test/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ test('throws on missed DATABASE_URL in production', () => {
test('passes keys', () => {
deepStrictEqual(
getEnv({
ASSETS_DIR: '/dist/',
DATABASE_URL,
NODE_ENV: 'production'
}),
{
ASSETS_DIR: '/dist/',
DATABASE_URL,
NODE_ENV: 'production'
}
Expand Down

0 comments on commit a25b8a5

Please sign in to comment.