-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
9 changed files
with
132 additions
and
7 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
5 changes: 5 additions & 0 deletions
5
packages/seroval/test/web-api/__snapshots__/file.test.ts.snap
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,5 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`File > serializeAsync > supports File 1`] = `"Promise.resolve(new File([new Uint8Array([72,101,108,108,111,32,87,111,114,108,100]).buffer],\\"hello.txt\\",{type:\\"text/plain\\",lastModified:1681027542680}))"`; | ||
|
||
exports[`File > toJSONAsync > supports File 1`] = `"{\\"t\\":{\\"t\\":18,\\"i\\":0,\\"f\\":{\\"t\\":31,\\"i\\":1,\\"c\\":\\"text/plain\\",\\"m\\":\\"hello.txt\\",\\"f\\":{\\"t\\":28,\\"i\\":2,\\"s\\":[72,101,108,108,111,32,87,111,114,108,100]},\\"b\\":1681027542680}},\\"r\\":0,\\"i\\":false,\\"f\\":16383,\\"m\\":[]}"`; |
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,39 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import 'node-fetch-native/polyfill'; | ||
import { | ||
deserialize, | ||
fromJSON, | ||
serializeAsync, | ||
toJSONAsync, | ||
} from '../../src'; | ||
|
||
describe('File', () => { | ||
describe('serializeAsync', () => { | ||
it('supports File', async () => { | ||
const example = new File(['Hello World'], 'hello.txt', { | ||
type: 'text/plain', | ||
lastModified: 1681027542680, | ||
}); | ||
const result = await serializeAsync(Promise.resolve(example)); | ||
expect(result).toMatchSnapshot(); | ||
const back = await deserialize<Promise<File>>(result); | ||
expect(back).toBeInstanceOf(File); | ||
expect(await back.text()).toBe(await example.text()); | ||
expect(back.type).toBe(example.type); | ||
}); | ||
}); | ||
describe('toJSONAsync', () => { | ||
it('supports File', async () => { | ||
const example = new File(['Hello World'], 'hello.txt', { | ||
type: 'text/plain', | ||
lastModified: 1681027542680, | ||
}); | ||
const result = await toJSONAsync(Promise.resolve(example)); | ||
expect(JSON.stringify(result)).toMatchSnapshot(); | ||
const back = await fromJSON<Promise<File>>(result); | ||
expect(back).toBeInstanceOf(File); | ||
expect(await back.text()).toBe(await example.text()); | ||
expect(back.type).toBe(example.type); | ||
}); | ||
}); | ||
}); |