Skip to content

Commit

Permalink
Failing test: Ember.onerror setup via instance initailizer leaks acro…
Browse files Browse the repository at this point in the history
…ss visits
  • Loading branch information
rwjblue committed Oct 30, 2019
1 parent b67703f commit 0893cec
Show file tree
Hide file tree
Showing 12 changed files with 66,447 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/fastboot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,36 @@ describe('FastBoot', function() {

expect(html).to.match(/Items: 1/);
});

it('errors can be properly attributed', async function() {
this.timeout(3000);

var fastboot = new FastBoot({
distPath: fixture('onerror-per-visit'),
});

let first = fastboot.visit('/slow/100/reject', {
request: { url: '/slow/100/reject', headers: {} },
});

let second = fastboot.visit('/slow/50/resolve', {
request: { url: '/slow/50/resolve', headers: {} },
});

let third = fastboot.visit('/slow/25/resolve', {
request: { url: '/slow/25/resolve', headers: {} },
});

await Promise.all([second, third]);

await first.then(
() => {
throw new Error('Visit should not resolve!');
},
error => {
expect(error.code).to.equal('from-slow');
expect(error.fastbootRequestPath).to.equal('/slow/100/reject');
}
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
define('~fastboot/app-factory', ['onerror-per-visit/app', 'onerror-per-visit/config/environment'], function(App, config) {
App = App['default'];
config = config['default'];

return {
'default': function() {
return App.create(config.APP);
}
};
});

define("onerror-per-visit/initializers/ajax", ["exports"], function (_exports) {
"use strict";

Object.defineProperty(_exports, "__esModule", {
value: true
});
_exports.default = void 0;
const {
get
} = Ember;

var nodeAjax = function (options) {
let httpRegex = /^https?:\/\//;
let protocolRelativeRegex = /^\/\//;
let protocol = get(this, 'fastboot.request.protocol');

if (protocolRelativeRegex.test(options.url)) {
options.url = protocol + options.url;
} else if (!httpRegex.test(options.url)) {
try {
options.url = protocol + '//' + get(this, 'fastboot.request.host') + options.url;
} catch (fbError) {
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);
}
}

if (najax) {
najax(options);
} else {
throw new Error('najax does not seem to be defined in your app. Did you override it via `addOrOverrideSandboxGlobals` in the fastboot server?');
}
};

var _default = {
name: 'ajax-service',
initialize: function (application) {
application.register('ajax:node', nodeAjax, {
instantiate: false
});
application.inject('adapter', '_ajaxRequest', 'ajax:node');
application.inject('adapter', 'fastboot', 'service:fastboot');
}
};
_exports.default = _default;
});
define("onerror-per-visit/initializers/error-handler", ["exports"], function (_exports) {
"use strict";

Object.defineProperty(_exports, "__esModule", {
value: true
});
_exports.default = void 0;

/**
* Initializer to attach an `onError` hook to your app running in fastboot. It catches any run loop
* exceptions and other errors and prevents the node process from crashing.
*
*/
var _default = {
name: 'error-handler',
initialize: function () {
if (!Ember.onerror) {
// if no onerror handler is defined, define one for fastboot environments
Ember.onerror = function (err) {
const errorMessage = "There was an error running your app in fastboot. More info about the error: \n ".concat(err.stack || err);
console.error(errorMessage);
};
}
}
};
_exports.default = _default;
});//# sourceMappingURL=onerror-per-visit-fastboot.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
260 changes: 260 additions & 0 deletions test/fixtures/onerror-per-visit/assets/onerror-per-visit.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0893cec

Please sign in to comment.