Skip to content

Commit f5c87f8

Browse files
committed
move fastboot-location-config to scenario-tester
1 parent 4d899b4 commit f5c87f8

File tree

10 files changed

+126
-136
lines changed

10 files changed

+126
-136
lines changed

packages/ember-cli-fastboot/test/fastboot-location-config-test.js

Lines changed: 0 additions & 73 deletions
This file was deleted.

packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/router.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/routes/redirect-on-transition-to.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/routes/test-passed.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/templates/application.hbs

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/templates/test-passed.hbs

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/config/environment.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/config/targets.js

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

test-packages/test-scenarios/helpers/ember-serve.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { execaNode } from 'execa';
22

33
export default async function emberServe(app) {
4-
return new Promise((resolve, reject) => {
5-
const process = execaNode('node_modules/ember-cli/bin/ember', ['serve', '-p', '0'], { cwd: app.dir });
4+
return new Promise((resolve) => {
5+
const process = execaNode('node_modules/ember-cli/bin/ember', ['serve', '-p', '0'], {
6+
cwd: app.dir,
7+
});
68

79
process.stdout.on('data', (value) => {
810
const line = value.toString();

0 commit comments

Comments
 (0)