-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add waitForSettled support and use latests ember-test-helpers #633
base: master
Are you sure you want to change the base?
Changes from all commits
79ffabf
34b9587
ce3d5ca
69cd865
44b8298
8c11ab8
dbf8099
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,8 +6,28 @@ import { loadTests } from './test-loader'; | |
import setupTest from 'ember-mocha/setup-test'; | ||
import setupRenderingTest from 'ember-mocha/setup-rendering-test'; | ||
import setupApplicationTest from 'ember-mocha/setup-application-test'; | ||
import { it, afterEach } from 'mocha'; | ||
import { beforeEach, afterEach } from 'mocha'; | ||
import { setResolver, resetOnerror } from '@ember/test-helpers'; | ||
import Ember from 'ember'; | ||
|
||
/** | ||
Ensures that `Ember.testing` is set to `true` before each test begins | ||
(including `before` / `beforeEach`), and reset to `false` after each test is | ||
completed. This is done via `beforeEach` and `afterEach`. | ||
*/ | ||
export function setupEmberTesting() { | ||
beforeEach(function() { | ||
Ember.testing = true; | ||
}); | ||
|
||
afterEach(function() { | ||
Ember.testing = false; | ||
}); | ||
} | ||
Comment on lines
+13
to
+26
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. We should not need to add this code. It should be handled by Also, |
||
|
||
function setupMocha(options) { | ||
mocha.setup(options || {}); | ||
} | ||
|
||
/** | ||
* Instruct Mocha to start the tests. | ||
|
@@ -27,9 +47,12 @@ function setupResetOnerror() { | |
* @param {Object} [options] Options to be used for enabling/disabling behaviors | ||
* @param {Boolean} [options.loadTests] If `false` tests will not be loaded automatically. | ||
* @param {Boolean} [options.startTests] If `false` tests will not be automatically started | ||
* @param {Object} [options.mochaOptions] options to pass mocha setup method | ||
* (you must run `startTests()` to kick them off). | ||
*/ | ||
export function start(options = {}) { | ||
setupMocha(options?.mochaOptions); | ||
|
||
setupResetOnerror(); | ||
|
||
if (options.loadTests !== false) { | ||
|
@@ -45,6 +68,5 @@ export { | |
setupTest, | ||
setupRenderingTest, | ||
setupApplicationTest, | ||
it, | ||
setResolver, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,7 @@ import { | |
setupContext, | ||
teardownContext | ||
} from '@ember/test-helpers'; | ||
import { assign, merge } from '@ember/polyfills'; | ||
import { resolve } from 'rsvp'; | ||
import Ember from 'ember'; | ||
|
||
let teardownMandatorySetter; | ||
if (Ember.__loader && Ember.__loader.registry && Ember.__loader.registry['@ember/-internals/utils/index']) { | ||
teardownMandatorySetter = Ember.__loader.require('@ember/-internals/utils').teardownMandatorySetter; | ||
} | ||
|
||
const _assign = assign || merge; | ||
|
||
function chainHooks(hooks, context) { | ||
return hooks.reduce((promise, fn) => promise.then(fn.bind(context)), resolve()); | ||
|
@@ -30,37 +21,35 @@ function setupPauseTest(context) { | |
}; | ||
} | ||
|
||
export default function setupTest(options) { | ||
export default function setupTest(_options) { | ||
let originalContext; | ||
let beforeEachHooks = []; | ||
let afterEachHooks = []; | ||
let options = _options === undefined ? { waitForSettled: true } : Object.assign({ waitForSettled: true }, _options); | ||
|
||
beforeEach(function() { | ||
originalContext = _assign({}, this); | ||
originalContext = Object.assign({}, this); | ||
let context = new Proxy(this, {}); | ||
this._emberContext = context; | ||
|
||
return setupContext(this, options) | ||
return setupContext(this._emberContext, options) | ||
.then(() => setupPauseTest(this)) | ||
.then(() => chainHooks(beforeEachHooks, this)); | ||
}); | ||
|
||
afterEach(function() { | ||
return chainHooks(afterEachHooks, this) | ||
.then(() => teardownContext(this)) | ||
.then(() => teardownContext(this._emberContext, options)) | ||
.then(() => { | ||
// delete any extraneous properties | ||
for (let key in this) { | ||
if (!(key in originalContext)) { | ||
// starting from Ember 3.13 this seems to be necessary | ||
if (teardownMandatorySetter) { | ||
teardownMandatorySetter(this, key); | ||
} | ||
|
||
delete this[key]; | ||
} | ||
} | ||
|
||
// copy over the original values | ||
_assign(this, originalContext); | ||
Object.assign(this, originalContext); | ||
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. Are we explicitly dropping IE11 support in this release? IMHO, that should be decoupled from updating @ember/test-helpers. 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. @rwjblue would the babel transpiler not handle this for us? 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.
No, not by default. It is possible to configure this to transpile into core-js poly fills, but that requires the application has the polyfill installed/configured (which we can't assume). Additionally, we can't force the app to add the polyfill only in tests because then tests would pass in browsers that would never actually work in production/deployment. 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. So unfortunately with the 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. @rwjblue let me know what you would like to do regarding this? Should I use the proxy-polyfill or should we just drop IE support in this PR? |
||
}); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
import Application from '@ember/application'; | ||
import Resolver from './resolver'; | ||
import Resolver from 'ember-resolver'; | ||
import loadInitializers from 'ember-load-initializers'; | ||
import config from './config/environment'; | ||
|
||
const App = Application.extend({ | ||
modulePrefix: config.modulePrefix, | ||
podModulePrefix: config.podModulePrefix, | ||
Resolver | ||
}); | ||
export default class App extends Application { | ||
modulePrefix = config.modulePrefix; | ||
podModulePrefix = config.podModulePrefix; | ||
Resolver = Resolver; | ||
} | ||
|
||
loadInitializers(App, config.modulePrefix); | ||
|
||
export default App; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import EmberRouter from '@ember/routing/router'; | ||
import config from './config/environment'; | ||
|
||
const Router = EmberRouter.extend({ | ||
location: config.locationType, | ||
rootURL: config.rootURL | ||
}); | ||
export default class Router extends EmberRouter { | ||
location = config.locationType; | ||
rootURL = config.rootURL; | ||
} | ||
|
||
Router.map(function() { | ||
this.route('foo'); | ||
}); | ||
|
||
export default Router; |
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 not turn this rule off. The thing it is flagging is correct.
Ember.testing
should never be set during module evaluation.