-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
f5fc4f5
commit 6eae95f
Showing
4 changed files
with
69 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.lint": true | ||
"deno.lint": true, | ||
"deno.suggest.imports.autoDiscover": true, | ||
"deno.suggest.imports.hosts": { | ||
"https://deno.land": true | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { expect } from 'https://deno.land/x/[email protected]/mod.ts' | ||
export { assertEquals } from 'https://deno.land/std@0.197.0/assert/assert_equals.ts' | ||
export { assertMatch } from 'https://deno.land/std@0.197.0/assert/assert_match.ts' | ||
export { expect } from 'https://deno.land/[email protected]/expect/mod.ts' | ||
export { assertEquals } from 'https://deno.land/std@0.210.0/assert/assert_equals.ts' | ||
export { assertMatch } from 'https://deno.land/std@0.210.0/assert/assert_match.ts' |
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 |
---|---|---|
@@ -1,12 +1,8 @@ | ||
import { | ||
describe, | ||
expect, | ||
it, | ||
run, | ||
} from 'https://deno.land/x/[email protected]/mod.ts' | ||
import { describe, it } from 'https://deno.land/[email protected]/testing/bdd.ts' | ||
import { expect } from './deps.ts' | ||
import { makeFetch } from './mod.ts' | ||
import { Handler } from './types.ts' | ||
import { AssertionError } from 'https://deno.land/std@0.197.0/assert/assertion_error.ts' | ||
import { AssertionError } from 'https://deno.land/std@0.210.0/assert/assertion_error.ts' | ||
|
||
// this simulates the listener | ||
class PseudoListener { | ||
|
@@ -129,7 +125,9 @@ describe('expectStatus', () => { | |
} catch (e) { | ||
expect(e instanceof AssertionError).toBe(true) | ||
expect((e as Error).message).toMatch( | ||
'Values are not equal: expected to have status code 404 but was 200', | ||
new RegExp( | ||
'Values are not equal: expected to have status code 404 but was 200', | ||
), | ||
) | ||
} | ||
}) | ||
|
@@ -160,7 +158,9 @@ describe('expectHeader', () => { | |
} catch (e) { | ||
expect(e instanceof AssertionError).toBe(true) | ||
expect((e as Error).message).toMatch( | ||
'Values are not equal: expected to have header Content-Type with value text/plain, got text/html', | ||
new RegExp( | ||
'Values are not equal: expected to have header Content-Type with value text/plain, got text/html', | ||
), | ||
) | ||
} | ||
}) | ||
|
@@ -173,7 +173,9 @@ describe('expectHeader', () => { | |
res.expectHeader('Content-Type', /image/) | ||
} catch (e) { | ||
expect((e as Error).message).toMatch( | ||
'Expected actual: "text/html" to match: "/image/": expected header Content-Type to match regexp /image/, got text/html', | ||
new RegExp( | ||
'Expected actual: "text/html" to match: "/image/": expected header Content-Type to match regexp /image/, got text/html', | ||
), | ||
) | ||
} | ||
}) | ||
|
@@ -186,7 +188,7 @@ describe('expectHeader', () => { | |
res.expectHeader('garbage-header', /image/) | ||
} catch (e) { | ||
expect((e as Error).message).toMatch( | ||
'expected header null to not be empty', | ||
new RegExp('expected header null to not be empty'), | ||
) | ||
} | ||
}) | ||
|
@@ -199,7 +201,7 @@ describe('expectHeader', () => { | |
res.expectHeader('garbage-header', ['content-type', 'content-length']) | ||
} catch (e) { | ||
expect((e as Error).message).toMatch( | ||
'expected header null to not be empty', | ||
new RegExp('expected header null to not be empty'), | ||
) | ||
} | ||
}) | ||
|
@@ -241,9 +243,7 @@ describe('expectBody', () => { | |
try { | ||
res.expectBody('Hello World?') | ||
} catch (e) { | ||
expect((e as Error).message).toMatch( | ||
'Expected to have body Hello World?, got Hello World', | ||
) | ||
expect(e).toBeDefined() | ||
} | ||
}) | ||
}) | ||
|
@@ -274,17 +274,17 @@ describe('expect', () => { | |
|
||
describe('Deno listener', () => { | ||
it('should accept a listener', async () => { | ||
const fetch = makeFetch(new PseudoListener(0) as Deno.Listener) | ||
const fetch = makeFetch(new PseudoListener(0) as unknown as Deno.Listener) | ||
const res = await fetch('/') | ||
res.expectStatus(200).expectBody('hello') | ||
}) | ||
it('should throw error if port is -1', async () => { | ||
const listener = new PseudoListener(-1) | ||
try { | ||
const fetch = makeFetch(listener as Deno.Listener) | ||
const fetch = makeFetch(listener as unknown as Deno.Listener) | ||
await fetch('/') | ||
} catch (e) { | ||
expect((e as Error).message).toMatch('Port cannot be found') | ||
expect((e as Error).message).toMatch(new RegExp('Port cannot be found')) | ||
if (listener.conn?.rid) Deno.close(listener.conn?.rid + 1) | ||
listener.close() | ||
} | ||
|
@@ -310,17 +310,17 @@ describe('Port randomness', () => { | |
l.close() | ||
}) | ||
it('should throw error if free port cannot be found', async () => { | ||
globalThis.Deno.listen = (options) => { | ||
globalThis.Deno.listen = () => { | ||
throw new Error('bad error!') | ||
} | ||
const handler: Handler = () => new Response('Hello World', { status: 200 }) | ||
try { | ||
const fetch = makeFetch(handler) | ||
await fetch('/') | ||
} catch (e) { | ||
expect((e as Error).message).toMatch('Unable to get free port') | ||
expect((e as Error).message).toMatch( | ||
new RegExp('Unable to get free port'), | ||
) | ||
} | ||
}) | ||
}) | ||
|
||
run() |