Skip to content

Commit 770a23d

Browse files
authored
Merge pull request #90 from champierre/issue-83
xlsx-to-csv postprocess で*.xlsγ‚‚csvγ«ε€‰ζ›γ§γγ‚‹γ‚ˆγ†γ«γ™γ‚‹γ€‚
2 parents 056e3c7 + aa46704 commit 770a23d

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

β€Žlibs/postprocess/xlsx_to_csv_converter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class XlsxToCsvConverter extends BasePostprocess {
66
const workbook = await readXLSX(targetPath);
77
const sheetData = workbook.Sheets[workbook.SheetNames[0]];
88
const csv = xlsx.utils.sheet_to_csv(sheetData);
9-
Deno.writeTextFileSync(targetPath.replace(/\.xlsx$/, ".csv"), csv);
9+
Deno.writeTextFileSync(targetPath.replace(/\.xlsx?$/, ".csv"), csv);
1010
return targetPath;
1111
}
1212
validate(argumentList: string[]) {

β€Žtests/libs/actions.install.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,56 @@ describe("InstallAction", () => {
555555
}
556556
});
557557

558+
it('convert downloaded file from xls to csv and record in dim.json and dim-lock.json when specify "xlsx-to-csv" as postProcesses', async () => {
559+
createEmptyDimJson();
560+
const testXlsx = Deno.readFileSync("../test_data/test.xls");
561+
const kyGetStub = createKyGetStub(testXlsx);
562+
try {
563+
await new InstallAction().execute(
564+
{ name: "xlsx-to-csv", postProcesses: ["xlsx-to-csv"] },
565+
"https://example.com/dummy.xls",
566+
);
567+
assert(fileExists("data_files/xlsx-to-csv/dummy.xls"));
568+
const testData = Deno.readTextFileSync(
569+
"data_files/xlsx-to-csv/dummy.csv",
570+
);
571+
assertEquals(testData, "a,b\nc,d\ne,f\n");
572+
assertSpyCall(consoleLogStub, 0, { args: ["Convert xlsx to csv."] });
573+
const dimJson = JSON.parse(Deno.readTextFileSync("dim.json"));
574+
assertEquals(dimJson, {
575+
fileVersion: "1.1",
576+
contents: [{
577+
catalogResourceId: null,
578+
catalogUrl: null,
579+
headers: {},
580+
name: "xlsx-to-csv",
581+
postProcesses: ["xlsx-to-csv"],
582+
url: "https://example.com/dummy.xls",
583+
}],
584+
});
585+
586+
const dimLockJson = JSON.parse(Deno.readTextFileSync("dim-lock.json"));
587+
assertEquals(dimLockJson, {
588+
lockFileVersion: "1.1",
589+
contents: [{
590+
catalogResourceId: null,
591+
catalogUrl: null,
592+
eTag: null,
593+
headers: {},
594+
integrity: "",
595+
lastDownloaded: "2022-01-02T03:04:05.678Z",
596+
lastModified: null,
597+
name: "xlsx-to-csv",
598+
path: "./data_files/xlsx-to-csv/dummy.xls",
599+
postProcesses: ["xlsx-to-csv"],
600+
url: "https://example.com/dummy.xls",
601+
}],
602+
});
603+
} finally {
604+
kyGetStub.restore();
605+
}
606+
});
607+
558608
it('exit with error when specify "xlsx-to-csv a" as postProcesses and download', async () => {
559609
createEmptyDimJson();
560610
const kyGetStub = createKyGetStub("dummy");

β€Žtests/test_data/test.xls

25 KB
Binary file not shown.

0 commit comments

Comments
Β (0)