check-coverage.js 1.6 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. const files = JSON.parse( fs.readFileSync( './examples/files.json' ) );
  14. for ( const key in files ) {
  15. const section = files[ key ];
  16. for ( let i = 0, len = section.length; i < len; i ++ ) {
  17. F.push( section[ i ] );
  18. }
  19. }
  20. const subES = E.filter( x => ! S.includes( x ) );
  21. const subSE = S.filter( x => ! E.includes( x ) );
  22. const subEF = E.filter( x => ! F.includes( x ) );
  23. const 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. }