Skip to content

Unify internal testing styles #15988

Closed
Closed

Description

@thoov

Currently there are two different styles that tests are written. An older style which uses a QUnit global to define the module and tests via QUnit.module() and QUnit.test(). The old style also uses globals for the assertion such as ok, equal, etc. A newer style which does not use QUnit globals is partially rolled out in some of the packages. This issue tracks the work needed to move all tests over to the newer style and the related work surrounding it.

A breakdown of how to complete the conversion:

  1. QUnit.module becomes moduleFor
// Old Style:
QUnit.module('<MODULE_NAME>');

// New Style:
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

moduleFor('<MODULE_NAME>', class extends AbstractTestCase {
  //...
});

Note: There are a few test case classes already so check here for other options.

  1. QUnit.test becomes a property on the test case class
// Old Style:
QUnit.test('<TEST_NAME>', function() {
  // test case here
});

// New Style:
moduleFor('<MODULE_NAME>', class extends TestCase {
  ['@test <TEST_NAME>'](assert) {
    // test case here
  }
});
  1. Assertions should be references off of the callback assert argument
// Bad:
QUnit.test('<TEST_NAME>', function() {
  equal(1, 1);
});

// Bad:
moduleFor('<MODULE_NAME>', class extends TestCase {
  ['@test <TEST_NAME>']() {
    this.assert.equal(1, 1);
  }
});

// Good:
moduleFor('<MODULE_NAME>', class extends TestCase {
  ['@test <TEST_NAME>'](assert) {
    assert.equal(1,1)
  }
});

Below are the packages that need to be converted:

Below is the test related cleanup that is needed:

Activity

  1. changed the title [-]Unify testing strategies[/-] [+]Unify testing styles[/+] on Dec 15, 2017
  2. changed the title [-]Unify testing styles[/-] [+]Unify internal testing styles[/+] on Dec 15, 2017
  3. rwjblue commented on Dec 15, 2017

    @rwjblue
    Member

    Thanks for putting this together @thoov!

  4. locks commented on Dec 15, 2017

    @locks
    Contributor

    I have taken ember-application, ember-debug, and ember-utils: #15986.

  5. t-sauer commented on Dec 15, 2017

    @t-sauer
    Contributor

    I will take a stab at container.

  6. karthiicksiva commented on Dec 19, 2017

    @karthiicksiva
    Contributor

    I will take the ember-template-compiler

  7. mikerhyssmith commented on Dec 21, 2017

    @mikerhyssmith
    Contributor

    Happy to take a stab at runtime!

  8. cibernox commented on Dec 22, 2017

    @cibernox
    Contributor

    I can take ember-testing

  9. locks commented on Dec 22, 2017

    @locks
    Contributor

    Took part of ember: #16019.

  10. Turbo87 commented on Dec 30, 2017

    @Turbo87
    Member

    Can anyone tell me the advantages of the new testing API given that for Ember projects we're now explicitly moving away from moduleFor? 🤔

  11. rwjblue commented on Dec 30, 2017

    @rwjblue
    Member

    The moduleFor being used here is completely unrelated to the legacy moduleFor implementation that is provided by ember-qunit.

  12. Turbo87 commented on Dec 31, 2017

    @Turbo87
    Member

    @rwjblue I'm aware of that, but it seems that the same pros and cons apply and I'm wondering why this decision was made

  13. Serabe commented on Jan 5, 2018

    @Serabe
    Member

    Went through all the PRs and updated current state. Need to know a couple of details:

    1. @thoov is ember-metal complete?
    2. @mikerhyssmith do you need some help with ember-runtime?

    Thank you!

  14. 7 remaining items

  15. thoov commented on Jan 11, 2018

    @thoov
    MemberAuthor

    @michaelklishin We are moving away from testBoth as under the hood it is just converting it to this (https://github.com/emberjs/ember.js/blob/master/packages/internal-test-helpers/lib/test-groups.js#L15-L25) however in the second QUnit test it references USES_ACCESSORS which is never set and therefore it just does assert.ok('SKIPPING ACCESSORS'); which isn't useful. Originally we were going to support both cases (which is probably what you saw) but realized that we could just kill that one off. Here is a PR I recently did that moved away from testBoth (https://github.com/emberjs/ember.js/pull/16072/files) that you can use as a guide and let me know if you need help with anything.

  16. added a commit that references this issue on Feb 6, 2018
  17. added a commit that references this issue on Jul 13, 2018
  18. pixelhandler commented on Oct 19, 2018

    @pixelhandler
    Contributor

    @Turbo87 @cibernox @karthiicksiva @locks @mikerhyssmith @rwjblue @t-sauer @thoov is this still an issue, perhaps we should close, what do you think?

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