8
0

tasks.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* jshint node: true, esnext: true */
  2. 'use strict';
  3. const gulp = require( 'gulp' );
  4. const mocha = require( 'gulp-mocha' );
  5. const chai = require( 'chai' );
  6. const filterBy = require( 'gulp-filter-by' );
  7. const filter = require( 'gulp-filter' );
  8. const sinon = require( 'sinon' );
  9. const minimist = require( 'minimist' );
  10. const devTools = require( '../dev/utils/tools' );
  11. module.exports = () => {
  12. const ignoreRegexp = /\/\* ?bender-tags:.*\bbrowser-only\b.*\*\//;
  13. // Inject globals before running tests.
  14. global.should = chai.should;
  15. global.expect = chai.expect;
  16. global.assert = chai.assert;
  17. global.sinon = sinon;
  18. const tasks = {
  19. testEditor() {
  20. const options = minimist( process.argv.slice( 2 ), {
  21. boolean: [ 'node' ],
  22. default: {
  23. 'node': false
  24. }
  25. } );
  26. if ( options.node ) {
  27. return tasks.testInNode();
  28. }
  29. },
  30. testInNode() {
  31. return gulp.src( 'dist/cjs/tests/**/*.js' )
  32. .pipe( tasks.skipManual() )
  33. .pipe( tasks.skipIgnored() )
  34. .pipe( mocha() );
  35. },
  36. /**
  37. * Removes manual test files from source stream. It checks if the markdown file with the same name exists.
  38. *
  39. * @returns {Stream}
  40. */
  41. skipManual() {
  42. return filter( ( file ) => {
  43. return !devTools.isFile( file.path.slice( 0, -3 ) + '.md' );
  44. } );
  45. },
  46. /**
  47. * Skips test files that are marked to be ignored when testing outside browser.
  48. * To ignore file, add `browser-only` to bender-tags comment in test file.
  49. *
  50. * @returns {Stream}
  51. */
  52. skipIgnored() {
  53. return filterBy( file => !file.contents.toString().match( ignoreRegexp ) );
  54. }
  55. };
  56. gulp.task( 'test-editor', tasks.testEditor );
  57. return tasks;
  58. };