-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9286e89
commit 10e4a37
Showing
15 changed files
with
509 additions
and
15 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...t-support/asserts/deprecations-include.js → ...upport/assertions/deprecations-include.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
addon-test-support/asserts/deprecations.js → ...n-test-support/assertions/deprecations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { getDeprecationsForCallback, getDeprecations } from '@ember/test-helpers'; | ||
import checkMatcher from './utils/check-matcher'; | ||
|
||
export default function expectDeprecation(cb, matcher) { | ||
const test = deprecations => { | ||
const matchedDeprecations = deprecations.filter(deprecation => { | ||
return checkMatcher(deprecation.message, matcher); | ||
}); | ||
|
||
this.pushResult({ | ||
result: matchedDeprecations.length !== 0, | ||
actual: matchedDeprecations, | ||
expected: null, | ||
message: 'Expected deprecations during test, but no deprecations were found.' | ||
}); | ||
} | ||
|
||
if (typeof cb !== 'function') { | ||
test(getDeprecations()); | ||
} else { | ||
const maybeThenable = getDeprecationsForCallback(cb); | ||
if (maybeThenable !== null && typeof maybeThenable === 'object' && typeof maybeThenable.then === 'function') { | ||
return maybeThenable.then(test); | ||
} else { | ||
test(maybeThenable); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { end, _currentRunloop, _hasScheduledTimers, _cancelTimers } from '@ember/runloop'; | ||
|
||
export default function expectNoRunloop() { | ||
if (_currentRunLoop) { | ||
this.pushResult({ | ||
result: false, | ||
actual: run.currentRunLoop, | ||
expected: null, | ||
message: 'Should not be in a run loop at end of test' | ||
}); | ||
|
||
while (_currentRunLoop) { | ||
end(); | ||
} | ||
} | ||
|
||
if (_hasScheduledTimers()) { | ||
this.pushResult({ | ||
result: false, | ||
actual: true, | ||
expected: false, | ||
message: 'Ember run should not have scheduled timers at end of test' | ||
}); | ||
|
||
_cancelTimers(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getWarnings, getWarningsDuringCallback } from '@ember/test-helpers'; | ||
|
||
export default function expectNoWarnings(callback) { | ||
const warnings = typeof callback === 'function' ? getWarningsDuringCallback(callback) : getWarnings(); | ||
|
||
let warningStr = warnings.reduce((a, b) => { | ||
return `${b}${a.message}\n`; | ||
}, ''); | ||
|
||
this.pushResult({ | ||
result: warnings.length === 0, | ||
actual: warnings, | ||
expected: [], | ||
message: `Expected no warnings during test, but warnings were found.\n${warningStr}` | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import checkMatcher from './utils/check-matcher'; | ||
import { getWarningsDuringCallback } from '@ember/test-helpers'; | ||
|
||
export default function expectWarnings(callback, matcher) { | ||
let warnings; | ||
if (typeof callback === 'function') { | ||
warnings = getWarningsDuringCallback(callback); | ||
} else { | ||
matcher = callback; | ||
warnings = getWarnings(); | ||
} | ||
|
||
const matchedWarnings = warnings.filter(warning => checkMatcher(warning.message, matcher); | ||
|
||
this.pushResult({ | ||
result: matchedWarnings.length !== 0, | ||
actual: matchedWarnings, | ||
expected: null, | ||
message: 'Expected warnings during test, but no warnings were found.' | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { getDeprecations } from '@ember/test-helpers'; | ||
|
||
export default function noDeprecations() { | ||
// TODO: implement | ||
this.pushResult({ | ||
result: getDeprecations(), | ||
actual: [], | ||
expected: null, | ||
message: 'Expected no deprecations during test, but deprecations did occure.' | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function checkMatcher(message, matcher) { | ||
if (typeof matcher === 'string') { | ||
return includes(message, matcher); | ||
} else if (matcher instanceof RegExp) { | ||
return !!message.match(matcher); | ||
} else if (matcher) { | ||
throw new Error(`[ember-qunit] can only match Strings and RegExps. "${typeof matcher}" was provided.`); | ||
} | ||
|
||
// No matcher always returns true. Makes the code easier elsewhere. | ||
return true; | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { module, test } from 'qunit'; | ||
import expectAssertion from 'ember-qunit/assertions/expect-assertion'; | ||
import { assert as emberAssert } from '@ember/debug'; | ||
|
||
module('expectAssertion', function(hooks) { | ||
let mockAssert; | ||
|
||
hooks.beforeEach(() => { | ||
mockAssert = { | ||
pushedResults: [], | ||
expectAssertion | ||
}; | ||
}); | ||
|
||
test('called with assert', function(assert) { | ||
mockAssert.expectAssertion(() => { | ||
emberAssert('testing assert'); | ||
}); | ||
|
||
assert.ok(mockAssert.pushedResults[0].result, '`expectAssertion` captured deprecation call'); | ||
}); | ||
|
||
test('called without deprecation', function(assert) { | ||
mockAssert.expectAssertion(() => { | ||
emberAssert('testing assert', true); | ||
}); | ||
|
||
assert.notOk(mockAssert.pushedResults[0].result, '`expectAssertion` logged failed result'); | ||
}); | ||
|
||
test('called with deprecation and matched assert', function(assert) { | ||
mockAssert.expectAssertion(() => { | ||
emberAssert('testing assert'); | ||
}, /testing/); | ||
|
||
assert.ok(mockAssert.pushedResults[0].result, '`expectAssertion` captured deprecation call'); | ||
}); | ||
|
||
test('called with deprecation and unmatched assert', function(assert) { | ||
mockAssert.expectAssertion(() => { | ||
emberAssert('testing assert'); | ||
}, /different/); | ||
|
||
assert.notOk(mockAssert.pushedResults[0].result, '`expectAssertion` logged failed result'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import { module, test } from 'qunit'; | ||
import expectDeprecation from 'ember-qunit/assertions/expect-deprecation'; | ||
import { deprecate } from '@ember/debug'; | ||
|
||
// ............................................................ | ||
// Deprecation outside of a test. Should not cause test failures. | ||
deprecate('Deprecation outside of a test', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
// ............................................................ | ||
|
||
module('expectDeprecation', function(hooks) { | ||
let mockAssert; | ||
|
||
hooks.beforeEach(() => { | ||
mockAssert = { | ||
pushedResults: [], | ||
expectDeprecation, | ||
}; | ||
}); | ||
|
||
test('expectDeprecation called after test and with deprecation', function(assert) { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
|
||
mockAssert.expectDeprecation(); | ||
|
||
assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` captured deprecation call'); | ||
}); | ||
|
||
test('expectDeprecation called after test and without deprecation', function(assert) { | ||
mockAssert.expectDeprecation(); | ||
assert.notOk(mockAssert.pushedResults[0].result, '`expectDeprecation` logged failed result'); | ||
}); | ||
|
||
test('expectDeprecation called with callback and with deprecation', function(assert) { | ||
mockAssert.expectDeprecation(() => { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
}); | ||
|
||
assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` captured deprecation call'); | ||
}); | ||
|
||
test('expectDeprecation called with callback and without deprecation', function(assert) { | ||
mockAssert.expectDeprecation(() => { }); | ||
assert.notOk(mockAssert.pushedResults[0].result, '`expectDeprecation` logged failed result'); | ||
}); | ||
|
||
test('expectDeprecation called with callback and after test', function(assert) { | ||
mockAssert.expectDeprecation(() => { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
}); | ||
|
||
mockAssert.expectDeprecation(); | ||
assert.ok(mockAssert.pushedResults[0].result, 'first `expectDeprecation` captured deprecation call'); | ||
assert.notOk(mockAssert.pushedResults[1].result, 'second `expectDeprecation` logged failed result'); | ||
}); | ||
|
||
test('expectDeprecation called after test, with matcher and matched deprecation', function(assert) { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
|
||
mockAssert.expectDeprecation(/Something deprecated/); | ||
assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` captured deprecation call'); | ||
}); | ||
|
||
test('expectDeprecation called after test, with matcher and unmatched deprecation', function(assert) { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
|
||
mockAssert.expectDeprecation(/different deprecation/); | ||
assert.notOk(mockAssert.pushedResults[0].result, '`expectDeprecation` logged failed result'); | ||
}); | ||
|
||
test('expectDeprecation called with callback, matcher and matched deprecation', function(assert) { | ||
mockAssert.expectDeprecation(() => { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
}, /Something deprecated/); | ||
|
||
assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` captured deprecation call'); | ||
}); | ||
|
||
test('expectDeprecation called with callback, matcher and unmatched deprecation', function(assert) { | ||
mockAssert.expectDeprecation(() => { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
}, /different deprecation/); | ||
|
||
assert.notOk(mockAssert.pushedResults[0].result, '`expectDeprecation` logged failed result'); | ||
}); | ||
|
||
test('expectNoDeprecation called after test and without deprecation', function(assert) { | ||
assert.expectNoDeprecation(); | ||
assert.ok(mockAssert.pushedResults[0].result, '`expectNoDeprecation` caught no deprecation'); | ||
}); | ||
|
||
test('expectNoDeprecation called after test and with deprecation', function(assert) { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
|
||
assert.expectNoDeprecation(); | ||
assert.notOk(mockAssert.pushedResults[0].result, '`expectNoDeprecation` caught logged failed result'); | ||
}); | ||
|
||
test('expectNoDeprecation called with callback and with deprecation', function(assert) { | ||
assert.expectNoDeprecation(() => { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
}); | ||
|
||
assert.notOk(mockAssert.pushedResults[0].result, '`expectNoDeprecation` caught logged failed result'); | ||
}); | ||
|
||
test('expectNoDeprecation called with callback and without deprecation', function(assert) { | ||
assert.expectNoDeprecation(() => { }); | ||
assert.ok(mockAssert.pushedResults[0].result, '`expectNoDeprecation` caught no deprecation'); | ||
}); | ||
|
||
test('expectNoDeprecation called with callback and after test', function(assert) { | ||
assert.expectNoDeprecation(() => { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
}); | ||
|
||
assert.expectNoDeprecation(); | ||
assert.notOk(mockAssert.pushedResults[0].result, 'first `expectNoDeprecation` caught logged failed result'); | ||
assert.ok(mockAssert.pushedResults[1].result, 'second `expectNoDeprecation` caught no deprecation'); | ||
}); | ||
|
||
test('expectDeprecation with regex matcher', function(assert) { | ||
mockAssert.expectDeprecation(() => { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
}, /Somethi[a-z ]*ecated/); | ||
mockAssert.expectDeprecation(() => { | ||
deprecate('/Something* deprecated/', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
}, /Something* deprecated/); | ||
|
||
assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` matched RegExp'); | ||
assert.notOk(mockAssert.pushedResults[1].result, '`expectDeprecation` didn\'t RegExp as String match'); | ||
}); | ||
|
||
test('expectDeprecation with string matcher', function(assert) { | ||
mockAssert.expectDeprecation(() => { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
}, 'Something'); | ||
|
||
mockAssert.expectDeprecation(() => { | ||
deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); | ||
}, 'Something.*'); | ||
|
||
assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` captured deprecation for partial String match'); | ||
assert.notOk(mockAssert.pushedResults[1].result, '`expectDeprecation` didn\'t test a String match as RegExp'); | ||
}); | ||
}); |
Oops, something went wrong.