check-coverage.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import chalk from 'chalk';
  2. import * as fs from 'fs/promises';
  3. console.red = msg => console.log( chalk.red( msg ) );
  4. console.green = msg => console.log( chalk.green( msg ) );
  5. main();
  6. async function main() {
  7. // examples
  8. const E = ( await fs.readdir( 'examples' ) )
  9. .filter( s => s.endsWith( '.html' ) )
  10. .map( s => s.slice( 0, s.indexOf( '.' ) ) )
  11. .filter( f => f !== 'index' );
  12. // screenshots
  13. const S = ( await fs.readdir( 'examples/screenshots' ) )
  14. .filter( s => s.indexOf( '.' ) !== -1 )
  15. .map( s => s.slice( 0, s.indexOf( '.' ) ) );
  16. // files.js
  17. const F = [];
  18. const files = JSON.parse( await fs.readFile( 'examples/files.json' ) );
  19. for ( const section of Object.values( files ) ) {
  20. F.push( ...section );
  21. }
  22. const subES = E.filter( x => ! S.includes( x ) );
  23. const subSE = S.filter( x => ! E.includes( x ) );
  24. const subEF = E.filter( x => ! F.includes( x ) );
  25. const subFE = F.filter( x => ! E.includes( x ) );
  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.json!' );
  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 files.json for example(s): ' + subEF.join( ' ' ) );
  32. if ( subFE.length > 0 ) console.red( 'Remove description in files.json for example(s): ' + subFE.join( ' ' ) );
  33. console.red( 'TEST FAILED!' );
  34. process.exit( 1 );
  35. }
  36. }