I have a large CSV file that contains inputs and expected outputs for a complex calculation. I would like to use this file as the basis for tests of my calculator written in Node. However, it seems that frameworks like Mocha and Vows expect tests to be output synchronously, not asynchronously, after a CSV file has been read and parsed.
I could work around this by converting the CSV to JSON and including it in my test file, but I would rather use the authoritative CSV file as is, and anyway I'm just curious how to handle this situation. Thanks.
Basic approach now (using csvtojson
):
const cases = [];
csv()
.fromFile('../testdata/test.csv')
.on('json', (rowObj) => {
// convert columns to inputs and expected
cases.push(inputs: inputs, expected: expected);
})
.on('end', () => {
describe('Test cases', function() {
cases.forEach((test) => {
it(`${dynamicCaseName}`, () => {
// do our calculation
assert.equals(ours, test.theirs);
});
});
});
});
Aucun commentaire:
Enregistrer un commentaire