Skip to content

Commit 0570b97

Browse files
committed
fixed forcefully destroy the app instance test
1 parent 478ddb1 commit 0570b97

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/ember-app.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class EmberApp {
266266
let res = options.response;
267267
let html = options.html || this.html;
268268
let disableShoebox = options.disableShoebox || false;
269-
let destroyAppInstanceInMs = options.destroyAppInstanceInMs;
269+
let destroyAppInstanceInMs = parseInt(options.destroyAppInstanceInMs, 10);
270270

271271
let shouldRender = (options.shouldRender !== undefined) ? options.shouldRender : true;
272272
let bootOptions = buildBootOptions(shouldRender);
@@ -285,23 +285,19 @@ class EmberApp {
285285
});
286286

287287
let destroyAppInstanceTimer;
288-
if (parseInt(destroyAppInstanceInMs, 10) > 0) {
288+
if (destroyAppInstanceInMs > 0) {
289289
// start a timer to destroy the appInstance forcefully in the given ms.
290290
// This is a failure mechanism so that node process doesn't get wedged if the `visit` never completes.
291291
destroyAppInstanceTimer = setTimeout(function() {
292-
if (instance && !result.instanceDestroyed) {
292+
if (result.instance && !result.instanceDestroyed) {
293293
result.instanceDestroyed = true;
294294
result.error = new Error('App instance was forcefully destroyed in ' + destroyAppInstanceInMs + 'ms');
295-
instance.destroy();
295+
result.instance.destroy();
296296
}
297297
}, destroyAppInstanceInMs);
298298
}
299299

300-
let instance;
301300
return this.visitRoute(path, fastbootInfo, bootOptions, result)
302-
.then(appInstance => {
303-
instance = appInstance;
304-
})
305301
.then(() => {
306302
if (!disableShoebox) {
307303
// if shoebox is not disabled, then create the shoebox and send API data
@@ -311,9 +307,9 @@ class EmberApp {
311307
.catch(error => result.error = error)
312308
.then(() => result._finalize())
313309
.finally(() => {
314-
if (instance && !result.instanceDestroyed) {
310+
if (result.instance && !result.instanceDestroyed) {
315311
result.instanceDestroyed = true;
316-
instance.destroy();
312+
result.instance.destroy();
317313

318314
if (destroyAppInstanceTimer) {
319315
clearTimeout(destroyAppInstanceTimer);

test/fastboot-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ describe("FastBoot", function() {
106106
distPath: fixture('basic-app')
107107
});
108108

109+
// delaying `visitRoute` to forcefully destroy app instance
110+
let originalVisitRoute = fastboot._app.visitRoute;
111+
fastboot._app.visitRoute = function() {
112+
return originalVisitRoute.apply(this, arguments)
113+
.then(function() {
114+
return new Promise(function(resolve) {
115+
setTimeout(resolve, 2000);
116+
});
117+
});
118+
};
119+
109120
return fastboot.visit('/', { destroyAppInstanceInMs: 5 })
110121
.catch((e) => {
111122
expect(e.message).to.equal('App instance was forcefully destroyed in 5ms');

0 commit comments

Comments
 (0)