8
0

tasks.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. const src = [
  32. 'build/cjs/tests/**/*.js',
  33. '!**/_utils/**/*.js',
  34. '!build/cjs/tests/{ui,ui-*}/**/*.js',
  35. '!build/cjs/tests/theme-*/**/*.js'
  36. ];
  37. return gulp.src( src )
  38. .pipe( tasks.skipManual() )
  39. .pipe( tasks.skipIgnored() )
  40. .pipe( mocha() );
  41. },
  42. /**
  43. * Removes manual test files from source stream. It checks if the markdown file with the same name exists.
  44. *
  45. * @returns {Stream}
  46. */
  47. skipManual() {
  48. return filter( ( file ) => {
  49. return !devTools.isFile( file.path.slice( 0, -3 ) + '.md' );
  50. } );
  51. },
  52. /**
  53. * Skips test files that are marked to be ignored when testing outside browser.
  54. * To ignore file, add `browser-only` to bender-tags comment in test file.
  55. *
  56. * @returns {Stream}
  57. */
  58. skipIgnored() {
  59. return filterBy( file => !file.contents.toString().match( ignoreRegexp ) );
  60. }
  61. };
  62. gulp.task( 'test-editor', tasks.testEditor );
  63. return tasks;
  64. };