-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathfastboot-config-location-test.mjs
More file actions
123 lines (106 loc) · 3.39 KB
/
fastboot-config-location-test.mjs
File metadata and controls
123 lines (106 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import qunit from 'qunit';
import { merge } from 'lodash-es';
import { appScenarios } from './scenarios.mjs';
import emberServe from './helpers/ember-serve.mjs';
import fetch from 'node-fetch';
const { module: Qmodule, test } = qunit;
appScenarios
.map('fastboot-config-location', (project) => {
merge(project.files, {
app: {
routes: {
'redirect-on-transition-to.js': `
import Route from '@ember/routing/route';
import * as serviceModule from '@ember/service';
const service = serviceModule.service || serviceModule.inject;
export default class MyRoute extends Route {
@service
router;
beforeModel() {
this.router.transitionTo('test-passed');
}
}
`,
'test-passed.js': `
import Ember from 'ember';
export default Ember.Route.extend({});
`,
},
templates: {
'test-passed.hbs': `<h1>The Test Passed!</h1>
<p>All redirection tests should be set up to redirect here.</p>`,
},
'router.js': `
import Ember from 'ember';
let Router = Ember.Router;
Router.map(function() {
this.route('redirect-on-transition-to');
this.route('test-passed');
});
export default Router;
`,
},
config: {
'environment.js': `
'use strict';
module.exports = function(environment) {
var ENV = {
rootURL: '/',
locationType: 'auto',
environment: environment,
modulePrefix: 'classic-app-template',
fastboot: {
fastbootHeaders: false,
hostWhitelist: [/localhost:\\d+/],
redirectCode: 302,
}
};
return ENV;
};
`,
},
});
project.removeDependency('ember-fetch');
})
.forEachScenario((scenario) => {
Qmodule(scenario.name, function (hooks) {
let app; // PreparedApp
let process;
hooks.before(async () => {
app = await scenario.prepare();
process = await emberServe(app);
});
hooks.after(() => {
return process.stop();
});
test('use the redirect code provided by the EmberApp', async function (assert) {
const response = await fetch(`http://localhost:${process.port}/redirect-on-transition-to`, {
headers: {
Accept: 'text/html',
},
redirect: 'manual',
});
if (response.status === 500) throw new Error(await response.text());
assert.equal(response.status, 302);
assert.equal(
response.headers.get('location'),
`http://localhost:${process.port}/test-passed`
);
});
Qmodule('when fastboot.fastbootHeaders is false', function () {
test('should not send the "x-fastboot-path" header on a redirect', async function (assert) {
const response = await fetch(
`http://localhost:${process.port}/redirect-on-transition-to`,
{
redirect: 'manual',
headers: {
Accept: 'text/html',
},
}
);
if (response.status === 500) throw new Error(await response.text());
assert.notOk(response.headers.has('x-fastboot-path'));
});
});
});
});