check-coverage.js 1.5 KB

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