1
0

check-coverage.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import * as fs from 'fs/promises';
  2. console.red = msg => console.log( `\x1b[31m${msg}\x1b[39m` );
  3. console.green = msg => console.log( `\x1b[32m${msg}\x1b[39m` );
  4. main();
  5. async function main() {
  6. // examples
  7. const E = ( await fs.readdir( 'examples' ) )
  8. .filter( s => s.endsWith( '.html' ) )
  9. .map( s => s.slice( 0, s.indexOf( '.' ) ) )
  10. .filter( f => f !== 'index' );
  11. // screenshots
  12. const S = ( await fs.readdir( 'examples/screenshots' ) )
  13. .filter( s => s.indexOf( '.' ) !== - 1 )
  14. .map( s => s.slice( 0, s.indexOf( '.' ) ) );
  15. // files.js
  16. const F = [];
  17. const files = JSON.parse( await fs.readFile( 'examples/files.json' ) );
  18. for ( const section of Object.values( files ) ) {
  19. F.push( ...section );
  20. }
  21. const subES = E.filter( x => ! S.includes( x ) );
  22. const subSE = S.filter( x => ! E.includes( x ) );
  23. const subEF = E.filter( x => ! F.includes( x ) );
  24. const subFE = F.filter( x => ! E.includes( x ) );
  25. if ( subES.length + subSE.length + subEF.length + subFE.length === 0 ) {
  26. console.green( 'TEST PASSED! All examples is covered with screenshots and descriptions in files.json!' );
  27. } else {
  28. if ( subES.length > 0 ) console.red( 'Make screenshot for example(s): ' + subES.join( ' ' ) );
  29. if ( subSE.length > 0 ) console.red( 'Remove unnecessary screenshot(s): ' + subSE.join( ' ' ) );
  30. if ( subEF.length > 0 ) console.red( 'Add description in files.json for example(s): ' + subEF.join( ' ' ) );
  31. if ( subFE.length > 0 ) console.red( 'Remove description in files.json for example(s): ' + subFE.join( ' ' ) );
  32. console.red( 'TEST FAILED!' );
  33. process.exit( 1 );
  34. }
  35. }
粤ICP备19079148号