From cb5b7935860cb25ed18a057c2a9640e4303da710 Mon Sep 17 00:00:00 2001 From: Alex Caza Date: Tue, 9 Apr 2024 20:29:14 -0400 Subject: [PATCH 1/3] Remove duplicate tests for text export It overs no real extra coverage as text export is functionally the same. The only difference is in the file extension, which is covered with the integration tests. --- lib/__specs__/main.spec.ts | 216 ------------------------------------- 1 file changed, 216 deletions(-) diff --git a/lib/__specs__/main.spec.ts b/lib/__specs__/main.spec.ts index 0df4056..8e4da35 100644 --- a/lib/__specs__/main.spec.ts +++ b/lib/__specs__/main.spec.ts @@ -300,219 +300,3 @@ describe("ExportToCsv", () => { expect(firstLine).toBe("Test Csv 2\r"); }); }); - -describe("ExportToCsv As A Text File", () => { - it("should create a comma seperated string", () => { - const options: ConfigOptions = { - title: "Test Csv 1", - useTextFile: true, - useBom: true, - showColumnHeaders: true, - useKeysAsHeaders: true, - }; - - const string = asString(generateCsv(options)(mockData)); - expect(typeof string === "string").toBeTruthy(); - }); - - it("should use keys of first object in collection as headers", () => { - const options: ConfigOptions = { - filename: "Test Csv 2", - useTextFile: true, - useBom: true, - showColumnHeaders: true, - useKeysAsHeaders: true, - }; - - const output = asString(generateCsv(options)(mockData)); - - const firstLine = output.split("\n")[0]; - const keys = firstLine.split(",").map((s: string) => s.trim()); - - expect(keys).toEqual([ - '"name"', - '"age"', - '"average"', - '"approved"', - '"description"', - '"quotedNumber"', - ]); - }); - - it("should only use columns in columnHeaders", () => { - const options: ConfigOptions = { - filename: "Test Csv 2", - useTextFile: true, - useBom: true, - showColumnHeaders: true, - columnHeaders: ["name", "age"], - }; - - const output = asString(generateCsv(options)(mockData)); - - const firstLine = output.split("\n")[0]; - const keys = firstLine.split(",").map((s: string) => s.trim()); - - expect(keys).toEqual(['"name"', '"age"']); - }); - - it("should allow only headers to be generated", () => { - const options: ConfigOptions = { - filename: "Test Csv 2", - useTextFile: true, - useBom: false, - showColumnHeaders: true, - columnHeaders: ["name", "age"], - }; - - const output = asString(generateCsv(options)([])); - - expect(output).toEqual('"name","age"\r\n'); - }); - - it("should throw when no data supplied", () => { - const options: ConfigOptions = { - filename: "Test Csv 2", - useTextFile: true, - useBom: false, - showColumnHeaders: false, - }; - - expect(() => { - generateCsv(options)([]); - }).toThrow(); - }); - - it("should allow null values", () => { - const options: ConfigOptions = { - filename: "Test Csv 2", - useTextFile: true, - useBom: false, - showColumnHeaders: true, - useKeysAsHeaders: true, - }; - - const output = asString( - generateCsv(options)([ - { - "non-null": 24, - nullish: null, - }, - ]), - ); - - expect(output).toBe('"non-null","nullish"\r\n24,"null"\r\n'); - }); - - it("should convert undefined to empty string by default", () => { - const options: ConfigOptions = { - filename: "Test Csv 2", - useTextFile: true, - useBom: false, - showColumnHeaders: true, - useKeysAsHeaders: true, - }; - - const output = asString( - generateCsv(options)([ - { - car: "toyota", - color: "blue", - }, - { - car: "chevrolet", - }, - ]), - ); - - expect(output).toBe( - '"car","color"\r\n"toyota","blue"\r\n"chevrolet",""\r\n', - ); - }); - - it("should replace undefined with specified value", () => { - const options: ConfigOptions = { - filename: "Test Csv 2", - useTextFile: true, - useBom: false, - showColumnHeaders: true, - useKeysAsHeaders: true, - replaceUndefinedWith: "TEST", - }; - - const output = asString( - generateCsv(options)([ - { - car: "toyota", - color: "blue", - }, - { - car: "chevrolet", - }, - ]), - ); - - expect(output).toBe( - '"car","color"\r\n"toyota","blue"\r\n"chevrolet","TEST"\r\n', - ); - }); - - it("should handle varying data shapes by manually setting column headers", () => { - const options: ConfigOptions = { - filename: "Test Csv 2", - useTextFile: true, - useBom: false, - showColumnHeaders: true, - columnHeaders: ["car", "color", "town"], - }; - - const output = asString( - generateCsv(options)([ - { - car: "toyota", - color: "blue", - }, - { - car: "chevrolet", - }, - { - town: "montreal", - }, - ]), - ); - - expect(output).toBe( - '"car","color","town"\r\n"toyota","blue",""\r\n"chevrolet","",""\r\n"","","montreal"\r\n', - ); - }); - - it("should properly quote headers", () => { - const options: ConfigOptions = { - filename: "Test Csv 2", - useTextFile: true, - useBom: false, - showColumnHeaders: true, - columnHeaders: ["name", "age"], - }; - - const output = asString(generateCsv(options)(mockData)); - const firstLine = output.split("\n")[0]; - - expect(firstLine).toBe('"name","age"\r'); - }); - - it("should put the title on the first line", () => { - const options: ConfigOptions = { - title: "Test Csv 2", - showTitle: true, - useBom: false, - showColumnHeaders: true, - columnHeaders: ["name", "age"], - }; - - const output = asString(generateCsv(options)(mockData)); - const firstLine = output.split("\n")[0]; - - expect(firstLine).toBe("Test Csv 2\r"); - }); -}); From 34d3c9af8116726a0005705536e5bd4246c26207 Mon Sep 17 00:00:00 2001 From: Alex Caza Date: Tue, 9 Apr 2024 20:29:21 -0400 Subject: [PATCH 2/3] Add main test for fieldSeparator --- lib/__specs__/main.spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/__specs__/main.spec.ts b/lib/__specs__/main.spec.ts index 8e4da35..32877a8 100644 --- a/lib/__specs__/main.spec.ts +++ b/lib/__specs__/main.spec.ts @@ -43,6 +43,18 @@ describe("ExportToCsv", () => { expect(typeof string === "string").toBeTruthy(); }); + it("should use fieldSeparator if supplied", () => { + const options: ConfigOptions = { + title: "Test Csv", + useBom: false, + useKeysAsHeaders: true, + fieldSeparator: ";", + }; + + const string = asString(generateCsv(options)([{ test: "hello" }])); + expect(string).toEqual('"test"\r\n"hello"\r\n'); + }); + it("should use keys of first object in collection as headers", () => { const options: ConfigOptions = { title: "Test Csv", From f6a52bfc202cf526f7c85b4e53f25ae4febcaddd Mon Sep 17 00:00:00 2001 From: Alex Caza Date: Tue, 9 Apr 2024 20:29:29 -0400 Subject: [PATCH 3/3] Bump playwright version --- bun.lockb | Bin 21651 -> 22029 bytes flake.lock | 12 ++++++------ package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bun.lockb b/bun.lockb index fd261c7b3752e563f8ab2b2436842118ff597dde..b4dce7dfd2220d09bcdf03216e6adf808cadb0ee 100755 GIT binary patch delta 2427 zcmcImX;_q16u#f^p~E1|06LDyqNH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