Skip to content

Commit fd484dd

Browse files
committed
Display FastBoot errors in the testing container.
This will give ECFT users faster feedback as to why their pages arent rendering.
1 parent b48454f commit fd484dd

7 files changed

Lines changed: 90 additions & 2 deletions

File tree

addon-test-support/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ export async function fastboot(url, { headers = {} }) {
1717
let response = await fetch(endpoint);
1818
let result = await response.json();
1919

20-
let body = extractBody(result.html);
20+
let body = result.err ?
21+
formatError(result.err) :
22+
extractBody(result.html);
2123

22-
result.body = body;
2324
result.htmlDocument = parseHtml(result.html)
25+
result.body = body;
2426

2527
return result;
2628
}
@@ -58,3 +60,7 @@ export function extractBody(html) {
5860

5961
return html.substr(startAt, endAt);
6062
}
63+
64+
let formatError = function(err) {
65+
return `<pre>${err.stack}</pre>`;
66+
};

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,31 @@ module.exports = {
6565
html: html
6666
});
6767
});
68+
})
69+
.catch(err => {
70+
let errorObject;
71+
let jsonError = {};
72+
73+
errorObject = (typeof err === 'string') ?
74+
new Error(err) :
75+
err;
76+
77+
// we need to copy these properties off the error
78+
// object into a pojo that can be serialized and
79+
// sent over the wire to the test runner.
80+
let errorProps = [
81+
'description',
82+
'fileName',
83+
'lineNumber',
84+
'message',
85+
'name',
86+
'number',
87+
'stack'
88+
];
89+
90+
errorProps.forEach(key => jsonError[key] = errorObject[key]);
91+
92+
res.json({ err: jsonError });
6893
});
6994
});
7095
},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Route from '@ember/routing/route';
2+
3+
export default Route.extend({
4+
5+
model() {
6+
return document.title;
7+
}
8+
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Route from '@ember/routing/route';
2+
3+
export default Route.extend({
4+
5+
model() {
6+
throw new Error("This errors in FastBoot!");
7+
}
8+
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Route from '@ember/routing/route';
2+
3+
export default Route.extend({
4+
5+
model() {
6+
throw "This errors in FastBoot!";
7+
}
8+
9+
});

tests/dummy/app/router.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Router.map(function() {
2727

2828
this.route('request-object');
2929

30+
this.route('errors', function() {
31+
this.route('throw-message');
32+
this.route('throw-error-object');
33+
this.route('access-document');
34+
});
35+
3036
this.route('not-found', { path: '/*path' });
3137
});
3238

tests/fastboot/errors-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { module, test } from 'qunit';
2+
import { setup, visit } from 'ember-cli-fastboot-testing/test-support';
3+
4+
module('Fastboot | errors', function(hooks) {
5+
setup(hooks);
6+
7+
test('it displays fastboot errors', async function(assert) {
8+
await visit('/examples/errors/throw-message');
9+
10+
assert.dom().includesText('This errors in FastBoot!');
11+
});
12+
13+
test('it displays fastboot error objects', async function(assert) {
14+
await visit('/examples/errors/throw-error-object');
15+
16+
assert.dom().includesText('This errors in FastBoot!');
17+
});
18+
19+
test('it displays fastboot errors like trying to access document', async function(assert) {
20+
await visit('/examples/errors/access-document');
21+
22+
assert.dom().includesText('ReferenceError: document is not defined');
23+
});
24+
});

0 commit comments

Comments
 (0)