Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
73 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { test } from 'https://deno.land/x/testing/testing.ts'; | ||
import { exit } from 'deno'; | ||
import { assertEqual } from 'https://deno.land/x/pretty_assert@0.1.1/index.ts'; | ||
import { App } from './dinatra.ts'; | ||
|
||
const testPort = '8376'; | ||
const host = `http://localhost:${testPort}`; | ||
|
||
const app = new App(testPort, 'testdata/static'); | ||
app.serve(); | ||
|
||
const sleep = ms => new Promise(r => setTimeout(r, ms)); | ||
|
||
(async () => { | ||
interface testCase { | ||
name: string; | ||
path: string; | ||
expected: string; | ||
} | ||
|
||
const testCases: Array<testCase> = [ | ||
{ | ||
name: 'valid normal path', | ||
path: 'index.js', | ||
expected: 'ok', | ||
}, | ||
{ | ||
name: 'valid index path', | ||
path: '', | ||
expected: 'ok', | ||
}, | ||
{ | ||
name: 'valid nested normal path', | ||
path: 'nested/index.js', | ||
expected: 'ok', | ||
}, | ||
{ | ||
name: 'valid nested index path', | ||
path: 'nested', | ||
expected: 'ok', | ||
}, | ||
{ | ||
name: 'invalid not found', | ||
path: 'nonExistencePath', | ||
expected: 'not found', | ||
}, | ||
]; | ||
|
||
for (const tc of testCases) { | ||
test({ | ||
name: tc.name, | ||
async fn() { | ||
await sleep(50); | ||
const res = await fetch(`${host}/${tc.path}`); | ||
const actual = await res.text(); | ||
const contentLength = res.headers.get('content-length'); | ||
assertEqual(actual, tc.expected); | ||
assertEqual(contentLength, tc.expected.length.toString()); | ||
}, | ||
}); | ||
} | ||
|
||
await sleep(500); | ||
exit(0); | ||
})(); |
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 @@ | ||
ok |
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 @@ | ||
ok |
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 @@ | ||
ok |
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 @@ | ||
ok |