check-coverage.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // To expose files variable to out of eval scope, we need var statement, not const.
  14. eval( fs.readFileSync( './examples/files.js' )
  15. .toString().replace( 'const files', 'var files' ) );
  16. for ( const key in files ) {
  17. const section = files[ key ];
  18. for ( let i = 0, len = section.length; i < len; i ++ ) {
  19. F.push( section[ i ] );
  20. }
  21. }
  22. let subES = E.filter( x => ! S.includes( x ) );
  23. let subSE = S.filter( x => ! E.includes( x ) );
  24. let subEF = E.filter( x => ! F.includes( x ) );
  25. let subFE = F.filter( x => ! E.includes( x ) );
  26. console.green = ( msg ) => console.log( `\x1b[32m${ msg }\x1b[37m` );
  27. console.red = ( msg ) => console.log( `\x1b[31m${ msg }\x1b[37m` );
  28. if ( subES.length + subSE.length + subEF.length + subFE.length === 0 ) {
  29. console.green( 'TEST PASSED! All examples is covered with screenshots and descriptions in files.js!' );
  30. } else {
  31. if ( subES.length > 0 ) console.red( 'Make screenshot for example(s): ' + subES.join( ' ' ) );
  32. if ( subSE.length > 0 ) console.red( 'Remove unnecessary screenshot(s): ' + subSE.join( ' ' ) );
  33. if ( subEF.length > 0 ) console.red( 'Add description in file.js for example(s): ' + subEF.join( ' ' ) );
  34. if ( subFE.length > 0 ) console.red( 'Remove description in file.js for example(s): ' + subFE.join( ' ' ) );
  35. console.red( 'TEST FAILED!' );
  36. process.exit( 1 );
  37. }