Skip to content

Commit

Permalink
Shutdown the pretender server on destroyApp.
Browse files Browse the repository at this point in the history
Ember-CLI 1.13.9 and beyond will have a destroy-app helper that we can shutdown the server in.
This patch automatically inserts this behavior, or shows a message if the user doesn't have a destroy-app helper explaining how to fix the problem.
Fixes #226.
  • Loading branch information
blimmer committed Dec 15, 2015
1 parent c36c1bf commit 2d48d7e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Next

Update notes:
- We now use `destroyApp` test helper in Ember-CLI to shutdown the Mirage server
after each test to resolve a memory leak reported in #226. It's important to run
`ember g ember-cli-mirage` when upgrading to take advantage of this fix.

Changes:
- [BREAKING CHANGE] missing routes will now throw an Error instead of logging
to the Logger's `error` channel.
Expand Down
20 changes: 20 additions & 0 deletions blueprints/ember-cli-mirage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
'use strict';

var path = require('path');
var existsSync = require('exists-sync');
var chalk = require('chalk');
var EOL = require('os').EOL;

module.exports = {
normalizeEntityName: function() {
Expand Down Expand Up @@ -34,6 +37,23 @@ module.exports = {
after: '"predef": [\n'
});

if (existsSync('tests/helpers/destroy-app.js')) {
this.insertIntoFile('tests/helpers/destroy-app.js', ' server.shutdown();', {
after: "Ember.run(application, 'destroy');\n"
});
} else {
this.ui.writeLine(
EOL +
chalk.yellow(
'******************************************************' + EOL +
'destroy-app.js helper is not present. Please read this' + EOL +
'https://gist.github.com/blimmer/35d3efbb64563029505a' + EOL +
'to see how to fix the problem.' + EOL +
'******************************************************' + EOL
)
);
}

return this.addPackagesToProject([
{ name: 'ember-lodash', target: '0.0.5' }
]).then(function() {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"broccoli-unwatched-tree": "^0.1.1",
"ember-cli-babel": "^5.1.3",
"ember-lodash": "0.0.6",
"ember-inflector": "^1.9.2"
"ember-inflector": "^1.9.2",
"chalk": "^1.1.1",
"exists-sync": "0.0.3"
}
}

0 comments on commit 2d48d7e

Please sign in to comment.