import * as _ from "lodash"; import * as fs from "fs-extra"; export const generateAPIIndexTestTs = (data: any) => { const { api, apiFolder, templateFolder } = data; // loop over array of components _.forEach(api, apiClass => { // grab [tests] from the item in the loop const tests = apiClass["tests"]; // loop through it and build an [it_block] fs.readFile( `${templateFolder}/api/class.template/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 %>`, () => {})" + "\n"; const it_block = _.join( _.map(tests, test => _.template(templateString)({ test: test["it"] }) ), "\n" ); // pass [name] & [it_block] to Component.test.ts.template const IndexTestTs = _.template(data)({ name: apiClass["name"], it_block }); // save result to {outFolder}/api/{[Name]}/index.test.ts fs.outputFile( `${apiFolder}/${apiClass["name"]}/index.test.ts`, IndexTestTs ); } ); }); };