import { describe, expect, it } from 'vitest';
import { convertArrayToCsv, getHeaders } from './json-to-csv.service';
describe('json-to-csv service', () => {
describe('getHeaders', () => {
it('extracts all the keys from the array of objects', () => {
expect(getHeaders({ array: [{ a: 1, b: 2 }, { a: 3, c: 4 }] })).toEqual(['a', 'b', 'c']);
});
it('returns an empty array if the array is empty', () => {
expect(getHeaders({ array: [] })).toEqual([]);
});
});
describe('convertArrayToCsv', () => {
it('converts an array of objects to a CSV string', () => {
const array = [
{ a: 1, b: 2 },
{ a: 3, b: 4 },
];
expect(convertArrayToCsv({ array })).toMatchInlineSnapshot(`
"a,b
1,2
3,4"
`);
});
it('converts an array of objects with different keys to a CSV string', () => {
const array = [
{ a: 1, b: 2 },
{ a: 3, c: 4 },
];
expect(convertArrayToCsv({ array })).toMatchInlineSnapshot(`
"a,b,c
1,2,
3,,4"
`);
});
it('when a value is null, it is converted to the string "null"', () => {
const array = [
{ a: null, b: 2 },
];
expect(convertArrayToCsv({ array })).toMatchInlineSnapshot(`
"a,b
null,2"
`);
});
it('when a value is undefined, it is converted to an empty string', () => {
const array = [
{ a: undefined, b: 2 },
{ b: 3 },
];
expect(convertArrayToCsv({ array })).toMatchInlineSnapshot(`
"a,b
,2
,3"
`);
});
it('when a value contains a comma, it is wrapped in double quotes', () => {
const array = [
{ a: 'hello, world', b: 2 },
];
expect(convertArrayToCsv({ array })).toMatchInlineSnapshot(`
"a,b
\\"hello, world\\",2"
`);
});
it('when a value contains a double quote, it is escaped with another double quote', () => {
const array = [
{ a: 'hello "world"', b: 2 },
];
expect(convertArrayToCsv({ array })).toMatchInlineSnapshot(`
"a,b
hello \\\\\\"world\\\\\\",2"
`);
});
});
});
string-length'>dave/bundler-string-length
dave/es5-class-helper
dave/import.meta.resolve
dave/install-tag-without-dash
dave/lol
dave/nodemodule-preloadmodules
dave/postinstall
dave/postinstall_2
dave/remove-native-event
dave/zlib
debugger-dev
derrick/fix/bindings-mark-jscinitialize
derrick/fix/event-emitter-async-iter
derrick/fix/event-emitter-emit-throw-native
derrick/fix/http-lowercase-headers
derrick/fix/node-tests
derrick/test/add-ed25519-tests
detect-libc
doc/0.8
dylan/callback-fulfilled-after-rejection
dylan/change-pathname-assert
dylan/cli-fixes
dylan/encoding-fix
dylan/fix-bundling-lodash-es-is-buffer
dylan/fix-error-inlining
dylan/fix-module-field-in-exports
dylan/github-api-option
dylan/github-dependencies
dylan/import-file-path
dylan/non-enumerable-export-values
dylan/resolve-rope-in-string
dylan/set-exit-code
dylan/source-map-names-property
eventstream
feat/ecosystem
feat/npm
fix
fix-prepare-stack-trace
fix-websocket-upgrade
fs-watch-file
got
guides-3
improve-docker
insensitive-pkg-names
integration-tests
jarred/5859
jarred/actions
jarred/add-git
jarred/analytics
jarred/arenas
jarred/ast
jarred/ast-again
jarred/async_bio
jarred/bench
jarred/brotli
jarred/bump-uws
jarred/bundle-workspace-packages
jarred/bunfig
jarred/callable
jarred/canvas
jarred/ci-check
jarred/cjs2
jarred/cleanup-error
jarred/clipboard-objc
jarred/direct
jarred/dump
jarred/edgecase
jarred/esbuild-plugin-api
jarred/escapeHTML
jarred/esm-conditions
jarred/experiment-bsp
jarred/export-star-flat
jarred/exports-map
jarred/faster-error-capturestacktrace
jarred/faster-ordered-properties
jarred/fastmalloc
jarred/fetch-experiment
jarred/fetchheaders
jarred/fix-blob-slice-test
jarred/fix-bunbun-on-wsl
jarred/fix-crash
jarred/fix-http-compression
jarred/fix-issue-with-tsconfig-run
jarred/fix-proxy-regression
jarred/fixes-3129
jarred/gen
jarred/htmlrewriter
jarred/improve-testing
jarred/inquirer
jarred/isolation
jarred/jsc
jarred/land
jarred/landing
jarred/linux
jarred/live-bindings
jarred/make-strings-better
jarred/mdx-thrwawy
jarred/move
jarred/napi
jarred/new-bund
jarred/new-bund-ressurected-branch
jarred/new-http
jarred/no-more-npm
jarred/package-mapper
jarred/pg
jarred/port
jarred/possibly-2732
jarred/postgresql
jarred/precompile-linux-dependencies
jarred/prepare-for-libuv
jarred/profiled-call
jarred/read-tsconfig-jsx
jarred/redo-evaluation-order
jarred/redo-zigstring-for-utf16
jarred/relay
jarred/rename
jarred/repl
jarred/request-finalizer
jarred/rewrite-router
jarred/run
jarred/simdjson
jarred/simplify
jarred/some-fixes-for-eventsource
jarred/standalone-repro1
jarred/start
jarred/strong
jarred/subprocess
jarred/support-tee
jarred/tcc
jarred/throw-if
jarred/update-install-stuff
jarred/update-zig1
jarred/upgrade-zig-2
jarred/uws
jarred/webkit-upgrade-may-17
jarred/wip-more-reliable
jarred/workers
jarred/zlib
jarred/zls
lithdew/picohttp-mimalloc
main
move-templates
nestjs-guide
next-cleanup
origin/main
plugin/plugindata
plugin/resolvedir
postinstall_3
repl
request-body-stream
reserve-commands
revert-5167-dylan/decode-regex-if-needed
rfc/bun-bundler-api
rfc/bunfig-overhaul
save-in-update
sdl
test/action
types/mock
types/readable-stream-default
types/tty
u/vjpr/zig-0.10
xHyroM/types/expose-Bun-Env
Unnamed repository; edit this file 'description' to name the repository.
Age Commit message (Collapse ) Author Files Lines
some tests
* docs(cli/bunx): add notice bunx alias bun x
* docs: grammar
* iterate through remaining indexes, keep prop identifier
* tests
* format
* Add lastModified field for FileBlob (#1431)
lastModified value is epoch timestamp in millisecond unit.
* update according to review comment.
* Update typecheck
* Test ci
* Test ci
* Prettify files
* Use zsh-compatible syntax in cowsay example
zsh interprets the string !" differently than bash or sh, but we can use single quotes in all of them. See https://unix.stackexchange.com/a/497335/548905.
* Add tests for bun:test with preload scripts
* Look at `stderr` in `bun test --preload` tests
hopefully fixes an issue reported in Discord
* fix proxy authentication
* add auth tests
* remove unused
Related message by Jarred: https://discord.com/channels/876711213126520882/876711213126520885/1093286199369682944
If you put `--watch` after the script name, it will not work.
* `deepEqual` handles slow array indexes
* another test
* oops
* remove bad test
* compare indexes in non-strict mode
* more tests
* Implement `import.meta.main`
* Update main-test-1.js
* Update fs.test.ts
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
* handle `umask()` invalid arguments
* move `bktree-fast` to test root, fix postinstall
* fix fs test
* could be baseline
* handle different timezones
* accidentally deleted tests
* fix hang in `AbortSignal.timeout`
* bring abort tests back
* Revert "bring abort tests back"
This reverts commit 0ff2ad5bf408694ac719b8ba0a38b16070e10201.
* bunx node-gyp
* bun x
* fix typecheck
* test
* Update inspect.test.js
---------
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
* Add install bench
* Update scripts and readme
* remove lockfiles
* Format bench
* Add dev instructions