Truffle: No way to provide mocha command-line options

Created on 5 Feb 2017  Â·  8Comments  Â·  Source: trufflesuite/truffle

  • [x] I've asked for help in the Truffle Gitter before filing this issue.

Issue

The way that truffle runs mocha disallows babel-core/register and babel-polyfill (needed for async/await, e.g.). This functionality cannot be achieved with mocha's programmatic options.

truffle test used to provide -- as a way to pass arguments to mocha, iirc. That appears to not be possible any more.

Steps to Reproduce

truffle test -- --compilers js:babel-core/register

I am using a babel config of:

{
  "presets": [
    "es2015"
  ],
  "plugins": [
    "transform-async-to-generator"
  ]
}

Expected Behavior

Tests should run with babel's runtime transformations.

Actual Results

Using network 'development'.

  0 passing (1ms)

Possible Solution

Presumably being able to pass command line arguments through to mocha would fix the issue, so that truffle test would behave like mocha --compilers js:babel-core/register.

Alternatively, adding these two lines of code to truffle's ./cli.js solves the problem:

require('babel-core/register')
require('babel-polyfill')

Obviously not every user wants this, so it would have to be conditional. What would be the best way to re-enable this functionality? Thanks!

Environment

  • Operating System: OSX
  • Truffle version: 3.1.1
  • Ethereum client: N/A
  • node version: 7.0.4
  • npm version: 4.0.5

Most helpful comment

Also, Truffle doesn't call mocha via the command line. Instead, it does it
programmatically. You can alter the mocha configuration via the mocha key
in your Truffle configuration file.
http://truffleframework.com/docs/advanced/configuration#mocha

On Feb 5, 2017 1:22 PM, "Tim Coulter" tim@timothyjcoulter.com wrote:

Have your tried adding the babel-register require in your truffle.js
file? Truffle relied on babel previously but it caused more harm than good.
I'd prefer not making babel a dependency of Truffle.

On Feb 5, 2017 12:52 PM, "Raine Revere" notifications@github.com wrote:

>


Issue

The way that truffle runs mocha disallows babel-core/register and
babel-polyfill (needed for async/await, e.g.). This functionality cannot
be achieved with mocha's programmatic options
https://github.com/mochajs/mocha/issues/1220.

truffle test used to provide -- as a way to pass arguments to mocha,
iirc. That appears to not be possible any more.
Steps to Reproduce

truffle test -- --compilers js:babel-core/register

I am using a babel config of:

{
"presets": [
"es2015"
],
"plugins": [
"transform-async-to-generator"
]
}

Expected Behavior

Tests should run with babel's runtime transformations.
Actual Results

Using network 'development'.

0 passing (1ms)

Possible Solution

Presumably being able to pass command line arguments through to mocha
would fix the issue, so that truffle test would behave like mocha
--compilers js:babel-core/register.

Alternatively, adding these two lines of code to truffle's ./cli.js
solves the problem:

require('babel-core/register')require('babel-polyfill')

Obviously not every user wants this, so it would have to be conditional.
What would be the best way to re-enable this functionality? Thanks!
Environment

  • Operating System: OSX
  • Truffle version: 3.1.1
  • Ethereum client: N/A
  • node version: 7.0.4
  • npm version: 4.0.5

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/ConsenSys/truffle/issues/346, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFp1Tbhgs19QBckKJcC_pm_JtI3aPOFks5rZjaogaJpZM4L3n16
.

All 8 comments

Have your tried adding the babel-register require in your truffle.js
file? Truffle relied on babel previously but it caused more harm than good.
I'd prefer not making babel a dependency of Truffle.

On Feb 5, 2017 12:52 PM, "Raine Revere" notifications@github.com wrote:

>


Issue

The way that truffle runs mocha disallows babel-core/register and
babel-polyfill (needed for async/await, e.g.). This functionality cannot
be achieved with mocha's programmatic options
https://github.com/mochajs/mocha/issues/1220.

truffle test used to provide -- as a way to pass arguments to mocha,
iirc. That appears to not be possible any more.
Steps to Reproduce

truffle test -- --compilers js:babel-core/register

I am using a babel config of:

{
"presets": [
"es2015"
],
"plugins": [
"transform-async-to-generator"
]
}

Expected Behavior

Tests should run with babel's runtime transformations.
Actual Results

Using network 'development'.

0 passing (1ms)

Possible Solution

Presumably being able to pass command line arguments through to mocha
would fix the issue, so that truffle test would behave like mocha
--compilers js:babel-core/register.

Alternatively, adding these two lines of code to truffle's ./cli.js
solves the problem:

require('babel-core/register')require('babel-polyfill')

Obviously not every user wants this, so it would have to be conditional.
What would be the best way to re-enable this functionality? Thanks!
Environment

  • Operating System: OSX
  • Truffle version: 3.1.1
  • Ethereum client: N/A
  • node version: 7.0.4
  • npm version: 4.0.5

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/ConsenSys/truffle/issues/346, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFp1Tbhgs19QBckKJcC_pm_JtI3aPOFks5rZjaogaJpZM4L3n16
.

Also, Truffle doesn't call mocha via the command line. Instead, it does it
programmatically. You can alter the mocha configuration via the mocha key
in your Truffle configuration file.
http://truffleframework.com/docs/advanced/configuration#mocha

On Feb 5, 2017 1:22 PM, "Tim Coulter" tim@timothyjcoulter.com wrote:

Have your tried adding the babel-register require in your truffle.js
file? Truffle relied on babel previously but it caused more harm than good.
I'd prefer not making babel a dependency of Truffle.

On Feb 5, 2017 12:52 PM, "Raine Revere" notifications@github.com wrote:

>


Issue

The way that truffle runs mocha disallows babel-core/register and
babel-polyfill (needed for async/await, e.g.). This functionality cannot
be achieved with mocha's programmatic options
https://github.com/mochajs/mocha/issues/1220.

truffle test used to provide -- as a way to pass arguments to mocha,
iirc. That appears to not be possible any more.
Steps to Reproduce

truffle test -- --compilers js:babel-core/register

I am using a babel config of:

{
"presets": [
"es2015"
],
"plugins": [
"transform-async-to-generator"
]
}

Expected Behavior

Tests should run with babel's runtime transformations.
Actual Results

Using network 'development'.

0 passing (1ms)

Possible Solution

Presumably being able to pass command line arguments through to mocha
would fix the issue, so that truffle test would behave like mocha
--compilers js:babel-core/register.

Alternatively, adding these two lines of code to truffle's ./cli.js
solves the problem:

require('babel-core/register')require('babel-polyfill')

Obviously not every user wants this, so it would have to be conditional.
What would be the best way to re-enable this functionality? Thanks!
Environment

  • Operating System: OSX
  • Truffle version: 3.1.1
  • Ethereum client: N/A
  • node version: 7.0.4
  • npm version: 4.0.5

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/ConsenSys/truffle/issues/346, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFp1Tbhgs19QBckKJcC_pm_JtI3aPOFks5rZjaogaJpZM4L3n16
.

It works! 😃

Yay! I need to write docs for this use case...

On Feb 5, 2017 1:40 PM, "Raine Revere" notifications@github.com wrote:

Closed #346 https://github.com/ConsenSys/truffle/issues/346.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/ConsenSys/truffle/issues/346#event-949567922, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAFp1RtgvE7qQvdIqAIlWD-XRjNH63L0ks5rZkHigaJpZM4L3n16
.

@raineorshine
Hi. can you please provide the truffle.js, or any configuration files that worked for you?

@tomerweisman Here's an example that tells mocha to consume a third-party reporter. Equivalent to:

mocha --reporter <reporter-name> --reporter-options <options>
module.exports = {
  networks: {
    ...etc...
  },
  mocha: {
    reporter: 'super-test',
    reporterOptions : {
      extraEmojis: false,
    }
  }
};

@cgewecke this for the example. my problem is that I cant get truffle (mocha) to recognize ES6 "import" syntax.
Ive added the following dependencies in package.json:
"devDependencies": { "babel-polyfill": "^6.26.0", "babel-preset-es2015": "^6.24.1", "babel-preset-stage-2": "^6.24.1", "babel-preset-stage-3": "^6.24.1", "babel-register": "^6.26.0", "solidity-coverage": "^0.5.0" }

and have this .babelrc file:
{ "presets": ["es2015", "stage-2", "stage-3"] }

and truffle-config.js file:
require('babel-register')({ ignore: /node_modules\/(?!zeppelin-solidity)/ }); require('babel-polyfill');

Truffle v4.1.8 (core: 4.1.8)
Solidity v0.4.23 (solc-js)

I wanted @raineorshine to share the config files that worked for her
Any idea how to solve?

thanks

Hey @tomerweisman - thanks so much - your truffle-config.js example totally allowed me to do the same thing you're after!

I have the same .babelrc and package.json files, but placed the require('babel.. in truffle.js instead.

Try changing zeppelin-solidity to openzeppelin-solidity as well.

Thanks again!

Was this page helpful?
0 / 5 - 0 ratings