Open krzkaczor opened 6 years ago
Hi @krzkaczor. Truffle does expose / consume a mocha
object in truffle.js where you can set mocha options.
The syntax is:
module.exports = {
networks: {
...etc...
},
mocha: {
someOption: <some-value>,
anotherOption: <another-value>
}
};
Truffle just passes mocha this object so anything that usually works with mocha should theoretically be fine. The contract
abstraction aliases describe and passes in accounts and shouldn't interfere with anything.
An example of mocha extensions working ok with truffle is eth-gas-reporter which uses mocha's third-party-reporter feature.
If you have a chance could you see if mocha-prepare
can be enabled through the config?
@krzkaczor Do the mocha options in the config work for your use case? Is this closable?
@cgewecke thanks for your response. So I guess, what I am asking about is: can i run mocha cli (node_modules/.bin/mocha
) with some set of parameters and have the same outcome as running truffle test
. This would be cool since it would allow more easily to integrate with IDEs (things like: run this test only).
@krzkaczor At the moment no - unless you write your own version of what happens at truffle in the test command. That code is mostly here and the key resources injected into the test environment are here. Mocha's also passed the config options object and accounts are injected into contract
test wrapper.
It is possible to write contract.only
or contract.skip
for more a little more control over what tests run.
truffle test
is one of next things on the schedule for a rewrite - I guess I would like to keep this open now. Agree we should try support the use case you identified, along with other test frameworks like jest etc.
Advantages
All advantages that I can see are around tooling support (mostly IDEs and editors). For example, things that would work out of the box if it was pure mocha:
Implementation problems
The biggest problem right now is that without workarounds like mocha-prepare or changes to mocha itself it's impossible to run all required async tasks before running tests itself.
Another problem, of course, is that
truffle
usescontract
functions to describe tests suites instead of relying ondescribe
. I am curious what's the reasoning behind it and could it be easily replaced withdescribe
?Is there any pressure for bringing full compatibility with mocha?