Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating to Gulp 4: Running into Issues with gulp-mocha tests #193

Open
poorejc opened this issue Jan 13, 2019 · 0 comments
Open

Migrating to Gulp 4: Running into Issues with gulp-mocha tests #193

poorejc opened this issue Jan 13, 2019 · 0 comments

Comments

@poorejc
Copy link

poorejc commented Jan 13, 2019

Hello,

Have been running gulp-mocha 6.0.0/gulp 3.9.1 on script builds--tests ran well. However, gulp 3.9.1 dependencies have (minimatch) ReDOS vulnerabilities. Updating to Gulp 4 (including moving away from gulp-utils) to resolve. After my update, my gulp-mocha tests aren't running, printing, although artifacts from my builds are being generated to expectations. If you can help me spot any obvious errors (syntax or otherwise), that would be super helpful. Below is a before and after:

gulpfile with Gulp 3.9.1 (successful tests)

...
const mocha = require('gulp-mocha');
const babel = require('babel-register');
const gulp = require('gulp');
const gutil = require('gulp-util')
...

// Test
gulp.task('test', ['build', 'lint'], function() {
  return gulp.src('test/**/*_spec.js', { read : false })
    .pipe(mocha({
      compilers : 'js:babel-core/register'
    }))
    .on('error', function(err) {
      gutil.log(err);
      this.emit('end');
    });
});

// Development mode
gulp.task('dev', ['clean', 'test'], function() {
  gulp.watch(['src/**/*.js', 'test/**/*.{js,html}'], ['test']);
});

Output

(node:3916) DeprecationWarning: "--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info
  attachHandlers
    ✓ attaches all the event handlers without duplicates
    ✓ debounces bufferedEvents (505ms)
    defineDetails
      - configures high detail events correctly

  configure
    ✓ merges new configs into main config object
    ✓ includes a userid if present in the window.location
    getUserIdFromParams
      ✓ fetches userId from URL params
      ✓ returns null if no matching param

  getInitialSettings
    timeStampScale
      ✓ no event.timestamp
      ✓ zero
      ✓ epoch milliseconds
      ✓ epoch microseconds
      ✓ performance navigation time
    getInitialSettings
      ✓ fetches all settings from a script tag (101ms)
      ✓ grabs user id from params

  Userale API
    ✓ provides configs
    ✓ edits configs
    ✓ starts + stops (216ms)
    ✓ sends custom logs

  packageLogs
    setLogFilter
      ✓ assigns the handler to the provided value
      ✓ allows the handler to be nulled
    setLogMapper
      ✓ assigns the handler to the provided value
      ✓ allows the handler to be nulled
    packageLog
      ✓ only executes if on
      ✓ calls detailFcn with the event as an argument if provided
      ✓ packages logs
      ✓ filters logs when a handler is assigned and returns false
      ✓ assigns logs to the mapper's return value if a handler is assigned
      ✓ does not call the map handler if the log is filtered out
      ✓ does not attempt to call a non-function filter/mapper
    extractTimeFields
      ✓ returns the millisecond and microsecond portions of a timestamp
      ✓ sets micro to 0 when no decimal is present
      ✓ always returns an object
    getLocation
      ✓ returns event page location
      ✓ calculates page location if unavailable
      ✓ fails to null
    selectorizePath
      ✓ returns a new array of the same length provided
    getSelector
      ✓ builds a selector
      ✓ identifies window
      ✓ handles a non-null unknown value
    buildPath
      ✓ builds a path
      ✓ defaults to path if available

  sendLogs
    ✓ sends logs on an interval
    ✓ does not send logs if the config is off
    ✓ sends logs on page exit with navigator
    ✓ sends logs on page exit without navigator
    ✓ does not send logs on page exit if config is off


  45 passing (951ms)
  1 pending

[23:03:15] Finished 'test' after 3.29 s

gulpfile mods for Gulp 4 (substituing gulplog for gulp-utils)

const mocha = require('gulp-mocha');
const babel = require('babel-register');
const gulp = require('gulp');
const log = require('gulplog')

// Test
gulp.task('test', gulp.series(['build', 'lint']), function() {
  return gulp.src('test/**/*_spec.js', { read : false })
    .pipe(mocha({
      reporter: 'list',
      require: ['babel-core/register']
    }))
    .on('error', function(err) {
      log.error(err);
      this.emit('end');
    });
});

// Development mode
gulp.task('dev', gulp.series(['clean', 'test']), function() {
  gulp.watch(['src/**/*.js', 'test/**/*.{js,html}'], gulp.series(['test']));
});

I get no output. Tests finish too fast--likely not running and printing errors. See any obvious mistakes? Source, tests, and full gulpfile can be found here: https://github.com/apache/incubator-senssoft-useralejs/tree/SENSSOFT-192

I see that devDependencies for gulp-mocha list 3.9.1, but Gulp is posting recipes with gulp-mocha in Gulp 4 syntax (https://gulpjs.org/recipes/mocha-test-runner-with-gulp.html), so I figured gulp-mocha would work with syntax mods... Plz let me know if that is not the case.

Thnx

-J

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant