Advertisement
fhumayun

Gulp Selenium

Apr 10th, 2015
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var gulp = require('gulp');
  2. var streamify = require('gulp-streamify');
  3. var uglify = require('gulp-uglify');
  4. var notify = require('gulp-notify');
  5. var gutil = require('gulp-util');
  6. var less = require('gulp-less');
  7. var rename = require('gulp-rename');
  8. var nodemon = require('gulp-nodemon');
  9. var jshint = require('gulp-jshint');
  10. var react = require('gulp-react');
  11. var mocha = require('gulp-mocha');
  12. var selenium = require('gulp-mocha-selenium');
  13. var livereload = require('gulp-livereload');
  14. var browserify = require('browserify');
  15. var watchify = require('watchify');
  16. var babelify = require('babelify');
  17. var source = require('vinyl-source-stream');
  18. var lazypipe = require('lazypipe');
  19.  
  20. var isProduction = process.env.NODE_ENV === 'production';
  21.  
  22. gulp.task('jshint', function () {
  23. gulp.src(['views/*.jsx', 'views/**/*.jsx'])
  24. .pipe(react()) //Must use react as it preserves lines from jsx to js compile
  25. .pipe(streamify(jshint({
  26. laxbreak: true,
  27. laxcomma: true,
  28. es3: true,
  29. esnext: true, //JSHint Harmony/ES6
  30. eqnull: true,
  31. browser: true,
  32. jquery: true
  33. })))
  34. .pipe(jshint.reporter('jshint-stylish'))
  35. });
  36.  
  37. gulp.task('browserify', function () {
  38. watchify(browserify())
  39. .transform(babelify) //JSX and ES6
  40. .require('./views/app.jsx', {entry: true})
  41. .bundle()
  42. .on('error', function(err) {
  43. console.error(err.message);
  44. })
  45. .pipe(source('bundle.js'))
  46. .pipe(isProduction ? streamify(uglify('./built/')) : gutil.noop()) //Noop is empty stream for passthru
  47. .pipe(gulp.dest('./js/built/'))
  48. .pipe(livereload())
  49. .pipe(notify("Rebuilt Website"));
  50. });
  51.  
  52. gulp.task('less', function () {
  53. /**
  54. * LazyPipe is used create streams without initializing them
  55. * until they are used
  56. *
  57. * Never call streams directly
  58. *
  59. * .pipe(gulp.dest('/filepath')) becomes
  60. *
  61. * .pipe(gulp.dest, '/filepath')
  62. */
  63.  
  64. var prodLess = lazypipe()
  65. .pipe(less, {
  66. paths: ['less'],
  67. dumpLineNumbers: false,
  68. compress: true,
  69. cleancss: true,
  70. yuicompress: true
  71. })
  72. .pipe(rename, 'main.min.css')
  73. .pipe(gulp.dest, './css/');
  74.  
  75. var devLess = lazypipe()
  76. .pipe(less, {
  77. paths: ['less'],
  78. dumpLineNumbers: 'all',
  79. compress: false
  80. })
  81. .pipe(gulp.dest, './css/');
  82.  
  83. gulp.src('./less/main.less')
  84. //Use ternary operator for conditional statements
  85. .pipe(isProduction ? prodLess() : devLess())
  86. .pipe(livereload());
  87. });
  88.  
  89. gulp.task('mocha', function () {
  90. gulp.src(['test/*_test.js', 'test/**/*_test.js', '!test/selenium/*_test.js'])
  91. .pipe(mocha({
  92. reporter: 'spec',
  93. ui: 'bdd'
  94. }));
  95.  
  96. });
  97.  
  98. gulp.task('selenium', function () {
  99. gulp.src('test/selenium/*_test.js', {read: false})
  100. .pipe(selenium({
  101. browserName: 'chrome',
  102. reporter: 'spec',
  103. ui: 'bdd',
  104. usePromises: true
  105. }));
  106. });
  107.  
  108. gulp.task('server', function () {
  109. livereload.listen();
  110. nodemon({ script: 'app.js', ext: 'jsx', ignore: [] })
  111. .on('change', ['jshint', 'mocha', 'browserify']) //Only reload jsx on change
  112. });
  113.  
  114. if (isProduction) {
  115. gulp.task('default', ['server']);
  116. } else {
  117. gulp.task('default', ['jshint', 'browserify', 'server']);
  118. }
  119. gulp.task('test', ['jshint', 'mocha', 'selenium']);
  120. gulp.task('build', ['less', 'browserify']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement