var RSVP = require('rsvp'); var SimpleDOM = require('simple-dom'); var appModule = require('./helpers/app-module'); function assertHTMLMatches(assert, actualHTML, expectedHTML) { assert.ok(actualHTML.match(expectedHTML), actualHTML + ' matches ' + expectedHTML); } function handleError(assert) { return function(error) { assert.ok(false, error.stack); }; } // This is based on what fastboot-server does var HTMLSerializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap); function fastbootVisit(App, url) { var doc = new SimpleDOM.Document(); var rootElement = doc.body; var options = { isBrowser: false, document: doc, rootElement: rootElement }; return App.visit(url, options).then(function(instance) { try { return { url: instance.getURL(), title: doc.title, body: HTMLSerializer.serialize(rootElement), }; } finally { instance.destroy(); } }); } function assertFastbootResult(assert, expected) { return function(actual) { assert.equal(actual.url, expected.url); assertHTMLMatches(assert, actual.body, expected.body); }; } appModule('Ember.Application - visit() Integration Tests'); QUnit.test('FastBoot: basic', function(assert) { this.routes(function() { this.route('a'); this.route('b'); }); this.template('application', '
Error template rendered!
'); this.template('a', 'Error template rendered!
', }), handleError(assert) ), ]); }); QUnit.test('Resource-discovery setup', function(assert) { this.service('network', { init: function() { this.set('requests', []); }, fetch: function(url) { this.get('requests').push(url); return RSVP.resolve(); }, }); this.routes(function() { this.route('a'); this.route('b'); this.route('c'); this.route('d'); this.route('e'); }); this.route('a', { model: function() { return this.network.fetch('/a'); }, afterModel: function() { this.replaceWith('b'); }, }); this.route('b', { model: function() { return this.network.fetch('/b'); }, afterModel: function() { this.replaceWith('c'); }, }); this.route('c', { model: function() { return this.network.fetch('/c'); }, }); this.route('d', { model: function() { return this.network.fetch('/d'); }, afterModel: function() { this.replaceWith('e'); }, }); this.route('e', { model: function() { return this.network.fetch('/e'); }, }); this.template('a', '{{x-foo}}'); this.template('b', '{{x-foo}}'); this.template('c', '{{x-foo}}'); this.template('d', '{{x-foo}}'); this.template('e', '{{x-foo}}'); var xFooInstances = 0; this.component('x-foo', { init: function() { this._super(); xFooInstances++; }, }); var App = this.createApplication(); App.inject('route', 'network', 'service:network'); function assertResources(url, resources) { return App.visit(url, { isBrowser: false, shouldRender: false }).then(function(instance) { try { var viewRegistry = instance.lookup('-view-registry:main'); assert.strictEqual(Object.keys(viewRegistry).length, 0, 'did not create any views'); var networkService = instance.lookup('service:network'); assert.deepEqual(networkService.get('requests'), resources); } finally { instance.destroy(); } }, handleError(assert)); } return RSVP.all([ assertResources('/a', ['/a', '/b', '/c']), assertResources('/b', ['/b', '/c']), assertResources('/c', ['/c']), assertResources('/d', ['/d', '/e']), assertResources('/e', ['/e']), ]).then(function() { assert.strictEqual(xFooInstances, 0, 'it should not create any x-foo components'); }); }); QUnit.test('FastBoot: tagless components can render', function(assert) { this.template('application', "