import { ArrayBufferSink } from "bun"; import { describe, expect, it } from "bun:test"; import { mkfifo } from "mkfifo"; describe("FileSink", () => { const fixtures = [ [ ["abcdefghijklmnopqrstuvwxyz"], new TextEncoder().encode("abcdefghijklmnopqrstuvwxyz"), "abcdefghijklmnopqrstuvwxyz", ], [ ["abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"], new TextEncoder().encode( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ], [ ["πŸ˜‹ Get Emoji β€” All Emojis to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ"], new TextEncoder().encode( "πŸ˜‹ Get Emoji β€” All Emojis to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ", ), "πŸ˜‹ Get Emoji β€” All Emojis to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ", ], [ [ "abcdefghijklmnopqrstuvwxyz", "πŸ˜‹ Get Emoji β€” All Emojis to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ", ], new TextEncoder().encode( "abcdefghijklmnopqrstuvwxyz" + "πŸ˜‹ Get Emoji β€” All Emojis to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ", ), "abcdefghijklmnopqrstuvwxyz" + "πŸ˜‹ Get Emoji β€” All Emojis to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ", ], [ [ "abcdefghijklmnopqrstuvwxyz", "πŸ˜‹", " Get Emoji β€” All Emojis", " to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ", ], new TextEncoder().encode( "abcdefghijklmnopqrstuvwxyz" + "πŸ˜‹ Get Emoji β€” All Emojis to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ", ), "(rope) " + "abcdefghijklmnopqrstuvwxyz" + "πŸ˜‹ Get Emoji β€” All Emojis to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ", ], [ [ new TextEncoder().encode("abcdefghijklmnopqrstuvwxyz"), "πŸ˜‹", " Get Emoji β€” All Emojis", " to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ", ], new TextEncoder().encode( "abcdefghijklmnopqrstuvwxyz" + "πŸ˜‹ Get Emoji β€” All Emojis to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ", ), "(array) " + "abcdefghijklmnopqrstuvwxyz" + "πŸ˜‹ Get Emoji β€” All Emojis to βœ‚οΈ Copy and πŸ“‹ Paste πŸ‘Œ", ], ] as const; function getPath(label) { const path = `/tmp/bun-test-${Bun.hash(label).toString(10)}.txt`; try { require("fs").unlinkSync(path); } catch (e) {} return path; } var activeFIFO: Promise; var decoder = new TextDecoder(); function getFd(label) { const path = `/tmp/bun-test-${Bun.hash(label).toString(10)}.txt`; try { require("fs").unlinkSync(path); } catch (e) {} mkfifo(path, 0o666); activeFIFO = (async function (stream: ReadableStream) { var chunks: Uint8Array[] = []; for await (const chunk of stream) { chunks.push(chunk); } return Buffer.concat(chunks).toString(); // test it on a small chunk size })(Bun.file(path).stream(4)); return path; } for (let isPipe of [true, false] as const) { describe(isPipe ? "pipe" : "file", () => { for (const [input, expected, label] of fixtures) { var getPathOrFd = () => (isPipe ? getFd(label) : getPath(label)); it(`${JSON.stringify(label)}`, async () => { const path = getPathOrFd(); const sink = Bun.file(path).writer(); for (let i = 0; i < input.length; i++) { sink.write(input[i]); } await sink.end(); if (!isPipe) { const output = new Uint8Array(await Bun.file(path).arrayBuffer()); for (let i = 0; i < expected.length; i++) { expect(output[i]).toBe(expected[i]); } expect(output.byteLength).toBe(expected.byteLength); } else { const output = await activeFIFO; expect(output).toBe(decoder.decode(expected)); } }); it(`flushing -> ${JSON.stringify(label)}`, async () => { const path = getPathOrFd(); const sink = Bun.file(path).writer(); for (let i = 0; i < input.length; i++) { sink.write(input[i]); await sink.flush(); } await sink.end(); if (!isPipe) { const output = new Uint8Array(await Bun.file(path).arrayBuffer()); for (let i = 0; i < expected.length; i++) { expect(output[i]).toBe(expected[i]); } expect(output.byteLength).toBe(expected.byteLength); } else { const output = await activeFIFO; expect(output).toBe(decoder.decode(expected)); } }); it(`highWaterMark -> ${JSON.stringify(label)}`, async () => { const path = getPathOrFd(); const sink = Bun.file(path).writer({ highWaterMark: 1 }); for (let i = 0; i < input.length; i++) { sink.write(input[i]); await sink.flush(); } await sink.end(); if (!isPipe) { const output = new Uint8Array(await Bun.file(path).arrayBuffer()); for (let i = 0; i < expected.length; i++) { expect(output[i]).toBe(expected[i]); } expect(output.byteLength).toBe(expected.byteLength); } else { const output = await activeFIFO; expect(output).toBe(decoder.decode(expected)); } }); } }); } }); /option> Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2021-08-26[ci] yarn formatGravatar FredKSchott 1-1/+1
2021-08-25added bengali translation of the getting started page (#1215)Gravatar Rafid Muhymin Wafi 3-0/+68
2021-08-25updated comment 'threw' to 'through' (#1235)Gravatar Mark Howard 1-1/+1
2021-08-25Fix path to CSS file in www site (#1233)Gravatar Matthew Phillips 1-1/+1
* Fix path to CSS file in www site * remove console.log
2021-08-25NL docs typo fixes (#1232)Gravatar semvis123 1-1/+1
Fixes 2 small typos in the Dutch documentation
2021-08-25Update getting-started.md (#1231)Gravatar Anneke Sinnema 1-6/+6
2021-08-25[ci] yarn formatGravatar FredKSchott 2-142/+145
2021-08-25stop building, bundling, and transforming public/ files (#1210)Gravatar Fred K. Schott 28-191/+246
* stop bundling public/ files * update www and examples
2021-08-25[ci] yarn formatGravatar matthewp 2-5/+5
2021-08-25Arabic getting-started translation (#1166)Gravatar Ψ­Ω…Ψ― Ψ¨Ω†Ω‚Ψ§Ω„ΩŠ 3-0/+71
Co-authored-by: = <=>
2021-08-25Fix typo Mardown on line 219 (#1229)Gravatar E. Berke KARAGΓ–Z 1-1/+1
2021-08-25docs: fix header rtl logo view (#1224)Gravatar Fred K. Schott 1-0/+1
2021-08-25Upgrade unified deps and improve unified plugins types (#1200)Gravatar Robin MΓ©tral 12-428/+755
* Upgrade @astrojs/markdown-support deps and update types * Add changeset * Update changeset * Switch astro-markdown-plugins example to use rehype-autolink-headings Usage of remark-autolink-headings is discouraged in favor of the rehype counterpart: https://github.com/remarkjs/remark-autolink-headings\#remark-autolink-headings * Add stricter types for unified plugins This includes a few suggestions from a code review: - use vfile.toString instead of vfile.value.toString - refactor plugins to follow unified best practices instead of returning functions that return a plugin - use any instead of any[] for plugin options types * Narrow down types to more specific hast or mdast typings
2021-08-24Fix CSS in docs example (#1221)Gravatar Marcus OtterstrΓΆm 1-2/+3
2021-08-24Version Packages (#1217)astro@0.19.4Gravatar github-actions[bot] 24-31/+28
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-08-24[ci] yarn formatGravatar matthewp 1-1/+3
2021-08-24Fix linter errors and warnings (#1218)Gravatar Mihkel Eidast 12-26/+33
* fix lint issues, enable lint in ci * add changeset
2021-08-24Fix resolution of Astro.resolve in nested components (#1213)Gravatar Matthew Phillips 5-5/+14
* Fix resolution of Astro.resolve in nested components Components were previously tested, however nested folders were not. * Adds a changeset
2021-08-24Lazy load the youtube embed to boost homepage loading times (#1205)Gravatar Caleb Jasik 4-4/+138
2021-08-24[ci] yarn formatGravatar FredKSchott 2-7/+7
2021-08-23[i18n][Docs] Add Korean Translation of Getting Started page (#1189)Gravatar Joohoon Cha 4-1/+70
* translate getting-started.md into KR * add kr to KNOWN_LANGUAGES * add kr config to sidebar * add kr option to the language selector
2021-08-23remove ignored lint ruleGravatar Fred K. Schott 1-1/+1
2021-08-23update depsGravatar Fred K. Schott 1-317/+275
2021-08-23Version Packages (#1206)astro@0.19.3Gravatar github-actions[bot] 25-45/+38
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-08-23[ci] yarn formatGravatar FredKSchott 1-4/+5
2021-08-23fix docs on config apiGravatar Fred K. Schott 1-7/+11
2021-08-23[ci] yarn formatGravatar FredKSchott 6-11/+10
2021-08-23Add zod schema validation (#1198)Gravatar Fred K. Schott 32-361/+378
* add zod schema validation * update pageUrlFormat config name * add trailing slash support to config
2021-08-23[ci] yarn formatGravatar matthewp 1-2/+1
2021-08-23Add Astro `<Debug/>` component (#675)Gravatar Caleb Jasik 7-0/+350
* Initial MVP Debug component * Document the prettifying of the input * Just make `<Debug/>` a wrapper around `<Prism/>` lol * feat: add details/summary debug component * chore: remove Props (unused) * fix: prefer `div` to semantic elements * chore: format * fix: prop-drill `class` into components * fix: ensure `astro/components` are evaluated lazily * feat(debug): export debug component from `astro/debug` * fix: minimal example local snowpack config * docs: add debugging docs * chore: add changeset * docs: update debug docs Co-authored-by: Nate Moore <nate@skypack.dev>
2021-08-23Add a `titleClosure` to the `HeadSEO.astro` component (#1140)Gravatar Caleb Jasik 3-6/+69
* Testing out adding a `titleClosure` to the `HeadSEO.astro` component I think the api needs a bit of improvement, but the basic idea is you can pass this in to a published astro component for specifying how you want it to format your title! * Refactor to make it pretty * Rename the `titleClosure()` prop to `formatTitle()` to be more clear * Use title, with site title as the fallback (#1143) See og:title guidance (https://developers.facebook.com/docs/sharing/webmasters/) Co-authored-by: Jonathan Neal <jonathantneal@hotmail.com>
2021-08-23Version Packages (#1181)astro@0.19.2Gravatar github-actions[bot] 27-46/+31
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2021-08-23fix issue with multiple getStaticPaths calls during build (#1194)Gravatar Fred K. Schott 12-70/+116
2021-08-23Add trailingSlash & pageDirectoryUrl config options (#1197)Gravatar Fred K. Schott 17-92/+284
2021-08-23[ci] yarn formatGravatar matthewp 1-1/+0
2021-08-23fix the rtl search bar view (#1177)Gravatar Fred K. Schott 3-16/+14
2021-08-20update universal idGravatar Fred K. Schott 4-13/+10
2021-08-20Update getting-started.md (#1182)Gravatar headapplesgithub 1-1/+1
corrected typo "quickly" to "quick"
2021-08-20CodeSandbox-izing via template override (#1167)Gravatar Sarah Rainsberger 2-0/+11
* initial commit * Added to config to specify port and node version. I think this will be all that's needed.