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

Adding tests not settled detection support in tests #314

Merged
merged 8 commits into from
Feb 23, 2018

Conversation

scalvert
Copy link
Contributor

@scalvert scalvert commented Feb 13, 2018

This PR adds support for detecting if a test is not settled in tests. It tests for the settledness of timers via isSettled in ember-test-helpers.

A test is considered settled if it:

  • has no pending timers
  • is not in a runloop
  • has no pending AJAX requests
  • has no pending test waiters

@@ -228,6 +232,28 @@ export function setupEmberOnerrorValidation() {
});
}

export function setupAsyncTimerLeakDetection() {
QUnit.testDone(({ module, name }) => {
Copy link
Member

Choose a reason for hiding this comment

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

making these callbacks separate (but private) exported functions will allow you to invoke them manually from within a single test and assert that the expected error is thrown....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. That will address my nagging guilt at the thought of pushing code with no tests!

Copy link
Member

Choose a reason for hiding this comment

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

lol, its the guilt that drives me...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Split things up. Added tests.

@scalvert scalvert changed the title [WIP] - Adding async timer detection support in tests Adding async timer detection support in tests Feb 14, 2018
} from '@ember/test-helpers';
import { detectPendingTimers, reportPendingTimers } from './async-timer-leak-detection';

const TESTS_WITH_LEAKY_ASYNC = [];
Copy link
Member

Choose a reason for hiding this comment

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

we should move this into the util file, no need to track it here and pass it around

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Not sure why I didn't see this....

@@ -228,6 +233,18 @@ export function setupEmberOnerrorValidation() {
});
}

export function setupAsyncTimerLeakDetection() {
QUnit.testDone(({ module, name }) => {
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this whole function the thing that is extracted? So that the resulting code would be:

QUnit.testDone(importedThingGoesHere);
QUnit.done(otherImportedThingGoesHere);

@scalvert scalvert changed the title Adding async timer detection support in tests Adding tests not settled detection support in tests Feb 15, 2018
Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

The main changes look good to me!

I'd like to suggest a couple of alternative names for the flag and method names though:

  • setupLeakingTestsDetection
  • setupAsyncLeakDetection
  • setupLeakDetection

Any of those strike you as "better" or "worse"?

@scalvert
Copy link
Contributor Author

So I know that settled doesn't necessarily immediately scream what it does, it is consistent from ember-qunit through ember-test-helpers. Also, the specific reason I added more detail to the function names within the module is to help define settled.

That said, if I were to change it, I'd probably opt for:

setupTestAsyncLeakDetection

That helps convey that we're setting up async leak detection for tests. What do you think?

@scalvert
Copy link
Contributor Author

@rwjblue and I arrived at setupTestIsolationValidation.

@scalvert
Copy link
Contributor Author

@rwjblue any more changes required here?

@rwjblue rwjblue merged commit 5618777 into emberjs:master Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants