Skip to content

Commit

Permalink
Cleanup fastboot-app scenario tests (#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
thoov authored Sep 8, 2021
1 parent 60e16da commit ec2719c
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 242 deletions.
14 changes: 14 additions & 0 deletions tests/fixtures/fastboot-app/app/components/check-service.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div data-test="check-service">
{{#if this.message}}
{{this.message}}
{{else}}
No service present
{{/if}}
</div>
<div data-test="check-addon-file">
{{#if this.addonFileValue}}
{{this.addonFileValue}}
{{else}}
No addon file value
{{/if}}
</div>
16 changes: 16 additions & 0 deletions tests/fixtures/fastboot-app/app/components/check-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Component from '@glimmer/component';
import { getOwner } from '@ember/application';

export default class CheckServiceComponent extends Component {
constructor(...args) {
super(...args);
let service = getOwner(this).lookup('service:apps-fastboot-only');
if (service) {
this.message = service.message;
}
/* global requirejs, require */
if (requirejs.entries['from-fastboot-addon-sample']) {
this.addonFileValue = require('from-fastboot-addon-sample').default;
}
}
}
1 change: 1 addition & 0 deletions tests/fixtures/fastboot-app/app/components/example.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div data-test="example">{{this.message}}</div>
5 changes: 5 additions & 0 deletions tests/fixtures/fastboot-app/app/components/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Component from '@glimmer/component';
import { message } from '../lib/switchable';
export default class extends Component {
message = message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div data-test="lazy-component">{{this.message}}</div>
23 changes: 23 additions & 0 deletions tests/fixtures/fastboot-app/app/components/lazy-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Component from '@glimmer/component';
import { inject } from '@ember/service';
import { tracked } from '@glimmer/tracking';

export default class LazyComponent extends Component {
@inject fastboot;
@tracked message = 'loading...';

constructor(...args) {
super(...args);
if (this.fastboot.isFastBoot) {
this.fastboot.deferRendering(this.loadLibrary());
} else {
this.loadLibrary();
}
}

async loadLibrary() {
let library = (await import('@embroider/sample-lib')).default;
this.message = library();
window.lazyComponentDone = true;
}
}
1 change: 1 addition & 0 deletions tests/fixtures/fastboot-app/app/lib/switchable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const message = 'This is the browser implementation';
14 changes: 14 additions & 0 deletions tests/fixtures/fastboot-app/app/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class IndexRoute extends Route {
@service
fastboot;

beforeModel() {
// This is only to to make sure we can correctly access the request's host, which fails if FastBoot's 'hostWhitelist'
// is not correctly set up. This is the case when the changes added to /dist/package.json by FastBoot are not correctly
// merged by Embroider. So this serves as a reproduction of https://github.com/embroider-build/embroider/issues/160
return this.fastboot.isFastBoot ? this.fastboot.request.host : null;
}
}
5 changes: 5 additions & 0 deletions tests/fixtures/fastboot-app/app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div data-test="hello">Hello from fastboot-app</div>
<Example />
<AddonExample />
<CheckService />
<LazyComponent />
53 changes: 53 additions & 0 deletions tests/fixtures/fastboot-app/config/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

module.exports = function (environment) {
let ENV = {
modulePrefix: 'app-template',
environment,
rootURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: false,
},
},
fastboot: {
hostWhitelist: ['localhost:4200'],
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},
};

if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
}

if (environment === 'test') {
// Testem prefers this...
ENV.locationType = 'none';

// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;

ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;
}

if (environment === 'production') {
// here you can enable a production-specific feature
}

return ENV;
};
16 changes: 16 additions & 0 deletions tests/fixtures/fastboot-app/ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function (defaults) {
let app = new EmberApp(defaults, {});

const Webpack = require('@embroider/webpack').Webpack;
return require('@embroider/compat').compatBuild(app, Webpack, {
skipBabel: [
{
package: 'qunit',
},
],
});
};
1 change: 1 addition & 0 deletions tests/fixtures/fastboot-app/fastboot/lib/switchable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const message = 'This is the server implementation';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Service from '@ember/service';

export default class AppsFastbootOnlyService extends Service {
message = "I'm a fastboot-only service in the app";
}
36 changes: 36 additions & 0 deletions tests/fixtures/fastboot-app/tests/acceptance/basic-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { module, test } from 'qunit';
import { visit, waitUntil } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';

module('Acceptance | runtime basics', function (hooks) {
setupApplicationTest(hooks);

hooks.beforeEach(async function () {
await visit('/');
await waitUntil(() => window.lazyComponentDone);
});

test('content is rendered', function (assert) {
assert.dom('[data-test="hello"]').containsText('Hello from fastboot-app');
});

test('found browser implementation of in-app module', function (assert) {
assert.dom('[data-test="example"]').containsText('This is the browser implementation');
});

test('found browser implementation of addon service', function (assert) {
assert.dom('[data-test="addon-example"]').containsText('Browser AddonExampleService');
});

test('found no fastboot-only service from the app', function (assert) {
assert.dom('[data-test="check-service"]').containsText('No service present');
});

test('found no fastboot-only file from the addon', function (assert) {
assert.dom('[data-test="check-addon-file"]').containsText('No addon file value');
});

test('a component lazily loaded some code', async function (assert) {
assert.dom('[data-test="lazy-component"]').containsText('From sample-lib');
});
});
Loading

0 comments on commit ec2719c

Please sign in to comment.