Skip to content

Commit

Permalink
move fastboot-location-config to scenario-tester
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Feb 11, 2024
1 parent 4d899b4 commit f5c87f8
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 136 deletions.
73 changes: 0 additions & 73 deletions packages/ember-cli-fastboot/test/fastboot-location-config-test.js

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

122 changes: 122 additions & 0 deletions test-packages/test-scenarios/fastboot-location-config-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
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-location-config', (project) => {
merge(project.files, {
app: {
routes: {
'redirect-on-transition-to.js': `
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
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.body.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.body.text());
assert.notOk(response.headers.has('x-fastboot-path'));
});
});
});
});
6 changes: 4 additions & 2 deletions test-packages/test-scenarios/helpers/ember-serve.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { execaNode } from 'execa';

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

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

0 comments on commit f5c87f8

Please sign in to comment.