GithubHelp home page GithubHelp logo

embermap / ember-cli-fastboot-testing Goto Github PK

View Code? Open in Web Editor NEW
39.0 39.0 18.0 14.71 MB

Test your FastBoot-rendered HTML alongside your application's tests.

Home Page: https://embermap.github.io/ember-cli-fastboot-testing

License: MIT License

JavaScript 87.13% HTML 3.55% CSS 0.71% Handlebars 8.61%

ember-cli-fastboot-testing's People

Contributors

chrism avatar cvx avatar danwenzel avatar dependabot-preview[bot] avatar dependabot[bot] avatar dnalagatla avatar ember-tomster avatar eoneill avatar gfmartinez avatar gilest avatar haochuan avatar jherdman avatar jkeen avatar ryanto avatar samselikoff avatar sergeastapov avatar thoov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ember-cli-fastboot-testing's Issues

Build fails with latest Babel.js

Babel.js v7.11.1 was released earlier today and since then in our build we see errors like

04-Aug-2020 22:22:26 | cleaning up...
-- | --
04-Aug-2020 22:22:26 | Build Error (broccoli-persistent-filter:Babel > [Babel: ember-cli-fastboot-testing]) in ember-cli-fastboot-testing/test-support/-private/mock-server.js
04-Aug-2020 22:22:26 |  
04-Aug-2020 22:22:26 | /opt/bamboo_homes/bamboo-home1/xml-data/build-dir/GLOBE-UAF48-RATE/packages/agwa/ember-cli-fastboot-testing/test-support/-private/mock-server.js: Unexpected token (19:11)
04-Aug-2020 22:22:26 |  
04-Aug-2020 22:22:26 | 17 \|
04-Aug-2020 22:22:26 | 18 \| export let mockServer = {
04-Aug-2020 22:22:26 | > 19 \|   async get(path, response, status = 200) {
04-Aug-2020 22:22:26 | \|            ^
04-Aug-2020 22:22:26 | 20 \|     return createMock(path, "GET", status, response);
04-Aug-2020 22:22:26 | 21 \|   },
04-Aug-2020 22:22:26 | 22 \|
04-Aug-2020 22:22:26 |  
04-Aug-2020 22:22:26 |  
04-Aug-2020 22:22:26 | Stack Trace and Error Report: /tmp/error.dump.56b192bda8efa3169008d27ec1477668.log

Same error is reproducible via Babel REPL.

I think it fails because async getters are not a thing in JavaScript.

Testing for redirects behaves differently in local tests vs. CI

I have a route that redirects i.e. there is a replaceWith call in the redirect hook.

In local testing, when calling visit on the redirecting URL, the status code returned is 200, and the DOM returned is that of the final, redirected page.

However, when running the same test on CI (Circle), the status code returned is 307 (temporary redirect) and the DOM appears to be the original, non-redirected page.

In other words, it appears that visit on CI is returning the original page, whilst local tests are returning the final redirected page.

This may not be an issue with the add-on, and in fact, given the purpose of the add-on is to test the first render, it may be beyond its scope to test this case in this way. Though the differing results between local and CI seem odd.

If this is expected behaviour, I'd be grateful for any pointers as to why, and how to test for this case.

FastBoot.distPath returns deleted path upon running `ember test`

Not sure, if this is an issue with ember-cli-fastboot-testing addon but just wanted to report my observation. In my app code, in FastBoot only scenario, I am accessing the dist path using public getter FastBoot.distPath to get access to a Static JSON content.

The application works with issues upon running ember s and tests are passing upon using ember test --serve. But when I run just ember test then FastBoot.distPath usage failed as the path defined there is deleted.

Upon investigation, I noticed that ember test invokes the postBuild hook with broccoli temp path and deletes that path after a successful build. As a result use of FastBoot.distPath fails.

I have workaround by running ember build first and using the --path argument with ember test. But still wanted to check if there is any recommendation here for this use-case

Do not use ember-ajax

Could we not use ember-ajax ? It is relying on jQuery being present and so will not work in apps without jQuery.

Allow user to access fastboot instance in fastboot-testing.js config

Feature Request

This is the follow up feature request for #57

Currently in config/fastboot-testing.js, we have a way to customize the sandbox provided to FastBoot:

module.exports = {
  resilient: false,
  sandboxGlobals: {}
};

Add it would be super useful if in the config file, we can have a way to access the fastboot instance, which is created in the _createServer function inside index.js.

Proposal

Let's say I have the following config/fastboot-testing.js:

module.exports = {
  resilient: false,
  sandboxGlobals: {},
  setupFastboot: fastbootInstance => {
    // do something with the fastbootInstance here
  },
};

To make it work, we need to add the checking below in index.js:

_createServer(distPath) {
   // ...
  this.fastboot = new FastBoot(fastbootOptions);

  // In test config, you can define a function `setupFastboot` to have access to the fastboot instance
  if (options.setupFastboot && typeof options.setupFastboot === 'function') {
    options.setupFastboot(this.fastboot);
  }
}

Please let me know if that makes sense, I will have a PR for this soon 😄 . Thanks!

Monorepo support

I had forgotten about this until I recently began cleaning up EmberData's root package.json and hit the issue again. This project requires re-declaring all ember-cli and ember-source deps into monorepo-root in order for it to resolve them. It needs instead to properly resolve dependencies from the workspace root.

Error messages are not escaped

Saw this with a Fastboot error:

image

I think chromespeak Array.map(<anonymous>) is rendered unescaped and treated as containing an HTML tag.

Technically, this is an XSS vulnerability. 😬

upgrading from 0.0.13 to 0.0.14 breaks tests

My app uses ember-fetch, so my package.json declares:
https://github.com/mirai-audio/mir/blob/4468041c729b3fc30cdfed8bd2f52ac6406f2a1e/package.json#L95-L97

...
"fastbootDependencies": [
    "node-fetch"
  ]

my test is pretty basic:
https://github.com/mirai-audio/mir/blob/master/tests/fastboot/welcome-route-test.js

import { module, test } from 'qunit';
import { setup, visit } from 'ember-cli-fastboot-testing/test-support';

module('FastBoot | welcome route test', function(hooks) {
  setup(hooks);

  test('it renders the /welcome route', async function(assert) {
    let { htmlDocument } = await visit('/welcome');
    assert.dom('title', htmlDocument).hasText('mirai.audio');
    assert.dom('div').includesText('Play everything, play everywhere');
  });
});

currently passes on 0.0.13, but going to 0.0.14 breaks the test.

... 
There was an error running your app in fastboot. More info about the error:
 Error: Assertion Failed: You attempted to define a `{{link-to "application"}}` but did not pass the parameters required for generating its dynamic segments. Cannot find module 'abortcontroller-polyfill/dist/cjs-ponyfill' from '/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets'
    at new EmberError (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/@ember/error/index.js:37:1)
    at assert (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/@ember/debug/index.js:125:1)
    at Class.computeLinkToComponentHref (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:1972:1)
    at ComputedProperty.get (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-metal.js:2515:1)
    at _get (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-metal.js:1356:1)
    at RootPropertyReference.compute (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:346:1)
    at RootPropertyReference.value (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:223:1)
    at ComponentElementOperations.flush (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/@glimmer/runtime.js:1327:1)
    at Object.evaluate (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/@glimmer/runtime.js:860:1)
    at AppendOpcodes.evaluate (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/@glimmer/runtime.js:46:1)
    at LowLevelVM.evaluateSyscall (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/@glimmer/runtime.js:2895:1)
    at LowLevelVM.evaluateInner (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/@glimmer/runtime.js:2867:1)
    at LowLevelVM.evaluateOuter (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/@glimmer/runtime.js:2859:1)
    at VM.next (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/@glimmer/runtime.js:4787:1)
    at TemplateIteratorImpl.next (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/@glimmer/runtime.js:4879:1)
    at RootState.render (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4070:1)
    at TransactionRunner.runInTransaction (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-metal.js:406:1)
    at InertRenderer._renderRoots (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4340:1)
    at InertRenderer._renderRootsTransaction (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4372:1)
    at InertRenderer._revalidate (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4412:1)
    at invokeWithOnError (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:283:1)
    at Queue.flush (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:186:1)
    at DeferredActionQueues.flush (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:353:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:808:1)
    at Backburner.end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:558:1)
    at Backburner._run (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:847:1)
    at Backburner._join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:829:1)
    at Backburner.join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:612:1)
    at Array.loopEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4185:1)
    at Backburner._trigger (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:901:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:820:1)
    at Backburner.end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:558:1)
    at Backburner._run (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:847:1)
    at Backburner._join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:829:1)
    at Backburner.join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:612:1)
    at Array.loopEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4185:1)
    at Backburner._trigger (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:901:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:820:1)
    at Backburner.end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:558:1)
    at Backburner._run (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:847:1)
    at Backburner._join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:829:1)
    at Backburner.join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:612:1)
    at Array.loopEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4185:1)
    at Backburner._trigger (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:901:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:820:1)
    at Backburner.end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:558:1)
    at Backburner._run (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:847:1)
    at Backburner._join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:829:1)
    at Backburner.join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:612:1)
    at Array.loopEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4185:1)
    at Backburner._trigger (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:901:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:820:1)
    at Backburner.end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:558:1)
    at Backburner._run (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:847:1)
    at Backburner._join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:829:1)
    at Backburner.join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:612:1)
    at Array.loopEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4185:1)
    at Backburner._trigger (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:901:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:820:1)
    at Backburner.end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:558:1)
    at Backburner._run (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:847:1)
    at Backburner._join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:829:1)
    at Backburner.join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:612:1)
    at Array.loopEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4185:1)
    at Backburner._trigger (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:901:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:820:1)
    at Backburner.end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:558:1)
    at Backburner._run (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:847:1)
    at Backburner._join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:829:1)
    at Backburner.join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:612:1)
    at Array.loopEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4185:1)
    at Backburner._trigger (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:901:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:820:1)
    at Backburner.end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:558:1)
    at Backburner._run (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:847:1)
    at Backburner._join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:829:1)
    at Backburner.join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:612:1)
    at Array.loopEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4185:1)
    at Backburner._trigger (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:901:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:820:1)
    at Backburner.end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:558:1)
    at Backburner._run (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:847:1)
    at Backburner._join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:829:1)
    at Backburner.join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:612:1)
    at Array.loopEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4185:1)
    at Backburner._trigger (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:901:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:820:1)
    at Backburner.end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:558:1)
    at Backburner._run (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:847:1)
    at Backburner._join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:829:1)
    at Backburner.join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:612:1)
    at Array.loopEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4185:1)
    at Backburner._trigger (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:901:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:820:1)
    at Backburner.end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:558:1)
    at Backburner._run (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:847:1)
    at Backburner._join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:829:1)
    at Backburner.join (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:612:1)
    at Array.loopEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/ember-glimmer.js:4185:1)
    at Backburner._trigger (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:901:1)
    at Backburner._end (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:820:1)
    at Backburner._boundAutorunEnd (/var/folders/1t/rw1tf_f56zq4qc9mnvk38xrr0000gn/T/broccoli-635989Jkue2teQwtI/out-402-srihash_assets/assets/backburner.js:528:1)
(node:63598) UnhandledPromiseRejectionWarning: Error: infinite rendering invalidation detected
(node:63598) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 8)
(node:63598) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
not ok 25 Chrome 73.0 - [379 ms] - FastBoot | welcome route test: it renders the /welcome route
    ---
        actual: >

        expected: >
            mirai.audio
        stack: >
                at DOMAssertions.hasText (http://localhost:7357/assets/test-support.js:9861:20)
                at Object.<anonymous> (http://localhost:7357/assets/tests.js:371:41)
        message: >
            Element title has text "mirai.audio"
        negative: >
            false
        Log: |
    ...

Details:

yarn produces the following relevant versions:

$ grep '"version"' -B 1 node_modules/*fastboot*/package.json
node_modules/ember-cli-fastboot-testing/package.json-  "name": "ember-cli-fastboot-testing",
node_modules/ember-cli-fastboot-testing/package.json:  "version": "0.0.13",
--
node_modules/ember-cli-fastboot/package.json-  "name": "ember-cli-fastboot",
node_modules/ember-cli-fastboot/package.json:  "version": "2.0.4",
--
node_modules/fastboot-express-middleware/package.json-  "name": "fastboot-express-middleware",
node_modules/fastboot-express-middleware/package.json:  "version": "1.2.0",
--
node_modules/fastboot-transform/package.json-  "name": "fastboot-transform",
node_modules/fastboot-transform/package.json:  "version": "0.1.3",
--
node_modules/fastboot/package.json-  "name": "fastboot",
node_modules/fastboot/package.json:  "version": "1.2.1",
$ ember --version --verbose
DEPRECATION: ember-cli-babel 5.x has been deprecated. Please upgrade to at least ember-cli-babel 6.6. Version 5.2.8 located: mir -> ember-test-component -> ember-cli-babel
ember-cli: 3.9.0
http_parser: 2.8.0
node: 10.15.3
v8: 6.8.275.32-node.51
uv: 1.23.2
zlib: 1.2.11
ares: 1.15.0
modules: 64
nghttp2: 1.34.0
napi: 3
openssl: 1.1.0j
icu: 62.1
unicode: 11.0
cldr: 33.1
tz: 2018e
os: darwin x64

Reproduce

The repo is currently using this addon v0.0.13, so all you'd have to do to reproduce is just upgrade to 0.0.14 and run ember test --filter "FastBoot | Welcome"

git clone [email protected]:mirai-audio/mir.git
ember test --filter "FastBoot | Welcome" # should pass test
yarn test --filter "FastBoot | Welcome" # should pass test
# upgrade to 0.0.14
ember test --filter "FastBoot | Welcome" # should pass test
yarn test --filter "FastBoot | Welcome" # should FAIL test

Error: Request entity too large

I'm using ember-cli-fastboot-testing in couple with ember-cli-mirage. Sometimes returned data is very large (returned by factories) and as a result ExpressJS throws and error: Request entity too large. I was able to fix it by adding following lines (by specifying limit in (specify a limit in bodyparser). I can create PR with this changes, but probably we might allow user to configure some other parameters in bodyParser and implement this with external config (possible might lead to more issues since we will give more complex API to addon user)?

app.post('/__mock-request', bodyParser.json({ limit: '50mb' }), (req, res) => {

Support Mocha

Hi!

I've been able to run ember-cli-fastboot-testing with ember-mocha.

Unfortunately, yarn link breaks the app for me, so I wasn't able to make a PR quickly. Also, I used a weird hack. Hopefully, you'll be able to find a better solution.

When porting the test file to Mocha, I ran into two issues.

  1. ember-mocha requires running a setup helper. It has a few to offer, and every one of them runs setupContext and teardownContext. Since running those twice crashes the test pipeline, ember-cli-fastboot-testing can't be used, so I had to make my own without setupContext and teardownContext.

  2. My tests started passing, but the test pipeline crashed on teardown after all tests. The error was from inside Glimmer, where it was doing something like parent.remove(child) and crashing with "this child does not belong to this parent".

    I was able to identify the parent as the testing container. The child turned out to be the application div inside the container, that happens to be there before visit from ember-cli-fastboot-testing is called.

    I managed to fix the issue with a weird workaround. In the before hook, I remove the content of the test container and stash it. In the after hook, I put it back! It feels like an ugly hack 🙈, but it did unblock ember-cli-fastboot-testing for me.

So here's my setup helper that enables ember-cli-fastboot-testing to be used with ember-mocha:

import { mockServer } from 'ember-cli-fastboot-testing/test-support';
import getRootElement from '@ember/test-helpers/dom/get-root-element';


export function setupMockServer(hooks) {
  let children;

  hooks.beforeEach(async function() {
    await mockServer.cleanUp();
    children = removeChildrenFromParent();
  });

  hooks.afterEach(async function() {
    await mockServer.cleanUp();
    removeChildrenFromParent();
    restoreChildrenToParent(children);
  });
}


function removeChildrenFromParent(parent = getRootElement()) {
  const children = [];

  while (parent.firstChild) {
    children.push(parent.firstChild);
    parent.removeChild(parent.firstChild);
  }

  return children;
}


function restoreChildrenToParent(children, parent = getRootElement()) {
  children.forEach(child => {
    parent.appendChild(child);
  })
}

Add network mocking

Creating an issue to track development on network mocking in fastboot-testing. Feel free to use this issue to ask and answer questions related to mocking!

PR here: #31

[0.6.0] req.headers.origin undefined in CLI mode

version 0.6.0
ember-auto-import: 2.4.0
ember 3.28.0

When I run my fastboot test in browser mode it passes:

image

When I run it in cli mode it fails with:

Error: Ember CLI FastBoot Testing: We were unable to render /p/abc123. Is your test suite blocking or intercepting HTTP requests

Noticing it's missing the x-fastboot-testing header

{
  connection: 'keep-alive',
  'content-length': '22',
  'content-type': 'text/html; charset=utf-8',
  date: 'Tue, 08 Feb 2022 01:10:53 GMT',
  etag: '\\16-Iz+hV1iVsvp6pCFWupm+jyvhDK8\\',
  'keep-alive': 'timeout=5',
  vary: 'Accept-Encoding',
  'x-powered-by': 'Express'
}

Any suggestions on what could cause this?

edit 1

Was able to determine that it fails due to missing request origin header in cli mode at this line:
https://github.com/embermap/ember-cli-fastboot-testing/blob/v0.6.0/lib/helpers.js#L42

We need to use a fallback value for CLI mode where req.headers.origin is undefined:

const parsed = new URL(urlToVisit, req.headers.origin);

e.g.

 const origin = req.headers.origin || 'http://localhost';
 const parsed = new URL(urlToVisit, origin);

Include all request headers in Fastboot request?

That PR I submitted yesterday (#12) added the user-agent request header, but now I'm realizing I need the cookie header also to test that fastboot can serve pages requiring authentication. I have a PR ready, but before I add another one-off I thought I'd ask if we shouldn't just include all the request headers? Can you think of a reason not to, @ryanto ?

A future for this repo.

Thanks, heaps @ryanto, for your work on this repo. It is the go-to testing harness for fastboot applications.

Would you consider moving ember-cli-fastboot-testing into the ember-cli-fastboot addon as the bundled testing harness for fastboot?

The other option would be to add this addon to when ember-cli-fastboot is installed.

I would love to hear your thoughts, Ryan.

Thanks again for all your hard work to make this the go-to testing harness for fastboot.

Cheers
Dave

mockServer.get not working

Hello,

I'm trying to set up a fastboot rendering test and running into a problem where I can't seem to get mockServer.get() to work, and the test is instead hitting my real api.

my real api looks like: https://...api.com/v1/posts/:id

in the test I tried:
await mockServer.get('https://...api.com/v1/posts/abc123', {
await mockServer.get('/v1/posts/abc123', {
await mockServer.get('v1/posts/abc123', {
await mockServer.get('/posts/abc123', {
await mockServer.get('posts/abc123', {

How might I be able to further debug this? I turned off mirage autostart so mirage shouldnt be running either..

test command:
ember t -s -m 'FastBoot | routes/post'

Separate question: Is it expected to have to add 0.0.0.0:7357 to the fastboot whitelist in config? I had to do that to get past a separate error message.

Does not work with path=dist

When running:

ember build --environment=test`
ember test --path=dist`

...fastboot tests fail with Unexpected token C in JSON at position 0.

This is due to the request to __fastboot-testing returning a 500 Cannot read property 'visit' of undefined, probably thrown from this line.

I believe this is because the fastboot object is set up in the postBuild hook: https://github.com/embermap/ember-cli-fastboot-testing/blob/master/index.js#L158

...but postBuild does not run when running tests with path=dist

Add notice for testing with fake servers

For example, Mirage needs this, otherwise requesting /__fastboot-testing fails:

// mirage/config.js
export default function() {
  this.passthrough('/__fastboot-testing');
  // ...
}

Doesn't work in fresh app

ember new my-app
ember install ember-cli-fastboot ember-cli-fastboot-testing
ember s
> Error: Could not find module `fetch/setup` imported from `my-app/instance-initializers/setup-fetch`

I triggered a rebuild from Travis but it passed, I wonder why our tests aren't catching this?

Could not find module `fetch` imported from `ember-cli-fastboot-testing/test-support/index`

Hi,

After installing the addon with
ember install ember-cli-fastboot-testing

and generating a test with
ember g fastboot-test fingerprinted-path

I get this error when trying to run the tests with
ember test --server

TestLoader Failures: dummy/tests/fastboot/fingerprinted-path-test: could not be loaded (1, 0, 1)


Error: Could not find module `fetch` imported from `ember-cli-fastboot-testing/test-support/index`
  at missingModule (http://localhost:7357/assets/vendor-098320b95328ca4de617a0498ced5e00.js:252:11)
  at findModule (http://localhost:7357/assets/vendor-098320b95328ca4de617a0498ced5e00.js:263:7)
  at Module.findDeps (http://localhost:7357/assets/vendor-098320b95328ca4de617a0498ced5e00.js:173:24)
  at findModule (http://localhost:7357/assets/vendor-098320b95328ca4de617a0498ced5e00.js:267:11)
  at Module.findDeps (http://localhost:7357/assets/vendor-098320b95328ca4de617a0498ced5e00.js:173:24)
  at findModule (http://localhost:7357/assets/vendor-098320b95328ca4de617a0498ced5e00.js:267:11)
  at requireModule (http://localhost:7357/assets/vendor-098320b95328ca4de617a0498ced5e00.js:29:15)
  at TestLoader.require (http://localhost:7357/assets/tests-17afb8ac72971fb2872e0fe3db40269c.js:2803:9)
  at TestLoader.loadModules (http://localhost:7357/assets/tests-17afb8ac72971fb2872e0fe3db40269c.js:2796:14)
  at loadTests (http://localhost:7357/assets/tests-17afb8ac72971fb2872e0fe3db40269c.js:3440:22)

I'm using the addon to test an addon I'm working on.

Thanks!

Config not working

I'm running into an issue where defining config/fastboot-testing.js isn't working as expected.

I was able to determine that the addon code indeed finds the config and exports it to be initialized with Fastboot(), however when the tests actually run, the global URL is not set properly and so my test fails.

I'm not sure why the global would not be available when the test runs or how to debug this?

For more info see my comment here:
ember-fastboot/ember-cli-fastboot#816 (comment)

edit 1

I determined the reason this fails is due to the version of fastboot in this addon.

It seems that buildSandboxGlobals() isn't working in 2.X but is working in latest 3.2.0-beta.2

Not sure how to proceed other than disabling my fastboot tests until either 3.0 comes out and/or the URL issue is resolved, but open to ideas!

najax not present when using jQuery in v0.4/v0.5

I'm trying to update ember-data's fastboot tests from v0.2. v0.3 works fine.

Starting in 0.4 however @ember/jquery seems to fail to correctly import jquery into the vendor shim and thus no jQuery global is present. No other dependencies are being changed and our fastboot version, ember-source version, and @ember/jquery is the latest release in all cases.

I haven't been able to determine what changed between 0.3 and 0.4 to trigger this (there are very few changes that aren't dependency changes), but wanted to surface this here in case anyone using jQuery still bumps into an error telling them they need to install ember-fetch after upgrading to 0.4 or 0.5.

Edit: after looking through the codepaths it seems the jQuery global check was a red herring, it's always false in fastboot. When using jQuery najax needs to be installed, this used to be brought by fastboot itself but that support was changed in 3.x which v0.4 here bumped to (a deprecation would have been nice, but oh well). The solution here was to install the beta of ember-cli-fastboot 3.x, the latest fastboot, the latest najax, and to configure config/fastboot-testing.js

module.exports = {
  resilient: true,
  buildSandboxGlobals(defaultGlobals) {
    const additionalGlobals = {};
    try {
      const najax = require('najax'); // eslint-disable-line
      additionalGlobals.najax = najax;
    } catch (e) {
      // we only add the global if najax is installed
    }
    return Object.assign({}, defaultGlobals, additionalGlobals);
  },
};

Skip outputReady in production builds

The outputReady hook shouldn't need to run in production builds:

// we have to use the outputReady hook to ensure that ember-cli has finished copying the contents to the outputPath directory
outputReady(result) {

Seems implementing isEnabled() will do this (currently only in the included hook:

const isEnabled =
this.app.name === 'dummy' || this.app.env !== 'production';
if (!isEnabled) return;


The specific issue I'm running into is that result.directory is wrong when this hook is called (I'm trying out embroider and not yet sure if it's an issue with that or something else).

Details about the failure

When ember-cli calls the outputReady hook, the directory is correct (with my custom --output-path):
https://github.com/ember-cli/ember-cli/blob/26b2ee9f1b9f3431d7b96a7f850464007281eb35/lib/models/builder.js#L152

[ember-cli:builder] buildResults.directory /var/folders/dw/l307h_b16vzc0wys2f_nbmm00000gn/T/broccoli-121748JRezg9nx2Ji/out-1244-packager_runner_embroider_webpack
[ember-cli:builder] outputPath /dev/my-app/custom-dist-path
[ember-cli:builder] combinedOptions .directory /dev/my-app/custom-dist-path

CALLING outputReady for fb-testing with results.directory /dev/my-app/custom-dist-path

But inside the hook itself, it's wrong, using some default value

[ember-cli-fastboot-testing] process.env.EMBER_CLI_TEST_OUTPUT undefined
[ember-cli-fastboot-testing] result.directory /dev/my-app/dist <----- THIS IS WRONG

My only guess as to what's happening is that the object is getting updated somehow, but I'm not sure.

Environment is "development" instead of "test" during tests

Hi! I don't know if this is a bug here or maybe on FastBoot - or maybe I am missing something. But this code is evaluating "development" instead of "test":

let config = getOwner(this).resolveRegistration('config:environment');
config.environment // => "development"

This happens only in FastBoot tests. In acceptance tests it evaluates "test".

FastBoot service request info is uninitialized

The current value of the request object is the below. This breaks tests written against apps that rely on any of this data. For example, mine needs the request path to determine the locale.

request:
  FastBootRequest {
    hostWhitelist: [Array],
    protocol: 'undefined:',
    headers: [FastBootHeaders],
    queryParams: undefined,
    path: undefined,
    method: undefined,
    body: undefined,
    cookies: {} },

Option to throw on error in `visit`

We've found this kind of syntax useful:

const result = await visit('/home');

if (result.err)
  throw result.err;

Seems like something that could be useful to bake into the visit helper.

Visit helper not returning correct content upon using `this.replaceWith` for redirection

Currently, the Visit helper returns <body><h1>Redirecting to ... as DOM content instead of the DOM of the route to which the initial route redirects using this.replaceWith.

The issue is happening at this returned value - https://github.com/embermap/ember-cli-fastboot-testing/blob/master/index.js#L86

As fastboot provides the html content based on the statusCode and if it is a redirection getting redirection text - https://github.com/embermap/ember-cli-fastboot-testing/blob/master/addon-test-support/index.js#L46

I think for testing the finalized body should be provided by using page.domContents().body as HTML content.

Allow more customization of network mocking urls

nock has several customization options that would be nice to implement in ember-cli-fastboot-testing's network mocking. Just to mention a few:

  • Setting of the hostname - Currently, we are limited to using the same hostname as the test runner. Oftentimes we have a separate api host that we'd like to override.
  • Customizing the path - Currently, we can only use exact path matches - it would be great to be able to use RegEx or the includes option.
  • Customizing the query string - Similar to above, it would be really helpful to explicitly specify the query string, use regex, or use nock's .query(true) option to ignore the query string altogether. Otherwise, it's only a match if the query string is appended to the url with the exact full string.

We also have this issue: https://github.com/embermap/ember-cli-fastboot-testing/issues

It seems like we either need a way to use nock's syntax when creating these mocks, or expand the API to allow several different customization options. Maybe something like:

await mockServer.get('/api/posts/1', { <body>}, { <options> } )

(we'd have to move the status code into an option, and maybe deprecate the string as a 3rd param)

I'd be happy to work on a PR for this once we land on the approach.

Support for ember projects with a rootURL containing a subdirectory

Hi Ya'll!

Unless I am mistaken, it doesn't appear this library supports ember projects hosted from within a subdirectory: rootURL: "/my-ember-app/" for example.

mockServer and visit all assume the ember project is being hosted at the bare root and as a result requests are missing the ember app.

I've poked around the code and see a few places I think would need to be changed to respect the host app's rootURL configuration. Let me know if this is something you plan on supporting or think would be easy to add support for.

Excellent work on the project. I was really excited to get this up and running and the documentation is stellar!

incompatibile with ember-exam?

Hi there!

First of all - thank you for great addon!

I'm not sure it's necessarily a defect, maybe just "how things work". If my assumptions are correct - maybe worth to add this as a note somewhere in docs.

We use ember-exam to parallelize tests sugar following command:

ember exam --split=4 --parallel=1

As we started to write more fastBoot tests, they started to flow into different partitions.
At the same time what we observed is that FastBoot tests sporadically fail.

My assumption is:
when tests run, ember-cli-fastboot-testing creates instance of testemMiddleware (here).

As we parallelize tests and run them in 4 browser instances at the same time, FastBoot tests may be split between different browser instances.
After every test run afterEach hook calls /__cleanup-mocks url (from here, defined here).

Due to multiple threads of test runners but single instance of testemMiddleware - mocks may be cleaned up while some other test is running, which may cause tests to fail sporadically (execution order and execution timing in not guarantied when we have 4 browser instances running in parallel).

Please share your thoughts on this.

As a mitigation, we changed test command to following:

ember exam --split=4 --parallel=1 --filter='!Fastboot |' && ember test --filter='Fastboot |'

Cut new release v0.6.1

Hi @ryanto! Would you be able to cut a new release v0.6.1 with all the improvements and updates made in the past year or so?

Allow for custom host in mockServer calls

In our application, our api proxies to a different host, which prevents us from being able to use the mockServer to respond to the calls generated by the fastboot acceptance tests.

It would be great to just specify the hostname in the creation of a mockServer endpoint.

For example, if we are running our tests on localhost:4200 and had mockServer.get('htttp://localhost:3000/path/to/api', response) then when the fastboot application test visits a page that relies on those calls to localhost:3000, the mockServer can respond.

Currently, due to the way the mockServer is created via nock, this is impossible to do.
PR to follow shortly :)

Allow to specify request body on serverMock

Server mocks are great! I have already been using it and works nicely.

I'm using it to mock a GraphQL server. While it has been working fine for my set of simple tests, for me to be able to use it further, I would need to be able to mock requests on the same path but differentiate it on the request body.

It seems that nock does support this use case: https://github.com/nock/nock#specifying-request-body

Note that all requests to a GraphQL server are POST methods.

Supporting request body as String, RegExp and JSON object should do the trick.

Allow user to pass functions inside the `options` parameter while calling `visit`

Feature Request

This is the follow up feature request for #60.

#60 give us the ability to pass custom visit options to fastboot.visit. Since it's using JSON.stringify to prepare the body for calling /_fastboot-testing, any function will be dropped during this process.

Example Use Case

This is very critical to our Ember Fastboot apps since we are using a number of heavily customized addons in our use case. In order to use this addon to test our SSR content, we need to have the way to pass functions in the options to fastboot.visit.

Sample test file:

import { module, test } from 'qunit';
import { setup, visit } from 'ember-cli-fastboot-testing/test-support';

module('Fastboot | basic', function(hooks) {
  setup(hooks);

  test('custom visit options', async function(assert) {
    const options = {
      metadata: {
        myFunc: () => {}
      }
    }
    await visit('/', options);
    // ....
  });
});

In this case, the actual option in fastboot.visit will be:

{
  metadata: {}
}

Proposal

Although json is not designed to store any function in general, it's good to give users the ability to pass anything to fastboot. In the proposed changes below, we are using a simple helper library json-fn, to stringify and parse the options.

In addon-test-support/index.js:

import JSONfn from 'json-fn';
// ...
let fetchFromEmberCli = async function(url, options) {
  // ...
  try {
    response = await fetch('/__fastboot-testing', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        url,
        options: JSONfn.stringify(options), // before: options: options
      }),
    });
  } catch (e) {
      // ...
};

In index.js:

let JSONfn = require('json-fn');

module.exports = {
  // ...
  _fastbootRenderingMiddleware(app) {
    // ...
    app.post('/__fastboot-testing', bodyParser.json(), (req, res) => {
      let urlToVisit = decodeURIComponent(req.body.url);
      let parsed = url.parse(urlToVisit, true);

      // ...

      // before:  let options = Object.assign(defaultOptions, req.body.options);
      let options = Object.assign(defaultOptions, JSONfn.parse(req.body.options));
      // ...
    });
  },
};

Please let me know if that makes sense, I will have a PR for this soon 😄 . Thanks!

Broken build on CI

The build is currently broken because of postcss-less, which requires node ">=6.14.4" while some Travis instances come with versions as low as 6.12.

IMO the best course of action is to just drop node 6 (PR #62).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.