-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup fastboot-app scenario tests (#964)
- Loading branch information
Showing
15 changed files
with
193 additions
and
242 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
tests/fixtures/fastboot-app/app/components/check-service.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
tests/fixtures/fastboot-app/app/components/check-service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div data-test="example">{{this.message}}</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
tests/fixtures/fastboot-app/app/components/lazy-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const message = 'This is the browser implementation'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
], | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const message = 'This is the server implementation'; |
5 changes: 5 additions & 0 deletions
5
tests/fixtures/fastboot-app/fastboot/services/apps-fastboot-only.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
tests/fixtures/fastboot-app/tests/acceptance/basic-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
Oops, something went wrong.