Truffle: `Truffle test` should allow user to run a specific test using `mocha -g`

Created on 6 Jun 2019  路  10Comments  路  Source: trufflesuite/truffle

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

Following up from Twitter conversation with @gnidan - ref https://twitter.com/gnidan/status/1136386257481863169


Issue

We should have a way to run individual truffle tests, similar to how mocha -g works (greps for a test string).

  • There is an alternative way to do this by specifying .only in Mocha tests
  • Being able to pass in -g allows us to run specific tests, e.g. in CI

Steps to Reproduce

truffle test -- -g "name of test"

Follow-ups

I'll be working on this, which is similar to issue #7 opened by @oed.

enhancement needs requirements priority6 馃挱 truffle test

Most helpful comment

A workaround you can use is to use only on your test and then feed mocha the specific path to that test.

So you can do

it.only("returns the value I expect", () => {
  const expectedValue = 10;
  ...

And then just run truffle test ./test/myFavoriteTestFile.js

Let me know if you think this workaround is not enough and we can consider a more robust solution.

All 10 comments

@gnidan, I splunked through the codebase. Can I ask for your feedback on developer UX and codebase intuition?

Developer experience

usage:
      "truffle test [<test_file>] [--compile-all] [--network <name>] [--verbose-rpc] [--show-events] **[--grep]**",
    options: [
      {
        option: "--grep",
        description:
          "Only run tests matching this string or regexp, similar to `mocha --grep`"
      },

Implementation

I'm fairly inexperienced with javascript + mocha - so writing the code splunk trail here:

The flow of execution of truffle test is the following (all in truffle-core):
-> cli.js:45 & lib/command.js:110-113: parses args into options object
-> lib/commands/test.js:112: collates config object (:114)
-> lib/test.js:58: creates mocha test with config files (:143). To implement grep, mochaConfig.grep needs to be set to arg values

@onggunhao I believe you can just use the path to the test file as an argument and it should work. For example truffle test ./test/mySpecificTest.sol.

@onggunhao Just an FYI, I have a PR out that reworks a lot of the test stuff. It hasn't been merged yet but if might be very relevant to the work you are doing. Check out https://github.com/trufflesuite/truffle/pull/2081

@eggplantzzz Ah nice work on #2081! I was actually going to offer more of my sabbatical time to ES6-ify the truffle test package - the callbacks were really weird to follow (esp. the environmentCallback calling run)

I'll probably branch from #2081 and follow up from there. Happy to lend a hand on other tasks - doing this as a way to learn

Ok great, I'm going to go ahead and try and get it reviewed and merged for the next release.

Did this ever get worked on? Being able to test a single case is extremely useful in large test files

@GregTheGreek You should be able to just run one test file by passing the path in as follows:

truffle test ./test/myFavoriteTestFile.js

Any update on this? Running specific test-file is not enough IMO. When you have tens of tests in a file, only one is failing and you have to rerun the whole suite just for that one test. Especially when you work with time-delays...

Any update on this?

A workaround you can use is to use only on your test and then feed mocha the specific path to that test.

So you can do

it.only("returns the value I expect", () => {
  const expectedValue = 10;
  ...

And then just run truffle test ./test/myFavoriteTestFile.js

Let me know if you think this workaround is not enough and we can consider a more robust solution.

Was this page helpful?
0 / 5 - 0 ratings