-
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.
Finished out driver, protocol, and core tests
- Loading branch information
Showing
26 changed files
with
303 additions
and
170 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
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
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
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
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,46 @@ | ||
import { beforeAll, describe, expect, test } from 'vitest' | ||
import type { SuperJSONResult } from 'superjson' | ||
import { Attachment } from '@/attachments' | ||
import useSuperJson from '@/rpc/transformer' | ||
|
||
describe('superjson', () => { | ||
let superjson: ReturnType<typeof useSuperJson> | ||
beforeAll(() => { | ||
superjson = useSuperJson() | ||
}) | ||
|
||
describe('attachments', () => { | ||
test('serialize', () => { | ||
const payload = { file: new Attachment('test.txt', 'text/plain', Buffer.from('Hello World')) } | ||
expect(superjson.serialize(payload)).toStrictEqual({ | ||
json: { file: { name: 'test.txt', type: 'text/plain', data: 'SGVsbG8gV29ybGQ=' } }, | ||
meta: { values: { file: [['custom', 'Attachment']] } } | ||
}) | ||
}) | ||
|
||
test('deserialize', () => { | ||
const payload = { | ||
json: { file: { name: 'test.txt', type: 'text/plain', data: 'SGVsbG8gV29ybGQ=' } }, | ||
meta: { values: { file: [['custom', 'Attachment']] } } | ||
} satisfies SuperJSONResult | ||
expect(superjson.deserialize(payload)).toStrictEqual({ | ||
file: new Attachment('test.txt', 'text/plain', Buffer.from('Hello World')) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('functions', () => { | ||
test('serialize', () => { | ||
const payload = { hello: () => undefined } | ||
expect(() => superjson.serialize(payload)).toThrow(new TypeError('Functions may not be serialized')) | ||
}) | ||
|
||
test('deserialize', () => { | ||
const payload = { | ||
json: { file: null }, | ||
meta: { values: { file: [['custom', 'Function']] } } | ||
} satisfies SuperJSONResult | ||
expect(() => superjson.deserialize(payload)).toThrow(new TypeError('Functions may not be serialized')) | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.