Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Mocha compatibility #1228

Open
krzkaczor opened this issue Aug 25, 2018 · 4 comments
Open

Mocha compatibility #1228

krzkaczor opened this issue Aug 25, 2018 · 4 comments

Comments

@krzkaczor
Copy link

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:

  • support for seeing test results directly in your IDE with VS Code (plugins) or webstorm (built in)
    Webstorm support
  • easy jumping to different test cases
  • run only one test case with single click

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 uses contract functions to describe tests suites instead of relying on describe. I am curious what's the reasoning behind it and could it be easily replaced with describe?

Is there any pressure for bringing full compatibility with mocha?

@cgewecke
Copy link
Contributor

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?

@cgewecke
Copy link
Contributor

@krzkaczor Do the mocha options in the config work for your use case? Is this closable?

@krzkaczor
Copy link
Author

@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).

@cgewecke
Copy link
Contributor

@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.

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

No branches or pull requests

3 participants