Skip to content

Commit ef21e7c

Browse files
committed
update tests for configurable docx export locale
add test cases to ensure the locale option correctly updates default language in generated .docx files and defaults to en-US when omitted
1 parent b4f23cc commit ef21e7c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/xl-docx-exporter/src/docx/docxExporter.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ describe("exporter", () => {
2828
}),
2929
docxDefaultSchemaMappings,
3030
);
31-
const doc = await exporter.toDocxJsDocument(testDocument);
31+
const doc = await exporter.toDocxJsDocument(testDocument, {
32+
sectionOptions: {},
33+
documentOptions: {},
34+
locale: "en-US",
35+
});
3236

3337
const blob = await Packer.toBlob(doc);
3438
const zip = new ZipReader(new BlobReader(blob));
@@ -56,6 +60,7 @@ describe("exporter", () => {
5660
);
5761

5862
const doc = await exporter.toDocxJsDocument(testDocument, {
63+
locale: "en-US",
5964
documentOptions: {
6065
creator: "John Doe",
6166
},
@@ -181,6 +186,7 @@ describe("exporter", () => {
181186
],
182187
},
183188
]),
189+
{ sectionOptions: {}, documentOptions: {}, locale: "en-US" },
184190
);
185191

186192
const blob = await Packer.toBlob(doc);

shared/util/fileUtil.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ export async function loadFileBuffer(requireUrl: {
3636
if (url.startsWith("/@fs/")) {
3737
url = url.substring("/@fs".length);
3838
}
39+
// On Windows, vite/vitest may yield paths like "/C:/..." after removing /@fs
40+
// Node on Windows treats paths starting with "/" as relative to current drive,
41+
// which would produce "C:\C:\...". Strip leading slash when followed by a drive letter.
42+
if (/^\/[A-Za-z]:/.test(url)) {
43+
url = url.slice(1);
44+
}
3945
const buffer = fs.readFileSync(url);
4046
return buffer;
4147
} else {

0 commit comments

Comments
 (0)