-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
v1rtl
committed
Jun 4, 2023
1 parent
40d2beb
commit c524ab6
Showing
5 changed files
with
57 additions
and
11 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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { parseRequest } from './request.ts' | ||
import { assertEquals } from 'https://deno.land/[email protected]/testing/asserts.ts' | ||
|
||
Deno.test('parseRequest', async (t) => { | ||
await t.step('Returns an error if not object', () => { | ||
assertEquals(parseRequest('i am text'), 'parse-error') | ||
}) | ||
await t.step('Marks as invalid if empty array', () => { | ||
assertEquals(parseRequest('[]'), ['invalid']) | ||
}) | ||
await t.step('Marks as invalid if not array of objects', () => { | ||
assertEquals(parseRequest('["i am text"]'), ['invalid']) | ||
}) | ||
await t.step('Marks as invalid if version is not 2.0', () => { | ||
assertEquals(parseRequest(JSON.stringify({ method: 'hello' })), ['invalid']) | ||
assertEquals( | ||
parseRequest(JSON.stringify({ method: 'hello', jsonrpc: '1.0' })), | ||
['invalid'], | ||
) | ||
}) | ||
await t.step('Marks as invalid if method is missing', () => { | ||
assertEquals(parseRequest(JSON.stringify({ jsonrpc: '2.0' })), ['invalid']) | ||
}) | ||
await t.step('Properly parses valid request', () => { | ||
const response = { jsonrpc: '2.0', method: 'hello' } | ||
assertEquals(parseRequest(JSON.stringify(response)), [response]) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,23 +1,31 @@ | ||
import { lazyJSONParse, pathsAreEqual } from './utils.ts' | ||
import { assertEquals } from 'https://deno.land/[email protected]/testing/asserts.ts' | ||
import { delay, lazyJSONParse, pathsAreEqual } from './utils.ts' | ||
import { assertEquals, assert } from 'https://deno.land/[email protected]/testing/asserts.ts' | ||
|
||
Deno.test('lazyJSONParse', async (it) => { | ||
await it.step('should parse JSON like JSON.parse', () => { | ||
Deno.test('lazyJSONParse', async (t) => { | ||
await t.step('should parse JSON like JSON.parse', () => { | ||
assertEquals(lazyJSONParse('{ "a": "b" }'), JSON.parse('{ "a": "b" }')) | ||
}) | ||
await it.step('should return an empty object on failed parse', () => { | ||
await t.step('should return an empty object on failed parse', () => { | ||
assertEquals(lazyJSONParse('{ "a": "b"'), {}) | ||
}) | ||
}) | ||
|
||
Deno.test('pathsAreEqual', async (it) => { | ||
await it.step('if expected path is asterisk, return true', () => { | ||
Deno.test('pathsAreEqual', async (t) => { | ||
await t.step('if expected path is asterisk, return true', () => { | ||
assertEquals(pathsAreEqual('/hello', '*'), true) | ||
}) | ||
await it.step('should assert equal paths', () => { | ||
await t.step('should assert equal paths', () => { | ||
assertEquals(pathsAreEqual('/hello', '/hello'), true) | ||
}) | ||
await it.step('if nothing is expected, default to "/"', () => { | ||
await t.step('if nothing is expected, default to "/"', () => { | ||
assertEquals(pathsAreEqual('/'), true) | ||
}) | ||
}) | ||
|
||
Deno.test('delay', async (t) => { | ||
await t.step('it delays a function for given time', async () => { | ||
const then = performance.now() | ||
await delay(10) | ||
assert(performance.now() - then < 15) // there's extra run-time | ||
}) | ||
}) |