Skip to content

Commit

Permalink
bump std and deps
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Jan 4, 2024
1 parent f5fc4f5 commit 6eae95f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 28 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
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
}
}
41 changes: 39 additions & 2 deletions deno.lock

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

6 changes: 3 additions & 3 deletions deps.ts
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'
44 changes: 22 additions & 22 deletions mod_test.ts
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 {
Expand Down Expand Up @@ -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',
),
)
}
})
Expand Down Expand Up @@ -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',
),
)
}
})
Expand All @@ -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',
),
)
}
})
Expand All @@ -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'),
)
}
})
Expand All @@ -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'),
)
}
})
Expand Down Expand Up @@ -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()
}
})
})
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()

0 comments on commit 6eae95f

Please sign in to comment.