-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
Changes from 1 commit
4924b49
a406a56
193bd8b
2643f84
f5eb5a6
3febb6b
0488804
a7e93c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ export { module, test, skip, only, todo } from 'qunit'; | |
export { loadTests } from './test-loader'; | ||
|
||
import { deprecate } from '@ember/debug'; | ||
import { run } from '@ember/runloop'; | ||
import { loadTests } from './test-loader'; | ||
import Ember from 'ember'; | ||
import QUnit from 'qunit'; | ||
|
@@ -24,8 +25,11 @@ import { | |
setupApplicationContext, | ||
teardownApplicationContext, | ||
validateErrorHandler, | ||
getSettledState, | ||
} from '@ember/test-helpers'; | ||
|
||
const TESTS_WITH_LEAKY_ASYNC = []; | ||
|
||
export function setResolver() { | ||
deprecate( | ||
'`setResolver` should be imported from `@ember/test-helpers`, but was imported from `ember-qunit`', | ||
|
@@ -228,6 +232,28 @@ export function setupEmberOnerrorValidation() { | |
}); | ||
} | ||
|
||
export function setupAsyncTimerLeakDetection() { | ||
QUnit.testDone(({ module, name }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol, its the guilt that drives me... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split things up. Added tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); |
||
let { hasPendingTimers } = getSettledState(); | ||
|
||
if (hasPendingTimers) { | ||
TESTS_WITH_LEAKY_ASYNC.push(`${module}: ${name}`); | ||
run.cancelTimers(); | ||
} | ||
}); | ||
|
||
QUnit.done(() => { | ||
if (TESTS_WITH_LEAKY_ASYNC.length > 0) { | ||
throw new Error( | ||
`ASYNC LEAKAGE DETECTED IN TESTS | ||
The following (${TESTS_WITH_LEAKY_ASYNC.length}) tests setup a timer that was never torn down before the test completed: \n | ||
${TESTS_WITH_LEAKY_ASYNC.join('\n')} | ||
` | ||
); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
@method start | ||
@param {Object} [options] Options to be used for enabling/disabling behaviors | ||
|
@@ -265,6 +291,10 @@ export function start(options = {}) { | |
setupEmberOnerrorValidation(); | ||
} | ||
|
||
if (options.setupAsyncTimerLeakDetection !== false) { | ||
setupAsyncTimerLeakDetection(); | ||
} | ||
|
||
if (options.startTests !== false) { | ||
startTests(); | ||
} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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....