Skip to content

Commit 0aefab4

Browse files
add tests
1 parent 6fb00f0 commit 0aefab4

File tree

22 files changed

+107797
-0
lines changed

22 files changed

+107797
-0
lines changed

packages/fastboot/test/fastboot-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ describe('FastBoot', function() {
6363
});
6464
});
6565

66+
it('can render HTML with default metadata', function() {
67+
var fastboot = new FastBoot({
68+
distPath: fixture('app-with-default-metadata'),
69+
});
70+
71+
return fastboot
72+
.visit('/', { request: { headers: {} } })
73+
.then(r => r.html())
74+
.then(html => {
75+
expect(html).to.match(/test fastboot metadata/);
76+
});
77+
});
78+
6679
it('outputs html attributes from the fastboot app', function() {
6780
var fastboot = new FastBoot({
6881
distPath: fixture('custom-html-attrs'),

packages/fastboot/test/fixtures/app-with-default-metadata/assets/auto-import-fastboot.js

Whitespace-only changes.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
define('~fastboot/app-factory', ['fastboot-app/app', 'fastboot-app/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("fastboot-app/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("fastboot-app/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 ${err.stack || err}`;
77+
console.error(errorMessage);
78+
};
79+
}
80+
}
81+
};
82+
_exports.default = _default;
83+
});
84+
define("fastboot-app/instance-initializers/setup-fetch", ["exports", "fetch"], function (_exports, _fetch) {
85+
"use strict";
86+
87+
Object.defineProperty(_exports, "__esModule", {
88+
value: true
89+
});
90+
_exports.default = void 0;
91+
92+
/**
93+
* To allow relative URLs for Fastboot mode, we need the per request information
94+
* from the fastboot service. Then we save the request from fastboot info.
95+
* On each fetch with relative url we get host and protocol from it.
96+
*/
97+
function patchFetchForRelativeURLs(instance) {
98+
const fastboot = instance.lookup('service:fastboot');
99+
(0, _fetch.setupFastboot)(fastboot.get('request'));
100+
}
101+
102+
var _default = {
103+
name: 'fetch',
104+
initialize: patchFetchForRelativeURLs
105+
};
106+
_exports.default = _default;
107+
});//# sourceMappingURL=fastboot-app-fastboot.map

packages/fastboot/test/fixtures/app-with-default-metadata/assets/fastboot-app-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.

packages/fastboot/test/fixtures/app-with-default-metadata/assets/fastboot-app.css

Whitespace-only changes.

0 commit comments

Comments
 (0)