import * as _ from "lodash"; import * as fs from "fs-extra"; export const generateIndexTestTs = (data: any) => { const { name, test_plan, outputFolder, templateFolder } = data; // grab [name] from json // grab [test_plan] from json fs.readFile( `${templateFolder}/index.test.ts.template`, "utf8", (err, data) => { if (err) return console.error(err); // loop through test_plan and build an [it_block] const templateString = " it(`<%= test['scenario'] %>: <%= test['expected'] %>`, () => {})" + "\n"; const it_block = _.join( _.map(test_plan, test => _.template(templateString)({ test })), "\n" ); // pass [name] & [it_block] to index.test.ts.template const indexTestTs = _.template(data)({ name, it_block }); // save result to {outFolder}/index.test.ts fs.outputFile(`${outputFolder}/index.test.ts`, indexTestTs); } ); };