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

Test: Implement universal module setup/teardown #635

Merged
merged 3 commits into from
Sep 1, 2014

Conversation

leobalter
Copy link
Member

This implements the equivalent of setup/teardown methods that are define once for the entire testsuite, but run for each test. To make this easier to understand, we've went from setup/teardown to beforeEach/afterEach, renaming the existing module properties at the same time (in a separate commit).

Fixes #633

@JamesMGreene
Copy link
Member

Just took a very quick look but seems good to me.

var translate = {
beforeEach: "setup",
afterEach: "teardown"
};
Copy link
Member Author

Choose a reason for hiding this comment

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

this translate object is temporary until we deprecate and remove QUnit.module's setup/teardown names for beforeEach/afterEach

@jzaefferer jzaefferer changed the title Test: Implements universal module setup [WIP] Test: Implements universal module setup/teardown Aug 25, 2014
@Krinkle Krinkle changed the title Test: Implements universal module setup/teardown Test: Implement universal module setup/teardown Aug 25, 2014
@jzaefferer
Copy link
Member

I didn't yet run this test, so something may be wrong, but it should work like this:

QUnit.config.beforeEach = function( assert ) {
  assert.deepEqual( Object.keys( this ), [ "helper" ] );
};
QUnit.module("context object", {
  beforeEach: function( assert ) {
    assert.deepEqual( Object.keys( this ), [ "helper" ] );
    this.prop = "foobar";
  },
  helper: function() {}
});
QUnit.test("keys", function( assert ) {
  assert.deepEqual( Object.keys( this ), [ "helper", "prop" ] );
});

See also qunitjs/api.qunitjs.com#63

@leobalter leobalter force-pushed the universal-module-setup branch 2 times, most recently from 16ebe40 to 982063e Compare August 26, 2014 14:39
@@ -8,7 +8,7 @@ function Test( settings ) {
Test.count = 0;

Test.prototype = {
setup: function() {
beforeEach: function() {
Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with renaming these methods, but the "each" part doesn't really make sense, since they are called just once for each Test instance. We can also just leave the names as-is (Test#setup and Test#teardown), since these have a completely different scope. If we rename, then "before" and "after" should be good.

@leobalter leobalter force-pushed the universal-module-setup branch 4 times, most recently from bc490e9 to cf4321b Compare September 1, 2014 14:14
@leobalter
Copy link
Member Author

Rebased with suggested changes:

  • globalSetup is now hooks
  • Test prototype internal methods setup and teardown were renamed to before and after.
  • beforeEach and afterEach methods are only seen on the external api as the module's hooks

@leobalter leobalter force-pushed the universal-module-setup branch 4 times, most recently from 846b027 to fa96fdf Compare September 1, 2014 14:58
QUnit.module setup and teardown functions are now deprecated as
they were moved to beforeEach/afterEach.

Tests were added to confirm they still work while deprecated.

beforeEach and afterEach are no longer exposed to the test context
as setup/teardown were accidentaly.

Ref qunitjs#635
QUnit.module tests were moved - with some improvements - to a new
test file modules.js

Some other tests were also removed because they were revealed as
unnecessary tests.

Ref qunitjs#635
@jzaefferer
Copy link
Member

Looks good, let's land it.

@leobalter leobalter merged commit 74d566f into qunitjs:master Sep 1, 2014
@leobalter leobalter deleted the universal-module-setup branch September 1, 2014 15:08
@jzaefferer
Copy link
Member

Now we just need the API docs to land when we release 1.16.

@JamesMGreene
Copy link
Member

Late to the party but just a note: I'm glad we chose "hooks" as that is consistent with Mocha's terminology.

@leobalter
Copy link
Member Author

@JamesMGreene we checked on their documentation before choosing the name.

@JamesMGreene
Copy link
Member

\o/

leobalter added a commit to leobalter/api.qunitjs.com that referenced this pull request Sep 11, 2014
leobalter added a commit to leobalter/api.qunitjs.com that referenced this pull request Sep 11, 2014
jzaefferer added a commit to jzaefferer/qunit that referenced this pull request Oct 10, 2014
Between locating the hooks in `QUnit` or `QUnit.config` and making them
simple setters and callback lists (like QUnit.done et al) and upcoming
plans for nested suites, we decided not to release this feature, for now.

I'm keeping the abstractions for hooks in place, so it should be trivial
to bring this back in whatever form we decide on later.

Effectively reverts 5ee31a0 and follow-up
commits.

Fixes qunitjs#665
Ref qunitjs#633
Ref qunitjs#635
Ref qunitjs#647
jzaefferer added a commit to jzaefferer/qunit that referenced this pull request Oct 17, 2014
Between locating the hooks in `QUnit` or `QUnit.config` and making them
simple setters and callback lists (like QUnit.done et al) and upcoming
plans for nested suites, we decided not to release this feature, for now.

I'm keeping the abstractions for hooks in place, so it should be trivial
to bring this back in whatever form we decide on later.

Effectively reverts 5ee31a0 and follow-up
commits.

Fixes qunitjs#665
Ref qunitjs#633
Ref qunitjs#635
Ref qunitjs#647
leobalter added a commit to qunitjs/api.qunitjs.com that referenced this pull request Dec 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Support global test-level setup/teardown callbacks
3 participants