Skip to content

Testing Suites #49

Open
Open

Description

@IshaGupta18

Currently, we are working with Mocha in our tests in this repo. However, I think we should chime in a couple of thoughts here regarding this.
We should do a comparison between Mocha, Jasmine, and Jest, the first 2 being used in different PL's repos, as far as I know.
https://medium.com/welldone-software/an-overview-of-javascript-testing-in-2019-264e19514d0a
https://stackshare.io/stackups/jasmine-vs-jest-vs-mocha
The above are a couple of posts which discuss the three.
Here are a couple of resources from @jywarren https://marcofranssen.nl/jasmine-vs-mocha/ and like he said, @Souravirus has switched to Mocha in plots2 (publiclab/plots2#2967 (comment))
So if we could discuss the pros and cons of the three, it would be pretty great! I am beginning to write tests in mocha, just for the sake of understanding it right now.
Also, I would love a suggestion on a testing framework for UI testing.
cc @jywarren @rexagod @namangupta01 @gauravano @Souravirus @IgorWilbert

Activity

  1. jywarren commented on Jun 17, 2019

    @jywarren
    Member

    Great, thanks for this summary!!!

    I found some great references search Gitter for mocha:

    https://gitter.im/publiclab/publiclab?at=59359203cf9c13503c570db7

    
    ananyo2012 Did you find which testing framework has a better support for API testing?
    ryzokuken Both Jasmine and Mocha have pretty solid support for API testing, I think.
    ryzokuken I'll need to confirm that though.
    ryzokuken You can even mock APIs in Mocha, I've heard.
    ryzokuken http://robdodson.me/mocking-requests-with-mocha-chai-and-sinon/
    ananyo2012 Yes Mocha has good support for mocks and Stubs
    
    matrixbot @matrixbot Jun 05 2017 13:16
    ryzokuken Actually, native Mocha doesn't come with any mocking/stubbing library like Jasmine
    ryzokuken this allows us to use Siphon, which is more powerful than what comes preloaded with Jasmine.
    

    Also from one of these results, input from @ananyo2012 (Hi Ananyo!!!!):

    I was reading this: http://stateofjs.com/2016/testing/ today
    To decide on what testing framework we should use
    Seems like Mocha and Jasmine are the 2 most used JavaScript testing frameworks
    But I dont really want to go with numbers
    

    And my thoughts on it were:

    Hi! On testing setups, we generally consider a few things: a) is it easy for newcomers to set up, b) is it well documented and maintained (maybe jasmine less so these days, i'm hearing from you all?), c) can we have consistency across our projects so people's skills transfer when moving between, and maybe others. But these are not blocking concerns; they just need to be balanced with the benefits. So if we're just trying mocha because it seems interesting, maybe not worth it, but if for one of these reasons it's better than Jasmine, and the pros outweigh the cons, go for it! Also, to some degree, if you've put hours into mocha and switching would be a lot of work, that's a good thing to consider too. Thanks!!!

  2. rexagod commented on Jun 17, 2019

    @rexagod
    Member

    As far as mocking support is concerned, along with ananyo's concerns, I'd say the we should give Jest a spin. It wasn't there back in 2012, or wasn't atleast popular so to say, but it's got everything, from headless support (below) to semantic expect and it APIs for the newer contributors.

    1_BK8l8MaHZaNJqOITCgMMCg

    I can go ahead in this direction, explaining the whats and hows and even integrate it into this lib, given @jywarren and @publiclab/soc decide to pursue this direction.

  3. IshaGupta18 commented on Jun 18, 2019

    @IshaGupta18
    CollaboratorAuthor

    I am okay with it I think since I am just exploring the three. have just begun with Mocha, although to start my testing, I require to create a UI test first. So that's why I got a little curious as to which framework we should use. I have seen the example given by @rexagod and I think it's pretty good. @jywarren what do you think? Should we give jest a shot?

  4. IshaGupta18 commented on Jun 18, 2019

    @IshaGupta18
    CollaboratorAuthor

    @rexagod I have a small doubt. I need to test my CsvParser functions first (before moving to View's functions), but to do so, I need a div element ie a mock of a div element, because when the function reaches this line:

    SimpleDataGrapher.elementIdSimpleDataGraphInstanceMap[this.elementId].view.continueViewManipulation();
    , it automatically shifts to the View file, which will return an error, if a div element (with some id) is not present
    this.elementId = elementId;
    this.element = document.getElementById(elementId);
    if(this.element == null){
    throw "No element exist with this id";
    }
    . What do you suggest be done here?

  5. rexagod commented on Jun 18, 2019

    @rexagod
    Member
    var div = document.createElement('DIV');
    div.setAttribute('id','xyz');
    ...
    ...
    div.parentNode.removeChild(div);
    

    Dynamically create, run tests on, and remove the div.

  6. IshaGupta18 commented on Jun 18, 2019

    @IshaGupta18
    CollaboratorAuthor

    Create this where? Btw this is what is there in the index.html file:

    <div id="first"></div>
    <div id="second"></div>
    <script src="../dist/PublicLab.Grapher.js"></script>
    <script>
    a = new SimpleDataGrapher("first");
    </script>

  7. rexagod commented on Jun 18, 2019

    @rexagod
    Member

    Add and delete the div during the period of the test run. Create the div, when test is done with it, destroy it.

  8. IshaGupta18 commented on Jun 18, 2019

    @IshaGupta18
    CollaboratorAuthor

    Could you please elaborate a little more, I am so sorry to ask so many questions, I am actually unable to understand the flow here?

  9. rexagod commented on Jun 18, 2019

    @rexagod
    Member

    What exactly are you unable to understand?

  10. IshaGupta18 commented on Jun 18, 2019

    @IshaGupta18
    CollaboratorAuthor
  11. rexagod commented on Jun 18, 2019

    @rexagod
    Member

    SimpleDataGrapher.elementIdSimpleDataGraphInstanceMap[this.elementId].view.continueViewManipulation();

    Just before this line, make a div using js (syntax above). Actually there's no need to destroy it just don't append it to the DOM. Refer to that div's id in your tests. That's it!

  12. ananyo2012 commented on Jun 18, 2019

    @ananyo2012
    Member

    Hey all. Nice to have mentioned. That was quite some time back I had that discussion with @ryzokuken on testing framework. Here is what I feel on choosing a testing framework

    1. Should have good mocking libraries. Having written tests in multiple frameworks and languages I feel this one is a major thing to consider. We don't want to spend a lot of time to write a mock or a stub which also makes it difficult to maintain.
    2. Unit tests should be fast. With time the number of tests increases and so the time taken to execute them. You don't want to wait a long time to have tests to pass.
    3. Should have good documentation as @jywarren mentioned. With a bunch of testing frameworks out there it can be difficult to consider which one to choose to from with just the above 2 points. When in dilemma always choose the one which has good support and documentation.
  13. ryzokuken commented on Jun 18, 2019

    @ryzokuken
    Member

    I use Jest (because I'm lazy) these days mostly, but both Chai and Mocha are nice testing libraries. Please feel free to hit me up if you need help/more context regarding any.

  14. Souravirus commented on Jun 20, 2019

    @Souravirus
    Member

    Hi everyone, I changed the tests in plots2 from Jasmine to Mocha because jasmine-rails was unable to test modern ES features. So, there was a need for another testing suite and Mocha seems perfect at that time.

  15. jywarren commented on Jun 21, 2019

    @jywarren
    Member

    Hi, this is not the same thing but a related convo on build tools was here - just found it: publiclab/PublicLab.Editor#227

  16. rexagod commented on Jun 21, 2019

    @rexagod
    Member

    I was curious to know @publiclab/soc @publiclab/reviewers opinions on using npm scripts as the ultimate task runner, just to keep things simple and way more flexible, while considerably reducing the bug count (no third-party mirrors of deps). I guess we can consider integrating the newer modules with gulp or webpack or even grunt if people see advantages in the same, otherwise, maybe we should consider the former as well?

  17. jywarren commented on Jun 21, 2019

    @jywarren
    Member
  18. IshaGupta18 commented on Jun 30, 2019

    @IshaGupta18
    CollaboratorAuthor

    Any suggestions for UI testing with mocha @jywarren @namangupta01 @rexagod ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions