Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add randomization support #1512

Closed
wants to merge 1 commit into from
Closed

Add randomization support #1512

wants to merge 1 commit into from

Conversation

TimothyGu
Copy link
Contributor

Big Fat Warning

This is a WIP. I just wanted to throw the idea out there and see if there's any feedback before I start writing tests and docs.

How to use it?

The array shuffling is done with the knuth-shuffle-seeded, my fork of knuth-shuffle that supports seeding.

mocha --randomization tests
mocha -a tests
mocha -a tests:mySeed123ee456eeed
{
  randomizeMode: 'test'
, randomizeSeed: 'mySeed'
}

If your test needs to be tested in a particular order, add noRandom:

describe.noRandom('my test', function () {
  [...]
})

noRandom plays nicely with other modifiers (although I admit the implementation is a little ugly):

describe.noRandom.only()
describe.only.noRandom()
describe.noRandom.skip()
describe.skip.noRandom()
xdescribe.noRandom()

Current state

Currently it only supports test-level randomization (mode === 'tests'), which means that only the order of tests within a suite is randomized.

TODO

  • tests
  • docs
  • suite-level randomization (might be added after this PR)

Fixes #902.

@TimothyGu
Copy link
Contributor Author

I'll take a look at Node.js 0.8 later (which is causing the Travis error).

@TimothyGu TimothyGu force-pushed the rand branch 2 times, most recently from affba74 to 22e2c13 Compare January 23, 2015 06:25
@travisjeffery
Copy link
Contributor

man those added apis are nastyyyy :S

@travisjeffery
Copy link
Contributor

i'm not really keen on this being in mocha

@TimothyGu
Copy link
Contributor Author

@travisjeffery you mean those only.noRandom and noRandom.only? Yes I would agree so. If you have any other way of doing it I would be happy to reimplement it.

@dasilvacontin
Copy link
Contributor

It would be desirable to discuss/design the API before hand in the issue. :/

@TimothyGu
Copy link
Contributor Author

@dasilvacontin well I did comment on the issue but nobody responded: #902 (comment)

@dasilvacontin
Copy link
Contributor

@TimothyGu, sorry, I'm quite busy until mid-Feb, and since I tend to not open slack anymore I miss a lot of convs/threads.

@TimothyGu
Copy link
Contributor Author

@dasilvacontin It's all good, just wanted to point out my comment

@travisjeffery
Copy link
Contributor

it's not the api, i just don't think it's needed in mocha

@TimothyGu
Copy link
Contributor Author

@travisjeffery You mean the feature? Well #902 is tagged as "PR PLEASE"

@dasilvacontin
Copy link
Contributor

@travisjeffery pretty much everyone in the issue agreed it would be helpful, even @boneskull. At the very least we could leave it in a plugin.

@boneskull
Copy link
Contributor

@travisjeffery It's probably not something I'd use, but many people want this.

@travisjeffery
Copy link
Contributor

all kinds of people want kinds of stuff, not really a great argument for anything imo. it would be sweet if we could add enable this feature as an external plugin however

@TimothyGu
Copy link
Contributor Author

@travisjeffery

Well again I just implemented it because it looks doable, fun, requested, and tagged as "PR PLEASE." If you disagree with doing it in Mocha, I would seriously think that you guys should clean up the issues tagged as PR PLEASE first, AND possibly close #902.

Personally, I do not care about this feature. It is likely that I will not even ever use this feature. I just did it for the good of the community, and as it looks like that the feature is requested by multiple people and looks useful.

I am not inclined to do further work on it if it is not appreciated, nor am I motivated enough to turn it into a plugin (even less so when there is literally zero documentation on doing so anywhere I could find).

@TimothyGu
Copy link
Contributor Author

Plus, if you think randomization is not helpful in the main Mocha distribution, why are useless things (let's be practical) like this or that even included in the standard Mocha distribution?

@TimothyGu
Copy link
Contributor Author

I said:

even less so when there is literally zero documentation on doing so anywhere I could find

Ah now I understand why, because the plugin framework doesn't even exist.

@boneskull
Copy link
Contributor

why are useless things (let's be practical) like this or that even included in the standard Mocha distribution?

No time to pull them out. Extracting the reporters (especially these reporters) from the core is on the TODO list.

@dasilvacontin
Copy link
Contributor

There was even an initiative to make framework-independent reporters, but guess how that is going. :)

@boneskull
Copy link
Contributor

it would be sweet if we could add enable this feature as an external plugin however

As @TimothyGu said, no such thing exists. So in the meantime, I'm happy to add one of the most requested features, which is why this was tagged PR PLEASE.

@boneskull
Copy link
Contributor

all kinds of people want kinds of stuff, not really a great argument for anything imo.

If one random dude wants one random thing, then probably not. This is not one of those, however.

If I had more time to dedicate to this, I'd try to give the most requested features attention, and add them, if I agree they belong somewhere in this framework. But I don't have the time, and we don't have the luxury of saying x feature should be in core, and y should be a plugin, because we have no plugin API.

So we have @TimothyGu who takes the time to do it. I haven't even had a chance to look at the PR, but if it looks good, I'd like to merge it.

@boneskull
Copy link
Contributor

@travisjeffery

man those added apis are nastyyyy :S

This is not necessary.

@dasilvacontin
Copy link
Contributor

Same thoughts here, @boneskull. I tend not to express myself much, maybe I should do it more often.

@dasilvacontin
Copy link
Contributor

We definitely appreciate the work you've put into the PR, @TimothyGu, in case it is not clear.

Once it looks good, we will merge it into core. And once we have a stable Plugin API, we will debate whether to export it into a plugin.

@TimothyGu
Copy link
Contributor Author

@boneskull and @dasilvacontin, I appreciate your constructive comments.

@TimothyGu
Copy link
Contributor Author

@dasilvacontin @boneskull ping? I will rebase the PR if you guys can take a look at it first.

*/

Suite.prototype.enableRandomize = function(enabled){
if (arguments.length === 0) return this._enableRandomize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels to me that executing this.enableRandomize() in a suite should enable randomize, but it doesn't, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, without arguments it's used as a getter... I think it would be bad to see .enableRandomize() around being used as a getter – not logical at all.

@dasilvacontin
Copy link
Contributor

The PR is lacking tests asserting that enableRandomize and noRandom functions are actually doing their job setting booleans.

It would also be nice to have a test suite that we run with a fixed seed, and check if the order of test execution is correct. And another one with a non-defined seed that just checks the tests are not run in the order they are described (it can still fail, but the probability is very low).

@boneskull
Copy link
Contributor

@TimothyGu Sorry busy as hell atm. Should have some time tomorrow

@dasilvacontin
Copy link
Contributor

Also, are suites inheriting ._enableRandomize? This should be asserted in the tests as well.

@TimothyGu
Copy link
Contributor Author

@dasilvacontin said:

The PR is lacking tests asserting that enableRandomize and noRandom functions are actually doing their job setting booleans.

I know, hence the TODOs in the first comment of the thread.

@dasilvacontin
Copy link
Contributor

@TimothyGu Oh sorry, I didn't re-read that part and just went on giving overall review of the PR.


Runner.prototype.randomize = function(mode, seed){
debug('randomize mode: "' + mode + '"; seed: ' + seed);
if (mode !== 'tests') return this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this temporary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as for now only tests can be randomized.

@dasilvacontin
Copy link
Contributor

Any update, @TimothyGu?

@TimothyGu
Copy link
Contributor Author

@dasilvacontin I've been fairly busy with other stuff recently, but I'll take a look at the suggestions soon (I hope).

@dasilvacontin
Copy link
Contributor

No worries. :)

Le 30 avr. 2015 à 19:05, Timothy Gu notifications@github.com a écrit :

@dasilvacontin I've been fairly busy with other stuff recently, but I'll take a look at the suggestions soon (I hope).


Reply to this email directly or view it on GitHub.

@boneskull
Copy link
Contributor

@TimothyGu not saying anyone will do this, but I'd like to get some traction on it; do you mind if me or someone else grabs your branch and makes changes?

@TimothyGu
Copy link
Contributor Author

@boneskull not at all, as long as maybe I'm credited for an initial implementation.

@jbnicolai
Copy link

@boneskull 👍 if you'd like to pick this up. Great feature to have :)

@jbnicolai jbnicolai force-pushed the master branch 3 times, most recently from 2f458ab to 2952eca Compare July 5, 2015 10:25
@boneskull
Copy link
Contributor

I'm going to see what I can do with this.

@boneskull boneskull self-assigned this Jun 9, 2016
@boneskull
Copy link
Contributor

@TimothyGu I will need to close this PR and create a new one, but your name will be on at least one commit here.

@boneskull boneskull closed this Jun 9, 2016
@TimothyGu
Copy link
Contributor Author

Alright, thanks.

@boneskull boneskull removed their assignment Dec 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 Feature: --order option for random test order
5 participants