import * as _ from "lodash"; import * as fs from "fs-extra"; export const generateComponentTestTsx = (data: any) => { const { filteredComponents, componentFolder, templateFolder } = data; // loop over array of components _.forEach(filteredComponents, (component) => { // grab [tests] from the item in the loop const tests = component["tests"]; // loop through it and build an [it_block] fs.readFile( `${templateFolder}/components/component.template/Component.test.tsx.template`, "utf8", (err, data) => { if (err) return console.error(err); // loop through test_plan and build an [it_block] const templateString = " test.skip(`<%= test %>`, () => {})" + "\n"; const it_block = _.join( _.map(tests, (test) => _.template(templateString)({ test: test["it"] }) ), "\n" ); // pass [name] & [it_block] to Component.test.tsx.template const ComponentTestTsx = _.template(data)({ name: component["name"], it_block, }); // save result to {outFolder}/components/{[Name]}/[Name].test.tsx fs.outputFile( `${componentFolder}/${component["name"]}/${component["name"]}.test.tsx`, ComponentTestTsx ); } ); }); };