jejacks0n / teaspoon

Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
1.43k stars 244 forks source link

Testing in engine Not loading *_spec.js #492

Open ngelx opened 8 years ago

ngelx commented 8 years ago

Hi, i'm working on an engine (gem) that has some js code to be tested but seems i can't get it working. I've followed the wiki article and set a basic example.

unless defined?(Rails)
  ENV["RAILS_ROOT"] = File.expand_path("../dummy", __FILE__)
  require File.expand_path("#{ENV["RAILS_ROOT"]}/config/environment", __FILE__)
end

Teaspoon.configure do |config|
...
  config.root = MyEngineName::Engine.root
...
end
desc "Run the javascript specs"
task :teaspoon => "app:teaspoon"
describe("My great feature", function() {
  it("Bang", () => {
    expect(true).toBe(false);
  });
});

The problem is that when i try to run the test engine, i'm getting

$> teaspoon 
Starting the Teaspoon server...
Thin web server (v1.7.0 codename Dunder Mifflin)
Maximum connections set to 1024
Listening on 127.0.0.1:57036, CTRL+C to stop
Teaspoon running default suite at http://127.0.0.1:57036/teaspoon/default

Finished in 0.01600 seconds
0 examples, 0 failures

I've also try to run the following commands, with the same result:

I have not much a clue of what is not working. As non standard app, i'm using es6 through browserify-rails (which is working ok), and got in engine.rb:

config.browserify_rails.paths = [
    lambda { |p| p.start_with?(MyEngineName::Engine.root.join("app").to_s) }
]

Any help or clue would be much appreciated.

ngelx commented 8 years ago

Any idea? Sorry but i can't get it to work and i'm run out of ideas.

jejacks0n commented 8 years ago

Check where the teaspoon_env is in the teaspoon repo. And its contents. That might help?


Jeremy Jackson

On Jul 13, 2016, at 5:22 AM, Angel notifications@github.com wrote:

Any idea? Sorry but i can't get it to work and i'm run out of ideas.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

ngelx commented 8 years ago

I've double check it, but still running 0 examples. Also I've created an engine form strach and set up a very basic test, in order to check if the problem was some kind of weird configuration on main engine. No success either. It seems that i'm definitely missing something.

The test engine is here

In Particular, the commit that add the teaspoon test/config is this one

Any help will be much appreciated.

ngelx commented 8 years ago

Found it! The issue was that the spec was written with arrow functions. If it is re-write to old plain js it runs as expected.

I've managed to test es6 code inside my app, but i'm just wondering if it is possible to write specs using es6. When i try to do something like

// spec/javascript/hello_spec.js

import Hello from "hello";
...

I'm getting

....
 Error: Cannot find module 'hello' from '/vagrant/engine_teaspoon_example/spec/javascripts' 
....

You can test the code in this example repo. es6 branch.

To reproduce it, just make sure you are on the right branch and run

teaspoon spec/javascripts/hello_spec.js

vkoves commented 6 years ago

I've had (I think), a similar issue where a file I pulled in using require didn't actually load because it used arrow functions. This failure was silent, which made it very difficult to trace, and I'm not sure why that isn't allowed. Do I need to convert it to ES5 code before Teaspoon can handle it?