1import chalk from 'chalk'; 2import jestExpect from 'expect'; 3 4export function reportMagic({ testName, failed, results, failures }) { 5 const formatResults = (results) => 6 results && 7 results 8 .replace(/---/g, chalk.cyan('---')) 9 .split('+++') 10 .join(chalk.red('+++')) 11 .split(` ${testName} `) 12 .join(chalk.magenta.bold(` ${testName} `)) 13 .replace(/toBe:\s/g, chalk.bold.green('toBe: ')); 14 15 console.log(`\n${chalk.bgMagenta.bold.black(` RESULTS `)}\n\n${formatResults(results)}`); 16 17 if (failed > 0) { 18 console.log(`\n${chalk.bgRed.bold.black(` FAILED `)}\n\n${formatResults(failures)}`); 19 } 20} 21 22export function expectResults({ testName, input }) { 23 const { magic, failed, failures, results } = JSON.parse(input); 24 jestExpect(results).toBeDefined(); 25 26 reportMagic({ 27 testName, 28 failed, 29 results, 30 failures, 31 }); 32 33 jestExpect(magic).toBe('[TEST-SUITE-END]'); 34 jestExpect(failed).toBe(0); 35} 36