Files
bun.sh/test/js/bun/console/console-table.test.ts
Jarred Sumner e848c3f226 Get Bun.write tests to pass on Windows and bun:sqlite tests to pass (#8393)
* Move ReadFile and WriteFile to separate file

* Use libuv for Bun.write()

* Update windows_event_loop.zig

* build

* Get bun-write tests to pass. Implement Bun.write with two files.

* UPdate

* Update

* Update failing test list

* update

* More

* More

* More

* More

* Mark the rest

* ok

* oops

* Update bun-write.test.js

* Update blob.zig

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Dave Caruso <me@paperdave.net>
Co-authored-by: Georgijs Vilums <georgijs.vilums@gmail.com>
2024-01-23 20:03:56 -08:00

207 lines
9.9 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, test } from "bun:test";
import { spawnSync } from "bun";
import { bunExe, bunEnv } from "harness";
describe("console.table", () => {
test("throws when second arg is invalid", () => {
expect(() => console.table({})).not.toThrow();
expect(() => console.table({}, [])).not.toThrow();
// @ts-expect-error
expect(() => console.table({}, "invalid")).toThrow();
});
test.each([
[
"not object (number)",
{
args: () => [42],
},
],
[
"not object (string)",
{
args: () => ["bun"],
},
],
[
"object - empty",
{
args: () => [{}],
},
],
[
"object",
{
args: () => [{ a: 42, b: "bun" }],
},
],
[
"array - empty",
{
args: () => [[]],
},
],
[
"array - plain",
{
args: () => [[42, "bun"]],
},
],
[
"array - object",
{
args: () => [[{ a: 42, b: "bun" }]],
},
],
[
"array - objects with diff props",
{
args: () => [[{ b: "bun" }, { a: 42 }]],
},
],
[
"array - mixed",
{
args: () => [[{ a: 42, b: "bun" }, 42]],
},
],
[
"set",
{
args: () => [new Set([42, "bun"])],
},
],
[
"map",
{
args: () => [
new Map<any, any>([
["a", 42],
["b", "bun"],
[42, "c"],
]),
],
},
],
[
"properties",
{
args: () => [[{ a: 42, b: "bun" }], ["b", "c", "a"]],
},
],
[
"properties - empty",
{
args: () => [[{ a: 42, b: "bun" }], []],
},
],
[
"values - array",
{
args: () => [
[
{ value: { a: 42, b: "bun" } },
{ value: [42, "bun"] },
{ value: new Set([42, "bun"]) },
{
value: new Map<any, any>([
[42, "bun"],
["bun", 42],
]),
},
],
],
},
],
[
"headers object",
{
args: () => [
new Headers([
["abc", "bun"],
["potato", "tomato"],
]),
],
},
],
])("expected output for: %s", (label, { args }) => {
const { stdout } = spawnSync({
cmd: [bunExe(), `${import.meta.dir}/console-table-run.ts`, args.toString()],
stdout: "pipe",
stderr: "inherit",
env: bunEnv,
});
const actualOutput = stdout.toString();
expect(actualOutput).toMatchSnapshot();
console.log(actualOutput);
});
});
test("console.table json fixture", () => {
const { stdout } = spawnSync({
cmd: [
bunExe(),
`${import.meta.dir}/console-table-run.ts`,
`(() => [${JSON.stringify(require("./console-table-json-fixture.json"), null, 2)}])`,
],
stdout: "pipe",
stderr: "inherit",
env: bunEnv,
});
const actualOutput = stdout
.toString()
// todo: fix bug causing this to be necessary:
.replaceAll("`", "'");
expect(actualOutput).toMatchSnapshot();
console.log(actualOutput);
});
test("console.table ansi colors", () => {
const obj = {
[ansify("hello")]: ansify("this is a long string with ansi color codes"),
[ansify("world")]: ansify("this is another long string with ansi color"),
[ansify("foo")]: ansify("bar"),
};
function ansify(str: string) {
return `\u001b[31m${str}\u001b[39m`;
}
const { stdout } = spawnSync({
cmd: [bunExe(), `${import.meta.dir}/console-table-run.ts`, `(() => [${JSON.stringify(obj, null, 2)}])`],
stdout: "pipe",
stderr: "inherit",
env: bunEnv,
});
const actualOutput = stdout
.toString()
// todo: fix bug causing this to be necessary:
.replaceAll("`", "'");
expect(actualOutput).toMatchSnapshot();
console.log(actualOutput);
});
test.skip("console.table character widths", () => {
// note: this test cannot be automated because cannot test printed witdhs consistently.
// so this test is just meant to be run manually
// top ~2000 most used unicode codepoints
const str = `~!@#$%^&*()_-+={[}]|:;"'<,>.?/¡¢£¤¥¦§¨©ª«¬ ®¯°±²³´µ¶·¸ʻ¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿŁłŃńŅņŇňŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŴŵŶŷŸŹźŻżŽžſƆƎƜɐɑɒɔɘəɛɜɞɟɡɢɣɤɥɨɪɬɮɯɰɴɵɶɷɸɹʁʇʌʍʎʞΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюяᴀᴁᴂᴃᴄᴅᴆᴇᴈᴉᴊᴋᴌᴍᴎᴏᴐᴑᴒᴓᴔᴕᴖᴗᴘᴙᴚᴛᴜᴝᴞᴟᴠᴡᴢᴣᴤᴥᴦᴧᴨᴩᴪẞỲỳỴỵỸỹ‐‑‒–—―‖‗‘’‚‛“”„‟†‡•‣․‥…‧‰‱′″‴‵‶‷‸‹›※‼‽‾‿⁀⁁⁂⁃⁄⁅⁆⁇⁈⁉⁊⁋⁌⁍⁎⁏⁐⁑⁒⁓⁔⁕⁗⁰ⁱ⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ⁿ₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₶₷₸₹℀℁ℂ℃℄℅℆ℇ℈℉ℊℋℌℍℎℏℐℑℒℓ℔ℕ№℗℘ℙℚℛℜℝ℞℟℠℡™℣ℤ℥Ω℧ℨ℩Åℬℭ℮ℯℰℱℲℳℴℵℶℷℸ⅁⅂⅃⅄ⅅⅆⅇⅈⅉ⅋ⅎ⅐⅑⅒⅓⅔⅕⅖⅗⅘⅙⅚⅛⅜⅝⅞⅟ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿↄ←↑→↓↔↕↖↗↘↙↚↛↜↝↞↟↠↡↢↣↤↥↦↧↨↩↪↫↬↭↮↯↰↱↲↳↴↵↶↷↸↹↺↻↼↽↾↿⇀⇁⇂⇃⇄⇅⇆⇇⇈⇉⇊⇋⇌⇍⇎⇏⇐⇑⇒⇓⇔⇕⇖⇗⇘⇙⇚⇛⇜⇝⇞⇟⇠⇡⇢⇣⇤⇥⇦⇧⇨⇩⇪⇫⇬⇭⇮⇯⇰⇱⇲⇳⇴⇵⇶⇷⇸⇹⇺⇻⇼⇽⇾⇿∀∁∂∃∄∅∆∇∈∉∊∋∌∍∎∏∐∑−∓∔∕∖∗∘∙√∛∜∝∞∟∠∡∢∣∤∥∦∧∨∩∪∫∬∭∮∯∰∱∲∳∴∵∶∷∸∹∺∻∼∽∾∿≀≁≂≃≄≅≆≇≈≉≊≋≌≍≎≏≐≑≒≓≔≕≖≗≘≙≚≛≜≝≞≟≠≡≢≣≤≥≦≧≨≩≪≫≬≭≮≯≰≱≲≳≴≵≶≷≸≹≺≻≼≽≾≿⊀⊁⊂⊃⊄⊅⊆⊇⊈⊉⊊⊋⊌⊍⊎⊏⊐⊑⊒⊓⊔⊕⊖⊗⊘⊙⊚⊛⊜⊝⊞⊟⊠⊡⊢⊣⊤⊥⊦⊧⊨⊩⊪⊫⊬⊭⊮⊯⊰⊱⊲⊳⊴⊵⊶⊷⊸⊹⊺⊻⊼⊽⊾⊿⋀⋁⋂⋃⋄⋅⋆⋇⋈⋉⋊⋋⋌⋍⋎⋏⋐⋑⋒⋓⋔⋕⋖⋗⋘⋙⋚⋛⋜⋝⋞⋟⋠⋡⋢⋣⋤⋥⋦⋧⋨⋩⋪⋫⋬⋭⋮⋯⋰⋱⌀⌁⌂⌃⌄⌅⌆⌇⌈⌉⌊⌋⌐⌑⌒⌓⌔⌕⌖⌗⌘⌙⌚⌛⌠⌡⌢⌣⌤⌥⌦⌧⌨⌫⌬⎛⎜⎝⎞⎟⎠⎡⎢⎣⎤⎥⎦⎧⎨⎩⎪⎫⎬⎭⏎⏏⏚⏛⏰⏱⏲⏳␢␣─━│┃┄┅┆┇┈┉┊┋┌┍┎┏┐┑┒┓└┕┖┗┘┙┚┛├┝┞┟┠┡┢┣┤┥┦┧┨┩┪┫┬┭┮┯┰┱┲┳┴┵┶┷┸┹┺┻┼┽┾┿╀╁╂╃╄╅╆╇╈╉╊╋╌╍╎╏═║╒╓╔╕╖╗╘╙╚╛╜╝╞╟╠╡╢╣╤╥╦╧╨╩╪╫╬╭╮╯╰╱╲╳╴╵╶╷╸╹╺╻╼╽╾╿▀▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▐░▒▓▔▕▖▗▘▙▚▛▜▝▞▟■□▢▣▤▥▦▧▨▩▪▫▬▭▮▯▰▱▲△▴▵▶▷▸▹►▻▼▽▾▿◀◁◂◃◄◅◆◇◈◉◊○◌◍◎●◐◑◒◓◔◕◖◗◘◙◚◛◜◝◞◟◠◡◢◣◤◥◦◧◨◩◪◫◬◭◮◯◰◱◲◳◴◵◶◷◸◹◺◻◼◽◾◿☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓☔☕☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻☼☽☾☿♀♁♂♃♄♅♆♇♈♉♊♋♌♍♎♏♐♑♒♓♔♕♖♗♘♙♚♛♜♝♞♟♠♡♢♣♤♥♦♧♨♩♪♫♬♭♮♯♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚐⚑⚒⚓⚔⚕⚖⚗⚘⚙⚚⚛⚜⚝⚞⚟⚠⚡⚢⚣⚤⚥⚦⚧⚨⚩⚪⚫⚬⚭⚮⚯⚰⚱⚲⚳⚴⚵⚶⚷⚸⚹⚺⚻⚼⛀⛁⛂⛃⛢⛤⛥⛦⛧⛨⛩⛪⛫⛬⛭⛮⛯⛰⛱⛲⛳⛴⛵⛶⛷⛸⛹⛺⛻⛼⛽⛾⛿✁✂✃✄✅✆✇✈✉✊✋✌✍✎✏✐✑✒✓✔✕✖✗✘✙✚✛✜✝✞✟✠✡✢✣✤✥✦✧✨✩✪✫✬✭✮✯✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞❟❠❡❢❣❤❥❦❧➔➘➙➚➛➜➝➞➟➠➡➢➣➤➥➦➧➨➩➪➫➬➭➮➯➱➲➳➴➵➶➷➸➹➺➻➼➽➾⟰⟱⟲⟳⟴⟵⟶⟷⟸⟹⟺⟻⟼⟽⟾⟿⤀⤁⤂⤃⤄⤅⤆⤇⤈⤉⤊⤋⤌⤍⤎⤏⤐⤑⤒⤓⤔⤕⤖⤗⤘⤙⤚⤛⤜⤝⤞⤟⤠⤡⤢⤣⤤⤥⤦⤧⤨⤩⤪⤫⤬⤭⤮⤯⤰⤱⤲⤳⤴⤵⤶⤷⤸⤹⤺⤻⤼⤽⤾⤿⥀⥁⥂⥃⥄⥅⥆⥇⥈⥉⥊⥋⥌⥍⥎⥏⥐⥑⬀⬁⬂⬃⬄⬅⬆⬇⬈⬉⬊⬋⬌⬍⬎⬏⬐⬑⬒⬓⬔⬕⬖⬗⬘⬙⬚ⱠⱡⱣⱥⱦⱭⱯⱰ⸢⸣⸤⸥⸮〃〄fffiflffifflſtst﴾﴿﷼︐︑︒︓︔︕︖︗︘︙︰︱︲︳︴︵︶︷︸︹︺︻︼︽︾︿﹀﹁﹂﹃﹄﹅﹆﹉﹊﹋﹌﹍﹎﹏﹐﹑﹒﹔﹕﹖﹗﹘﹙﹚﹛﹜﹝﹞﹟﹠﹡﹢﹣﹤﹥﹦﹨﹩﹪﹫\ufeff_⦅⦆¢£¬ ̄¦¥₩<EFBFBD>`;
const { stdout } = spawnSync({
cmd: [
bunExe(),
`${import.meta.dir}/console-table-run.ts`,
`(() => [${JSON.stringify([...str.matchAll(/.{16}|.+/g)].map(g => g[0].split("")))}])`,
],
stdout: "pipe",
stderr: "inherit",
env: bunEnv,
});
const actualOutput = stdout.toString();
console.log(actualOutput);
});