Commit 30566b0a authored by Tomáš Hübelbauer's avatar Tomáš Hübelbauer

Add basic Excel test

parent aa8aab19
......@@ -4,7 +4,9 @@ import os from 'os';
import path from 'path';
import child_process from 'child_process';
import util from 'util';
import testWordBasic from './tests/word-basic';
import testExcelBasic from './tests/excel-basic';
const mkdtemp = util.promisify(fs.mkdtemp);
const exec = util.promisify(child_process.exec);
......@@ -12,6 +14,7 @@ const exec = util.promisify(child_process.exec);
async function test() {
console.log('Running Office tests…\n');
await run(testWordBasic, 'docx', 'Word - basic');
await run(testExcelBasic, 'xlsx', 'Excel - basic');
// TODO: Add more tests.
}
......
import fs from 'fs';
import util from 'util';
import path from 'path';
const readFile = util.promisify(fs.readFile);
export default function(excel) {
const s1 = excel.makeNewSheet('sheet1');
s1.setCell('A1', 'Hello,');
s1.setCell('B2', 'World!');
const s2 = excel.makeNewSheet('sheet2');
s1.setCell('C3', 'Hi,');
s1.setCell('D4', 'here');
s1.setCell('D4', 'there');
return async (dir) => {
const spans = String(await readFile(path.join(dir, 'xl/sharedStrings.xml.txt'))).split('\n');
if (spans[1] !== 'Hello,' || spans[2] !== 'World!' || spans[3] !== 'Hi,' || spans[4] !== 'there' || spans[5] !== '\r') {
throw new Error('The resulting TXT file did not have matching spans to what was inserted.');
}
};
}
......@@ -18,5 +18,5 @@ export default function(word) {
if (spans[1] !== 'Hello,' || spans[2] !== 'World!' || spans[3] !== 'Hi,' || spans[4] !== 'it is me, Tom!' || spans[5] !== '\r') {
throw new Error('The resulting TXT file did not have matching spans to what was inserted.');
}
}
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment