-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
0bdf3c6
commit 53de824
Showing
17 changed files
with
2,030 additions
and
2,127 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,29 +1,37 @@ | ||
import { getDeprecationsForCallback, getDeprecations } from '@ember/test-helpers'; | ||
import { | ||
getDeprecationsDuringCallback, | ||
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 => { | ||
const test = (deprecations, matcher) => { | ||
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.' | ||
message: | ||
'Expected deprecations during test, but no deprecations were found.', | ||
}); | ||
} | ||
}; | ||
|
||
if (typeof cb !== 'function') { | ||
test(getDeprecations()); | ||
// cb is not a callback, so we assume it is the matcher | ||
test(getDeprecations(), cb); | ||
} else { | ||
const maybeThenable = getDeprecationsForCallback(cb); | ||
if (maybeThenable !== null && typeof maybeThenable === 'object' && typeof maybeThenable.then === 'function') { | ||
return maybeThenable.then(test); | ||
const maybeThenable = getDeprecationsDuringCallback(cb); | ||
if ( | ||
maybeThenable !== null && | ||
typeof maybeThenable === 'object' && | ||
typeof maybeThenable.then === 'function' | ||
) { | ||
return maybeThenable.then((deprecations) => test(deprecations, matcher)); | ||
} else { | ||
test(maybeThenable); | ||
test(maybeThenable, matcher); | ||
} | ||
} | ||
|
||
} |
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,37 @@ | ||
import checkMatcher from './utils/check-matcher'; | ||
import { | ||
getDeprecations, | ||
getDeprecationsDuringCallback, | ||
} from '@ember/test-helpers'; | ||
|
||
export default function expectNoDeprecation(cb, matcher) { | ||
const test = (deprecations, matcher) => { | ||
const matchedDeprecations = deprecations.filter((deprecation) => { | ||
return checkMatcher(deprecation.message, matcher); | ||
}); | ||
|
||
this.pushResult({ | ||
result: matchedDeprecations.length === 0, | ||
actual: matchedDeprecations, | ||
expected: [], | ||
message: | ||
'Expected no deprecations during test, but deprecations were found.', | ||
}); | ||
}; | ||
|
||
if (typeof cb !== 'function') { | ||
// cb is not a callback, so we assume it is the matcher | ||
test(getDeprecations(), cb); | ||
} else { | ||
const maybeThenable = getDeprecationsDuringCallback(cb); | ||
if ( | ||
maybeThenable !== null && | ||
typeof maybeThenable === 'object' && | ||
typeof maybeThenable.then === 'function' | ||
) { | ||
return maybeThenable.then((deprecations) => test(deprecations, matcher)); | ||
} else { | ||
test(maybeThenable, matcher); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,27 +1,65 @@ | ||
import { end, _currentRunloop, _hasScheduledTimers, _cancelTimers } from '@ember/runloop'; | ||
import { | ||
run, | ||
end, | ||
_getCurrentRunLoop, | ||
_hasScheduledTimers, | ||
_cancelTimers, | ||
} from '@ember/runloop'; | ||
|
||
function getCurrentRunLoop() { | ||
// Ember 3.24.4 does not have _getCurrentRunLoop, but does have run.currentRunLoop; | ||
if ('currentRunLoop' in run) { | ||
return run.currentRunLoop; | ||
} else { | ||
return _getCurrentRunLoop(); | ||
} | ||
} | ||
|
||
// TODO: It seems very odd to mix runloop + timers into a runloop | ||
// specific assertion. | ||
// | ||
// We should likely: | ||
// | ||
// * have timer specific expectations | ||
// * have runloop specific expectations | ||
// * not have either cancel timers or runloop, rather those should | ||
// be the explicitly choosen by the user | ||
export default function expectNoRunloop() { | ||
if (_currentRunLoop) { | ||
if (getCurrentRunLoop()) { | ||
this.pushResult({ | ||
result: false, | ||
actual: run.currentRunLoop, | ||
actual: getCurrentRunLoop(), | ||
expected: null, | ||
message: 'Should not be in a run loop at end of test' | ||
message: 'expected no active runloop', | ||
}); | ||
|
||
while (_currentRunLoop) { | ||
while (getCurrentRunLoop()) { | ||
end(); | ||
} | ||
} else { | ||
this.pushResult({ | ||
result: true, | ||
actual: null, | ||
expected: null, | ||
message: 'expected no active runloop', | ||
}); | ||
} | ||
|
||
if (_hasScheduledTimers()) { | ||
this.pushResult({ | ||
result: false, | ||
actual: true, | ||
expected: false, | ||
message: 'Ember run should not have scheduled timers at end of test' | ||
message: 'expected no active timers', | ||
}); | ||
|
||
_cancelTimers(); | ||
} else { | ||
this.pushResult({ | ||
result: true, | ||
actual: false, | ||
expected: false, | ||
message: 'expected no active timers', | ||
}); | ||
} | ||
} |
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,15 @@ | ||
import { getWarnings, getWarningsDuringCallback } from '@ember/test-helpers'; | ||
|
||
export default function expectNoWarning(callback) { | ||
const warnings = | ||
typeof callback === 'function' | ||
? getWarningsDuringCallback(callback) | ||
: getWarnings(); | ||
|
||
this.pushResult({ | ||
result: warnings.length === 0, | ||
actual: warnings, | ||
expected: [], | ||
message: 'Expected no warnings during test, but warnings were found.', | ||
}); | ||
} |
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 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
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 @@ | ||
module.exports = (app) => app.get('/', (_, res) => res.redirect('/tests')); |
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 |
---|---|---|
@@ -1,46 +1,58 @@ | ||
import { module, test } from 'qunit'; | ||
import expectAssertion from 'ember-qunit/assertions/expect-assertion'; | ||
// import expectAssertion from 'ember-qunit/assertions/expect-assertion'; | ||
import { assert as emberAssert } from '@ember/debug'; | ||
|
||
module('expectAssertion', function(hooks) { | ||
module.skip('expectAssertion', function (hooks) { | ||
let mockAssert; | ||
|
||
hooks.beforeEach(() => { | ||
mockAssert = { | ||
pushedResults: [], | ||
expectAssertion | ||
expectAssertion, | ||
}; | ||
}); | ||
|
||
test('called with assert', function(assert) { | ||
test('called with assert', function (assert) { | ||
mockAssert.expectAssertion(() => { | ||
emberAssert('testing assert'); | ||
}); | ||
|
||
assert.ok(mockAssert.pushedResults[0].result, '`expectAssertion` captured deprecation call'); | ||
assert.ok( | ||
mockAssert.pushedResults[0].result, | ||
'`expectAssertion` captured deprecation call' | ||
); | ||
}); | ||
|
||
test('called without deprecation', function(assert) { | ||
test('called without deprecation', function (assert) { | ||
mockAssert.expectAssertion(() => { | ||
emberAssert('testing assert', true); | ||
}); | ||
|
||
assert.notOk(mockAssert.pushedResults[0].result, '`expectAssertion` logged failed result'); | ||
assert.notOk( | ||
mockAssert.pushedResults[0].result, | ||
'`expectAssertion` logged failed result' | ||
); | ||
}); | ||
|
||
test('called with deprecation and matched assert', function(assert) { | ||
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'); | ||
assert.ok( | ||
mockAssert.pushedResults[0].result, | ||
'`expectAssertion` captured deprecation call' | ||
); | ||
}); | ||
|
||
test('called with deprecation and unmatched assert', function(assert) { | ||
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'); | ||
assert.notOk( | ||
mockAssert.pushedResults[0].result, | ||
'`expectAssertion` logged failed result' | ||
); | ||
}); | ||
}); |
Oops, something went wrong.