diff --git a/packages/ember-cli-fastboot/test/fastboot-location-config-test.js b/packages/ember-cli-fastboot/test/fastboot-location-config-test.js deleted file mode 100644 index b00213165..000000000 --- a/packages/ember-cli-fastboot/test/fastboot-location-config-test.js +++ /dev/null @@ -1,73 +0,0 @@ -/* eslint-disable no-undef */ -'use strict'; - -const expect = require('chai').expect; -const RSVP = require('rsvp'); -const request = RSVP.denodeify(require('request')); - -const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp; - -describe('FastBootLocation Configuration', function () { - this.timeout(300000); - - let app; - - before(function () { - app = new AddonTestApp(); - - return app - .create('fastboot-location-config', { - emberVersion: 'latest', - emberDataVersion: 'latest', - }) - .then(function () { - app.editPackageJSON((pkg) => { - delete pkg.devDependencies['ember-fetch']; - delete pkg.devDependencies['ember-welcome-page']; - // needed because @ember-data/store does `FastBoot.require('crypto')` - pkg.fastbootDependencies = ['crypto']; - }); - return app.run('npm', 'install'); - }) - .then(function () { - return app.startServer({ - command: 'serve', - }); - }); - }); - - after(function () { - return app.stopServer(); - }); - - it('should use the redirect code provided by the EmberApp', function () { - return request({ - url: 'http://localhost:49741/redirect-on-transition-to', - followRedirect: false, - headers: { - Accept: 'text/html', - }, - }).then(function (response) { - if (response.statusCode === 500) throw new Error(response.body); - expect(response.statusCode).to.equal(302); - expect(response.headers.location).to.equal( - '//localhost:49741/test-passed' - ); - }); - }); - - describe('when fastboot.fastbootHeaders is false', function () { - it('should not send the "x-fastboot-path" header on a redirect', function () { - return request({ - url: 'http://localhost:49741/redirect-on-transition-to', - followRedirect: false, - headers: { - Accept: 'text/html', - }, - }).then(function (response) { - if (response.statusCode === 500) throw new Error(response.body); - expect(response.headers).to.not.include.keys(['x-fastboot-path']); - }); - }); - }); -}); diff --git a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/router.js b/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/router.js deleted file mode 100644 index 25a6ad097..000000000 --- a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/router.js +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint-disable ember/new-module-imports, prettier/prettier */ -import Ember from 'ember'; - -let Router = Ember.Router; - -Router.map(function() { - this.route('redirect-on-transition-to'); - this.route('test-passed'); -}); - -export default Router; diff --git a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/routes/redirect-on-transition-to.js b/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/routes/redirect-on-transition-to.js deleted file mode 100644 index e0b5fa45b..000000000 --- a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/routes/redirect-on-transition-to.js +++ /dev/null @@ -1,8 +0,0 @@ -/* eslint-disable ember/new-module-imports, prettier/prettier */ -import Ember from 'ember'; - -export default Ember.Route.extend({ - beforeModel() { - this.transitionTo('test-passed'); - } -}); diff --git a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/routes/test-passed.js b/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/routes/test-passed.js deleted file mode 100644 index 567c2b55d..000000000 --- a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/routes/test-passed.js +++ /dev/null @@ -1,4 +0,0 @@ -/* eslint-disable ember/new-module-imports */ -import Ember from 'ember'; - -export default Ember.Route.extend({}); diff --git a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/templates/application.hbs b/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/templates/application.hbs deleted file mode 100644 index 5230580f8..000000000 --- a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/templates/application.hbs +++ /dev/null @@ -1,3 +0,0 @@ -

Welcome to Ember

- -{{outlet}} \ No newline at end of file diff --git a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/templates/test-passed.hbs b/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/templates/test-passed.hbs deleted file mode 100644 index cad7fc851..000000000 --- a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/app/templates/test-passed.hbs +++ /dev/null @@ -1,4 +0,0 @@ -

The Test Passed!

- -

All redirection tests should be set up to redirect here.

- diff --git a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/config/environment.js b/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/config/environment.js deleted file mode 100644 index 95d513ddf..000000000 --- a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/config/environment.js +++ /dev/null @@ -1,18 +0,0 @@ -/* eslint-disable no-undef, prettier/prettier */ -'use strict'; - -module.exports = function(environment) { - var ENV = { - rootURL: '/', - locationType: 'auto', - environment: environment, - modulePrefix: 'fastboot-location-config', - fastboot: { - fastbootHeaders: false, - hostWhitelist: [/localhost:\d+/], - redirectCode: 302, - } - }; - - return ENV; -}; diff --git a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/config/targets.js b/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/config/targets.js deleted file mode 100644 index 67994db90..000000000 --- a/packages/ember-cli-fastboot/test/fixtures/fastboot-location-config/config/targets.js +++ /dev/null @@ -1,13 +0,0 @@ -/* eslint-disable no-undef */ -'use strict'; - -const browsers = [ - 'last 1 Chrome versions', - 'last 1 Firefox versions', - 'last 1 Safari versions', -]; - -module.exports = { - browsers, - node: 'current', -}; diff --git a/test-packages/test-scenarios/fastboot-location-config-test.mjs b/test-packages/test-scenarios/fastboot-location-config-test.mjs new file mode 100644 index 000000000..334682b9d --- /dev/null +++ b/test-packages/test-scenarios/fastboot-location-config-test.mjs @@ -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': `

The Test Passed!

+ +

All redirection tests should be set up to redirect here.

`, + }, + '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')); + }); + }); + }); + }); diff --git a/test-packages/test-scenarios/helpers/ember-serve.mjs b/test-packages/test-scenarios/helpers/ember-serve.mjs index 6e3e7399f..bd8bf6e0e 100644 --- a/test-packages/test-scenarios/helpers/ember-serve.mjs +++ b/test-packages/test-scenarios/helpers/ember-serve.mjs @@ -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();