check-coverage.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @author munrocket / https://github.com/munrocket
  3. */
  4. const fs = require( 'fs' );
  5. // examples
  6. const E = fs.readdirSync( './examples' )
  7. .filter( s => s.slice( - 5 ) === '.html' )
  8. .map( s => s.slice( 0, s.length - 5 ) )
  9. .filter( f => f !== 'index' );
  10. // screenshots
  11. const S = fs.readdirSync( './examples/screenshots' )
  12. .filter( s => s.slice( - 4 ) === '.png' )
  13. .map( s => s.slice( 0, s.length - 4 ) )
  14. // files.js
  15. const F = [];
  16. eval( fs.readFileSync( './examples/files.js' ).toString() );
  17. for ( var key in files ) {
  18. var section = files[ key ];
  19. for ( var i = 0, len = section.length; i < len; i ++ ) {
  20. F.push( section[ i ] );
  21. }
  22. }
  23. let subES = E.filter( x => ! S.includes( x ) );
  24. let subSE = S.filter( x => ! E.includes( x ) );
  25. let subEF = E.filter( x => ! F.includes( x ) );
  26. let subFE = F.filter( x => ! E.includes( x ) );
  27. console.green = ( msg ) => console.log( `\x1b[32m${ msg }\x1b[37m` );
  28. console.red = ( msg ) => console.log( `\x1b[31m${ msg }\x1b[37m` );
  29. if ( subES.length + subSE.length + subEF.length + subFE.length === 0 ) {
  30. console.green( 'TEST PASSED! All examples is covered with screenshots and descriptions in files.js!' );
  31. } else {
  32. if ( subES.length > 0 ) console.red( 'Add screenshots for example(s): ' + subES.join(' ') );
  33. if ( subSE.length > 0 ) console.red( 'Remove unnecessary screenshot(s): ' + subSE.join(' ') );
  34. if ( subEF.length > 0 ) console.red( 'Add description in file.js for example(s): ' + subEF.join(' ') );
  35. if ( subFE.length > 0 ) console.red( 'Remove description in file.js for example(s): ' + subFE.join(' ') );
  36. console.red( 'TEST FAILED!' );
  37. process.exit( 1 );
  38. }