question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to use custom mocha ui

See original GitHub issue

Currently it’s impossible to use custom mocha ui. What I want is extra config option which allow to specify which files I want to load before bootstraping mocha (before adapter.js)

var initMocha = function (files, mochaConfig) {
  var mochaPath = path.dirname(require.resolve('mocha'))
  files.unshift(createPattern(__dirname + '/adapter.js'))
  // HERE: I want to iterate over config.mochaFiles and add them right after mocha.js
  files.unshift(createPattern(mochaPath + '/mocha.js'))

  if (mochaConfig && mochaConfig.reporter) {
    files.unshift(createPattern(mochaPath + '/mocha.css'))
  }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
christian-schulzecommented, Jun 25, 2016

@stalniy I’ve had some success getting your https://github.com/stalniy/bdd-lazy-var mocha ui to work by making the following changes to lib/index.js#initMocha:

var initMocha = function (files, mochaConfig) {
  var mochaPath = path.dirname(require.resolve('mocha'))
  var bddLazyVarPath = path.dirname(require.resolve('bdd-lazy-var'))
  files.unshift(createPattern(path.join(__dirname, 'adapter.js')))
  files.unshift(createPattern(path.join(bddLazyVarPath, 'bdd_lazy_var_global.js')))
  files.unshift(createPattern(path.join(mochaPath, 'mocha.js')))

  if (mochaConfig && mochaConfig.reporter) {
    files.unshift(createPattern(path.join(mochaPath, 'mocha.css')))
  }
}

I’ve generalised this solution, by using @dtothefp idea of a require array:

client: {
  mocha: {
    ui: 'my-ui',
    require: [ require.resolve('bdd-lazy-var/bdd_lazy_var_global') ]
  }
}

lib/index.js#initMocha

var initMocha = function (files, mochaConfig) {
  files.unshift(createPattern(path.join(__dirname, 'adapter.js')))

  if (mochaConfig.require) {
    for (var requirePath of mochaConfig.require) {
      files.unshift(createPattern(requirePath));
    }
  }

  var mochaPath = path.dirname(require.resolve('mocha'))
  files.unshift(createPattern(path.join(mochaPath, 'mocha.js')))

  if (mochaConfig && mochaConfig.reporter) {
    files.unshift(createPattern(path.join(mochaPath, 'mocha.css')))
  }
}

Also need to exclude the require array from being sent to mocha in the adapter. Will throw a PR together asap.

0reactions
dtothefpcommented, Feb 13, 2016

Think this is related but it would be nice to have a require option similar to gulp-mocha where we could hook into the --require functionality.

ex.

client: {
  mocha: {
    ui: 'my-ui',
    require: [ path.join(__dirname, 'some-script.js') ]
  }
}

Specifically this would be useful for me to do something like https://labnotes.org/yield-to-the-test-using-mocha-with-es6-generators/ where you could hook into something like mocha.Runnable.prototype.run before instantiation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocha - the fun, simple, flexible JavaScript test framework
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun.
Read more >
Is there a way to start Mocha tests from a React UI?
I am looking for a way to run Mocha either through the web or programmatically. React has made this a bit of a...
Read more >
Allow custom mocha runner interface to be specified
Mocha allows using custom 3rd-party test interfaces (there lots of them) but there is no way to use anything than you have in...
Read more >
Getting Started with Node.js and Mocha - Semaphore Tutorial
Mocha is a simple, extensible and fast testing library for Node.js. This article will walk you through its installation, configuration and usage.
Read more >
Testing Node.js with Mocha and Chai
Mocha does not discriminate, regardless of which assertion library you choose to use. If you're using Mocha in a Node.js environment, you can ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found