Skip to content

Commit 0a136d3

Browse files
committed
WIP
1 parent 0bdf3c6 commit 0a136d3

14 files changed

+1553
-2027
lines changed

addon-test-support/assertions/expect-deprecation.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getDeprecationsForCallback, getDeprecations } from '@ember/test-helpers';
1+
import { getDeprecationsDuringCallback, getDeprecations } from '@ember/test-helpers';
22
import checkMatcher from './utils/check-matcher';
33

44
export default function expectDeprecation(cb, matcher) {
5-
const test = deprecations => {
5+
const test = (deprecations, matcher) => {
66
const matchedDeprecations = deprecations.filter(deprecation => {
77
return checkMatcher(deprecation.message, matcher);
88
});
@@ -16,13 +16,14 @@ export default function expectDeprecation(cb, matcher) {
1616
}
1717

1818
if (typeof cb !== 'function') {
19-
test(getDeprecations());
19+
// cb is not a callback, so we assume it is the matcher
20+
test(getDeprecations(), cb);
2021
} else {
21-
const maybeThenable = getDeprecationsForCallback(cb);
22+
const maybeThenable = getDeprecationsDuringCallback(cb);
2223
if (maybeThenable !== null && typeof maybeThenable === 'object' && typeof maybeThenable.then === 'function') {
23-
return maybeThenable.then(test);
24+
return maybeThenable.then(deprecations => test(deprecations, matcher));
2425
} else {
25-
test(maybeThenable);
26+
test(maybeThenable, matcher);
2627
}
2728
}
2829

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import checkMatcher from './utils/check-matcher';
2+
import { getDeprecations, getDeprecationsDuringCallback } from '@ember/test-helpers';
3+
4+
export default function expectNoDeprecation(cb, matcher) {
5+
const test = (deprecations, matcher) => {
6+
const matchedDeprecations = deprecations.filter(deprecation => {
7+
return checkMatcher(deprecation.message, matcher);
8+
});
9+
10+
this.pushResult({
11+
result: matchedDeprecations.length === 0,
12+
actual: matchedDeprecations,
13+
expected: [],
14+
message: 'Expected no deprecations during test, but deprecations were found.',
15+
});
16+
}
17+
18+
if (typeof cb !== 'function') {
19+
// cb is not a callback, so we assume it is the matcher
20+
test(getDeprecations(), cb);
21+
} else {
22+
const maybeThenable = getDeprecationsDuringCallback(cb);
23+
if (maybeThenable !== null && typeof maybeThenable === 'object' && typeof maybeThenable.then === 'function') {
24+
return maybeThenable.then(deprecations => test(deprecations, matcher));
25+
} else {
26+
test(maybeThenable, matcher);
27+
}
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,59 @@
1-
import { end, _currentRunloop, _hasScheduledTimers, _cancelTimers } from '@ember/runloop';
1+
import { run, end, _getCurrentRunLoop, _hasScheduledTimers, _cancelTimers } from '@ember/runloop';
22

3+
function getCurrentRunLoop() {
4+
// Ember 3.24.4 does not have _getCurrentRunLoop, but does have run.currentRunLoop;
5+
if ('currentRunLoop' in run) {
6+
return run.currentRunLoop;
7+
} else {
8+
return _getCurrentRunLoop();
9+
}
10+
}
11+
12+
// TODO: It seems very odd to mix runloop + timers into a runloop
13+
// specific assertion.
14+
//
15+
// We should likely:
16+
//
17+
// * have timer specific expectations
18+
// * have runloop specific expectations
19+
// * not have either cancel timers or runloop, rather those should
20+
// be the explicitly choosen by the user
321
export default function expectNoRunloop() {
4-
if (_currentRunLoop) {
22+
if (getCurrentRunLoop()) {
523
this.pushResult({
624
result: false,
7-
actual: run.currentRunLoop,
25+
actual: getCurrentRunLoop(),
826
expected: null,
9-
message: 'Should not be in a run loop at end of test'
27+
message: 'expected no active runloop'
1028
});
1129

12-
while (_currentRunLoop) {
30+
while (getCurrentRunLoop()) {
1331
end();
1432
}
33+
} else {
34+
this.pushResult({
35+
result: true,
36+
actual: null,
37+
expected: null,
38+
message: 'expected no active runloop'
39+
});
1540
}
1641

1742
if (_hasScheduledTimers()) {
1843
this.pushResult({
1944
result: false,
2045
actual: true,
2146
expected: false,
22-
message: 'Ember run should not have scheduled timers at end of test'
47+
message: 'expected no active timers'
2348
});
2449

2550
_cancelTimers();
51+
} else {
52+
this.pushResult({
53+
result: true,
54+
actual: false,
55+
expected: false,
56+
message: 'expected no active timers'
57+
});
2658
}
2759
}

addon-test-support/assertions/expect-no-warnings.js renamed to addon-test-support/assertions/expect-no-warning.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { getWarnings, getWarningsDuringCallback } from '@ember/test-helpers';
22

3-
export default function expectNoWarnings(callback) {
3+
export default function expectNoWarning(callback) {
44
const warnings = typeof callback === 'function' ? getWarningsDuringCallback(callback) : getWarnings();
55

6-
let warningStr = warnings.reduce((a, b) => {
7-
return `${b}${a.message}\n`;
8-
}, '');
6+
const warningStr = warnings.reduce((a, b) => `${b}${a.message}\n`, '');
97

108
this.pushResult({
119
result: warnings.length === 0,

addon-test-support/assertions/expect-warnings.js renamed to addon-test-support/assertions/expect-warning.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import checkMatcher from './utils/check-matcher';
2-
import { getWarningsDuringCallback } from '@ember/test-helpers';
2+
import { getWarningsDuringCallback, getWarnings } from '@ember/test-helpers';
33

4-
export default function expectWarnings(callback, matcher) {
4+
export default function expectWarning(callback, matcher) {
55
let warnings;
66
if (typeof callback === 'function') {
77
warnings = getWarningsDuringCallback(callback);
@@ -10,7 +10,7 @@ export default function expectWarnings(callback, matcher) {
1010
warnings = getWarnings();
1111
}
1212

13-
const matchedWarnings = warnings.filter(warning => checkMatcher(warning.message, matcher);
13+
const matchedWarnings = warnings.filter(warning => checkMatcher(warning.message, matcher));
1414

1515
this.pushResult({
1616
result: matchedWarnings.length !== 0,

addon-test-support/assertions/no-deprecations.js

-11
This file was deleted.

addon-test-support/assertions/utils/check-matcher.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
export function checkMatcher(message, matcher) {
1+
function includes(message, search) {
2+
return message.includes ? message.includes(search) : message.indexOf(search) !== -1;
3+
}
4+
5+
// TODO: test
6+
export default function checkMatcher(message, matcher) {
27
if (typeof matcher === 'string') {
38
return includes(message, matcher);
49
} else if (matcher instanceof RegExp) {

addon-test-support/index.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@ import { installTestNotIsolatedHook } from './test-isolation-validation';
2727

2828
let waitForSettled = true;
2929

30-
import deprecationsInclude from './asserts/deprecations-include';
31-
import deprecations from './asserts/deprecations';
32-
import noDeprecations from './asserts/no-deprecations';
33-
import expectDeprecation from './asserts/expect-deprecation';
34-
import expectNoRunloop from './asserts/expect-no-runloop';
35-
import expectWarning from './asserts/expect-warning';
36-
37-
export function setup(assert) {
30+
import deprecationsInclude from './assertions/deprecations-include';
31+
import deprecations from './assertions/deprecations';
32+
import expectNoDeprecation from './assertions/expect-no-deprecation';
33+
import expectDeprecation from './assertions/expect-deprecation';
34+
import expectNoRunloop from './assertions/expect-no-runloop';
35+
// import expectWarning from './assertions/expect-warning';
36+
//
37+
export function setupAsserts(assert) {
3838
// TODO: decide which of these we should keep, which depreacte and which drop.
3939
assert.deprecationsInclude = deprecationsInclude;
4040
assert.deprecations = deprecations;
41-
assert.expectNoDeprecations = noDeprecations; // compat
42-
assert.noDeprecations = noDeprecations;
41+
assert.expectNoDeprecation = expectNoDeprecation;
4342
assert.expectDeprecation = expectDeprecation; // compat
4443
assert.expectNoRunloop = expectNoRunloop; // compat but fixed name
4544
// around for compat
@@ -241,5 +240,9 @@ export function start(options = {}) {
241240
startTests();
242241
}
243242

243+
if (options.setupAssertAdditions !== false) {
244+
setupAsserts(QUnit.assert);
245+
}
246+
244247
setupResetOnerror();
245248
}

server/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = (app) => app.get('/', (_, res) => res.redirect('/tests'));

tests/unit/assertions/assertion-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { module, test } from 'qunit';
2-
import expectAssertion from 'ember-qunit/assertions/expect-assertion';
2+
// import expectAssertion from 'ember-qunit/assertions/expect-assertion';
33
import { assert as emberAssert } from '@ember/debug';
44

5-
module('expectAssertion', function(hooks) {
5+
module.skip('expectAssertion', function(hooks) {
66
let mockAssert;
77

88
hooks.beforeEach(() => {

0 commit comments

Comments
 (0)