Closed denchen closed 7 years ago
I found a workaround for both my acceptance and integration tests.
In acceptance tests, my beforeEach()
now looks like:
beforeEach() {
server.shutdown();
application = startApp();
},
I'm still not sure why server.shutdown()
in afterEach()
doesn't properly shutdown the server.
And for my integration/unit tests, I've modified the code from Manually starting up Mirage to this:
// See: http://www.ember-cli-mirage.com/docs/v0.2.x/manually-starting-mirage/
import mirageInitializer from '../../initializers/ember-cli-mirage';
export default function startMirage(container) {
if (this.server) {
console.warn('Shutting down Mirage server before re-initializing');
this.server.shutdown();
}
mirageInitializer.initialize(container);
}
All my tests now pass. However, I'm not sure if the above modifications are what I should be doing or not.
Same here.
Update:
It seems that updating module-for-acceptance.js
to the newest version (from Ember CLI 2.8) and adding this snippet to integration tests which use Mirage:
afterEach() {
server.shutdown();
},
does the job - everything is fine then.
Mirage monky-patches the server.shutdown for acceptance tests, but not for integration tests. I suspect this will need to be done manually (as @netes has shown) and should be mentioned in the docs.
Is the https://github.com/samselikoff/ember-cli-mirage/pull/917 related to this issue?
Yes, it is an internal fix for the same thing. Users will need to do this on their own for now.
Thanks @dustinfarris ! Sounds good!
I tried everything but still can't make it work even with one single acceptance test. Anyone is in the same case? I'm using a custom moduleForAcceptance this may be the reason why..
This is definitely due to https://github.com/pretenderjs/pretender/pull/178 having been released without a major bump.
temporary workaround for us on #922
Pretender 1.4.1 is published and it will only give you a console.warn slap on the wrist.
Thanks @trek. I think we should still try to dissuade users from overlapping servers going forward though by updating the documentation here.
For example, users relying on startMirage
in their integration tests need to know why they are going to start seeing this warning.
I don't think there is a way to automagically handle this like we do for acceptance tests because moduleForComponent
comes directly from ember-qunit, probably best to just advise users to run shutdown after using it.
Overlapping servers will also prevent some useful tools like https://percy.io/ from running in projects that use Mirage in tests.
I'm using mostly default generated tests with ember 2.10 and was having this issue. Resolved it by adding if(server !== undefined) { server.shutdown(); }
to beforeEach and afterEach in each acceptance test file. As in,
module('Acceptance: Metro', {
beforeEach: function() {
if(server !== undefined) { server.shutdown(); }
application = startApp();
originalConfirm = window.confirm;
window.confirm = function() {
confirmCalledWith = [].slice.call(arguments);
return true;
};
},
afterEach: function() {
Ember.run(application, 'destroy');
window.confirm = originalConfirm;
confirmCalledWith = null;
if(server !== undefined) { server.shutdown(); }
}
});
Hope this helps someone else having the same problem.
You saved my day! Thank you!
I started getting this error today with
ember-cli-mirage@0.2.2
, and I'm fairly certain it has to do with Pretender 1.4.0 (that has a Notify on second Pretender fix) that was released today.This was in my acceptance test. I have failures in my integration tests as well, which look like:
So what is the appropriate way to shutdown the Mirage server? I currently have this in my acceptance tests:
Do I need something similar in my integration tests?