tricknotes / ember-cli-rails

Unify your EmberCLI and Rails Workflows
http://thoughtbot.github.io/ember-cli-rails/
MIT License
713 stars 205 forks source link

Fail to test #462

Closed williamweckl closed 8 years ago

williamweckl commented 8 years ago

Which operating system and version is the project developed on? Ubuntu 16.04

Which version of [ruby][ruby] is the project developed on? 2.3.1

Which version of [npm][npm] is the project developed on? 3.8.3

Which version of [ember-cli][ember-cli] is the project developed on? 2.5.1

What is the [rails][rails] version? 4.2.6

What is the [ember-cli-rails][gem] version (from Gemfile)? 0.7.4

What is the [ember-cli-rails-addon][addon] version (from package.json)? 0.7.0

What are the contents of config/initializers/ember.rb?

EmberCli.configure do |c|
  c.app :frontend, path: Rails.root.join('frontend').to_s
end

What are the contents of the Rails' view that renders the Ember application?

<!DOCTYPE html>
<html dir="ltr" lang="<%= I18n.locale %>">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><%= title %></title>
    <%= stylesheet_link_tag 'frontend' %>
    <%= javascript_include_tag 'frontend' %>
    <base href="/frontend/">
    <%= include_ember_script_tags :frontend %>
    <%# include_ember_stylesheet_tags :frontend %>
    <%= csrf_meta_tags %>
  </head>

  <body>
    <%= render 'layouts/top' if user_signed_in? %>
    <%= render_ember_app :frontend %>
    <%= yield %>
  </body>
</html>

How are the EmberCLI-related routes defined?

mount_ember_app :frontend, to: "/frontend/", controller: "frontend"
get 'frontend/*' => 'frontend#index'

Running rake ember:test from project root or ember test from /frontend giving the below error:

Looks like you have a different program called watchman, falling back to NodeWatcher.
Visit http://ember-cli.com/user-guide/#watchman for more info.
Built project successfully. Stored in "/home/william/dev/saas-internal/frontend/tmp/class-tests_dist-P6ZuPn5P.tmp".
not ok 1 Browser "phantomjs /home/william/dev/saas-internal/frontend/node_modules/testem/assets/phantom.js http://localhost:7357/9241/tests/index.html?hidepassed" failed to connect. testem.js not loaded?
Stdout: 
ReferenceError: Can't find variable: Ember
   http://localhost:7357/9241/tests/index.html?hidepassed : 38

1..1
# tests 1
# pass  0
# skip  0
# fail  1
Not all tests passed.
Error: Not all tests passed.
    at EventEmitter.App.getExitCode (/home/william/dev/saas-internal/frontend/node_modules/testem/lib/app.js:382:14)
    at EventEmitter.<anonymous> (/home/william/dev/saas-internal/frontend/node_modules/testem/lib/app.js:195:39)
    at /home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:726:13
    at /home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:52:16
    at /home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:269:32
    at /home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:44:16
    at /home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:723:17
    at /home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:167:37
    at EventEmitter.App.removeSignalListeners (/home/william/dev/saas-internal/frontend/node_modules/testem/lib/app.js:411:5)
    at /home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:718:13
    at iterate (/home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:262:13)
    at /home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:274:29
    at /home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:44:16
    at Server.<anonymous> (/home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:723:17)
    at Server.<anonymous> (/home/william/dev/saas-internal/frontend/node_modules/async/lib/async.js:167:37)
    at Server.g (events.js:273:16)

What am I missing?

williamweckl commented 8 years ago

Figured out that my frontend/tests/index.html should call assets with ../:

<script src="../testem.js" integrity=""></script>

Anyway, this file has been generated by the gem, could be fixed to generate as expected to work?

seanpdoyle commented 8 years ago

@williamweckl thanks for opening this issue.

Looking at the contents of your code snippets, a few things seem to be misconfigured, which might or might not be contributing to your problems.

We recommend that you use the render_ember_app helper, as it renders the EmberCLI-generated index.html file (a fully-formed and valid HTML document) into your Rails view.

Alternatively, the include_ember_script_tags and include_ember_stylesheet_tags helpers can be used to serve the EmberCLI-generated asset files from Rails, making them available from Rails views.

However, keep in mind that using the include style helpers is deprecated, in favor of the render_ember_app helper.

Whichever style of helper you pick, you should only use one style or the other.


mount_ember_app :frontend, to: "/frontend/", controller: "frontend"
get 'frontend/*' => 'frontend#index'

The mount_ember_app helper already declares a get route with a splat and an text/html contraint, so you could probably omit your get declaration.


this file has been generated by the gem

I think that file is generated by ember new, not the gem.

I'm a bit surprised that the solution was to modify that file. I've never had to modify the tests/index.html file for any Ember application.

I see that you're declaring a <base> tag in your Rails view. Have you configured your Ember application to use /frontend as the rootURL?

seanpdoyle commented 8 years ago

I'm closing this due to inactivity.

@williamweckl if you're still experiencing this issue, please respond to https://github.com/thoughtbot/ember-cli-rails/issues/462#issuecomment-226784935 and we'll reopen it.