Forked from mindstudio/big-rag
Project Files
test-fixtures / generate-fixtures.js
/**
* Generate test fixture files for all supported document formats.
* Run: node test-fixtures/generate-fixtures.js
*/
const fs = require("fs");
const path = require("path");
const JSZip = require("jszip");
const XLSX = require("xlsx");
const OUT_DIR = path.join(__dirname);
async function generateDocx() {
const zip = new JSZip();
// [Content_Types].xml
zip.file("[Content_Types].xml",
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">' +
'<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>' +
'<Default Extension="xml" ContentType="application/xml"/>' +
'<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>' +
'</Types>'
);
// _rels/.rels
zip.file("_rels/.rels",
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>' +
'</Relationships>'
);
// word/document.xml
zip.file("word/document.xml",
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">' +
'<w:body>' +
'<w:p><w:r><w:t>Big RAG DOCX test paragraph one.</w:t></w:r></w:p>' +
'<w:p><w:r><w:t>Second paragraph with more content for testing.</w:t></w:r></w:p>' +
'</w:body>' +
'</w:document>'
);
const buf = await zip.generateAsync({ type: "nodebuffer" });
fs.writeFileSync(path.join(OUT_DIR, "sample.docx"), buf);
console.log("✅ sample.docx");
}
async function generatePptx() {
const zip = new JSZip();
// [Content_Types].xml
zip.file("[Content_Types].xml",
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">' +
'<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>' +
'<Default Extension="xml" ContentType="application/xml"/>' +
'<Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/>' +
'<Override PartName="/ppt/slides/slide1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>' +
'<Override PartName="/ppt/slides/slide2.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>' +
'</Types>'
);
// _rels/.rels
zip.file("_rels/.rels",
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="ppt/presentation.xml"/>' +
'</Relationships>'
);
// ppt/_rels/presentation.xml.rels
zip.file("ppt/_rels/presentation.xml.rels",
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide1.xml"/>' +
'<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide2.xml"/>' +
'</Relationships>'
);
// ppt/presentation.xml
zip.file("ppt/presentation.xml",
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<p:presentation xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">' +
'<p:sldIdLst>' +
'<p:sldId id="256" r:id="rId1"/>' +
'<p:sldId id="257" r:id="rId2"/>' +
'</p:sldIdLst>' +
'</p:presentation>'
);
// ppt/slides/slide1.xml
zip.file("ppt/slides/slide1.xml",
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">' +
'<p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/></p:nvGrpSpPr>' +
'<p:sp><p:txBody><a:p><a:r><a:t>Big RAG PPTX slide one content for testing.</a:t></a:r></a:p></p:txBody></p:sp>' +
'</p:spTree></p:cSld>' +
'</p:sld>'
);
// ppt/slides/slide2.xml
zip.file("ppt/slides/slide2.xml",
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">' +
'<p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/></p:nvGrpSpPr>' +
'<p:sp><p:txBody><a:p><a:r><a:t>Second slide with additional text data.</a:t></a:r></a:p></p:txBody></p:sp>' +
'</p:spTree></p:cSld>' +
'</p:sld>'
);
const buf = await zip.generateAsync({ type: "nodebuffer" });
fs.writeFileSync(path.join(OUT_DIR, "sample.pptx"), buf);
console.log("✅ sample.pptx");
}
function generateXlsx() {
const wb = XLSX.utils.book_new();
const data = [
["Name", "Value", "Description"],
["Test Row 1", "100", "First test row for Big RAG"],
["Test Row 2", "200", "Second test row for parsing"],
];
const ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
XLSX.writeFile(wb, path.join(OUT_DIR, "sample.xlsx"));
console.log("✅ sample.xlsx");
}
function generateCsv() {
const csv = [
"Name,Value,Description",
"CSV Row 1,100,First CSV test row",
"CSV Row 2,200,Second CSV test row",
].join("\n");
fs.writeFileSync(path.join(OUT_DIR, "sample.csv"), csv, "utf-8");
console.log("✅ sample.csv");
}
async function main() {
console.log("Generating test fixtures...");
await generateDocx();
await generatePptx();
generateXlsx();
generateCsv();
console.log("\nAll fixtures generated in test-fixtures/");
}
main().catch((err) => {
console.error("Error generating fixtures:", err);
process.exit(1);
});