Skip to content

Commit 0893cec

Browse files
author
Robert Jackson
committed
Failing test: Ember.onerror setup via instance initailizer leaks across visits
1 parent b67703f commit 0893cec

12 files changed

Lines changed: 66447 additions & 0 deletions

test/fastboot-test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,36 @@ describe('FastBoot', function() {
423423

424424
expect(html).to.match(/Items: 1/);
425425
});
426+
427+
it('errors can be properly attributed', async function() {
428+
this.timeout(3000);
429+
430+
var fastboot = new FastBoot({
431+
distPath: fixture('onerror-per-visit'),
432+
});
433+
434+
let first = fastboot.visit('/slow/100/reject', {
435+
request: { url: '/slow/100/reject', headers: {} },
436+
});
437+
438+
let second = fastboot.visit('/slow/50/resolve', {
439+
request: { url: '/slow/50/resolve', headers: {} },
440+
});
441+
442+
let third = fastboot.visit('/slow/25/resolve', {
443+
request: { url: '/slow/25/resolve', headers: {} },
444+
});
445+
446+
await Promise.all([second, third]);
447+
448+
await first.then(
449+
() => {
450+
throw new Error('Visit should not resolve!');
451+
},
452+
error => {
453+
expect(error.code).to.equal('from-slow');
454+
expect(error.fastbootRequestPath).to.equal('/slow/100/reject');
455+
}
456+
);
457+
});
426458
});
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
define('~fastboot/app-factory', ['onerror-per-visit/app', 'onerror-per-visit/config/environment'], function(App, config) {
2+
App = App['default'];
3+
config = config['default'];
4+
5+
return {
6+
'default': function() {
7+
return App.create(config.APP);
8+
}
9+
};
10+
});
11+
12+
define("onerror-per-visit/initializers/ajax", ["exports"], function (_exports) {
13+
"use strict";
14+
15+
Object.defineProperty(_exports, "__esModule", {
16+
value: true
17+
});
18+
_exports.default = void 0;
19+
const {
20+
get
21+
} = Ember;
22+
23+
var nodeAjax = function (options) {
24+
let httpRegex = /^https?:\/\//;
25+
let protocolRelativeRegex = /^\/\//;
26+
let protocol = get(this, 'fastboot.request.protocol');
27+
28+
if (protocolRelativeRegex.test(options.url)) {
29+
options.url = protocol + options.url;
30+
} else if (!httpRegex.test(options.url)) {
31+
try {
32+
options.url = protocol + '//' + get(this, 'fastboot.request.host') + options.url;
33+
} catch (fbError) {
34+
throw new Error('You are using Ember Data with no host defined in your adapter. This will attempt to use the host of the FastBoot request, which is not configured for the current host of this request. Please set the hostWhitelist property for in your environment.js. FastBoot Error: ' + fbError.message);
35+
}
36+
}
37+
38+
if (najax) {
39+
najax(options);
40+
} else {
41+
throw new Error('najax does not seem to be defined in your app. Did you override it via `addOrOverrideSandboxGlobals` in the fastboot server?');
42+
}
43+
};
44+
45+
var _default = {
46+
name: 'ajax-service',
47+
initialize: function (application) {
48+
application.register('ajax:node', nodeAjax, {
49+
instantiate: false
50+
});
51+
application.inject('adapter', '_ajaxRequest', 'ajax:node');
52+
application.inject('adapter', 'fastboot', 'service:fastboot');
53+
}
54+
};
55+
_exports.default = _default;
56+
});
57+
define("onerror-per-visit/initializers/error-handler", ["exports"], function (_exports) {
58+
"use strict";
59+
60+
Object.defineProperty(_exports, "__esModule", {
61+
value: true
62+
});
63+
_exports.default = void 0;
64+
65+
/**
66+
* Initializer to attach an `onError` hook to your app running in fastboot. It catches any run loop
67+
* exceptions and other errors and prevents the node process from crashing.
68+
*
69+
*/
70+
var _default = {
71+
name: 'error-handler',
72+
initialize: function () {
73+
if (!Ember.onerror) {
74+
// if no onerror handler is defined, define one for fastboot environments
75+
Ember.onerror = function (err) {
76+
const errorMessage = "There was an error running your app in fastboot. More info about the error: \n ".concat(err.stack || err);
77+
console.error(errorMessage);
78+
};
79+
}
80+
}
81+
};
82+
_exports.default = _default;
83+
});//# sourceMappingURL=onerror-per-visit-fastboot.map

test/fixtures/onerror-per-visit/assets/onerror-per-visit-fastboot.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/onerror-per-visit/assets/onerror-per-visit.css

Whitespace-only changes.

test/fixtures/onerror-per-visit/assets/onerror-per-visit.js

Lines changed: 260 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)