nathanboktae / mocha-phantomjs

:coffee: :ghost: Run client-side mocha tests in the command line through phantomjs
MIT License
954 stars 112 forks source link

"Unable to open file" error for files in subfolders #125

Closed philippm closed 10 years ago

philippm commented 10 years ago

First of all many thanks for this useful tool!

Since version 3.3.0 I get an error when trying to run a spec file in a subfolder:

$ mocha-phantomjs coffee/spec/index.html
> Unable to open file 'path/to/rails/app/spec'

Note that it seems to be stripping to first-level folder ("coffee" in the above case).

When I run the file from within the subfolder everything works:

$ cd coffee/spec
$ mocha-phantomjs index.html
> ... test output ...

This problem does not occur in version 3.2.0.

Thank you in advance for looking into this!

kooliokey commented 10 years ago

I have the same issue happening with V 3.3.2 of Mocha-PhantomJS. From inside my project's root folder I'll run:

mocha-phantomjs spec/runner.html

and get

Unable to open file '/path/to/project/root/spec'

I've tried prefixing the path with ./ , quoting it, passing a full absolute path rather than relative and nothing works. If I cd into the spec folder it works just fine.

cd spec;
mocha-phantomjs runner.html

Not sure what the issue would be, but would be nice to get it working outside the spec folder.

nathanboktae commented 10 years ago

Sorry for the delay. I'm trying to repro the issue but I can't with 3.3.2, and I can't. What version of phantomjs are you using? How are you referencing your test scripts within your html file? I assume it's relative like <script src="../src/code.js"></script> correct?

philippm commented 10 years ago

No problem, many thanks for your reply and for looking into this.

The problem persists with the following setup:

I'm referencing the scripts as follows:

<script data-main="../../js/spec/spec_runner.js" src="../../js/lib/requirejs/require.js"></script>

Hope this helps!

nathanboktae commented 10 years ago

That's exactly my setup :/

Are you by chance trying to access files that are outside of the pwd tree? eg your runner file is 1 directory down but your specs are adjacent or higher than the current working directory?

I see you're using a require setup. Do your tests run fine when opening them in a browser?

philippm commented 10 years ago

Thank you for your quick response!

Yes, the tests run fine when I open the file in a browser.

Regarding the files outside of the pwd tree, the runner looks like this:

// Generated by CoffeeScript 1.7.1
(function() {
  var vendorPath;

  vendorPath = "../lib";

  require.config({
    baseUrl: "../../js/app",
    paths: {
      jquery: "../lib/jquery/dist/jquery",
      // ... more paths here
    },
    shim: {
      // ... shim definitions
    },
    urlArgs: "bust=" + (new Date()).getTime()
  });
  require(["require", "chai", "chai-jquery", "chai-backbone", "chai-changes", "spec/chai_validation", "sinon-chai", "sinon", "mocha", "jquery"], function(require, chai, chaiJquery, chaiBackbone, chaiChanges, chaiValidation) {
    var should;
    should = chai.should();
    window.expect = chai.expect;
    chai.use(chaiJquery);
    chai.use(chaiBackbone);
    chai.use(chaiChanges);
    chai.use(chaiValidation);
    mocha.setup("bdd");
    return require(["books" /* ... more spec files loaded here */], function(require) {
      if (window.mochaPhantomJS) {
        return mochaPhantomJS.run();
      } else {
        return mocha.run();
      }
    });
  });

}).call(this);

NB: Apologies the file is a bit convoluted, hope it helps track down the problem nonetheless.

nathanboktae commented 10 years ago

OK what's the full command path your passing in? Did you install phantom via npm? And if so globally or locally?

philippm commented 10 years ago

I installed via npm globally.

Not sure I understand your question about the full command path. I try to run the tests like so:

mocha-phantomjs coffee/spec/index.html

The mocha-phantomjs executable is installed in /usr/local/bin.

nathanboktae commented 10 years ago

Er oops I meant what are all the command line options you're passing into mocha-phantomjs ? And which phantomjs says phantomjs is where?

philippm commented 10 years ago

I run mocha-phantomjs without any command-line arguments.

Both phantomjs and mocha-phantomjs are located in /usr/local/bin.

nathanboktae commented 10 years ago

@philippm would you mind trying out the phantom-peer-dependency branch and see if that fixes your issue? you can change your dependency on mocha-phantomjs to a git one via this in your package.json:

  "mocha-phantomjs": "git://github.com/metaskills/mocha-phantomjs.git#phantom-peer-dependency"
philippm commented 10 years ago

@nathanboktae sure thing!

We don't use a package.json file so I installed it as follows:

$ npm uninstall -g mocha-phantomjs
$ npm install -g "git://github.com/metaskills/mocha-phantomjs.git#phantom-peer-dependency"
$ mocha-phantomjs --version
3.4.0

When I then try to run the specs I get this error:

$ mocha-phantomjs coffee/spec/index.html

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:988:11)
    at Process.ChildProcess._handle.onexit (child_process.js:779:34)

This also occurs when I try to run the spec file from within its folder:

$ cd coffee/spec
$ mocha-phantomjs index.html
# ... same error as above

Am I doing something wrong?

nathanboktae commented 10 years ago

Am I doing something wrong?

No, I was :disappointed: I'm now getting the path via require.resolve instead of trying to be smart about it.

try again? maybe npm uninstall and then reinstall is needed.

philippm commented 10 years ago

I just reran the uninstall/install commands from my previous comment, but it appears we're now back to the original error:

$ cd /Volumes/Data/Projects/Flag/books/app
$ mocha-phantomjs coffee/spec/index.html
> Unable to open file '/Volumes/Data/Projects/Flag/books/app/spec'

The error message differs slightly to the original one, as it now shows the full path.

Running from within the spec folder works:

$ cd coffee/spec
$ mocha-phantomjs coffee/spec/index.html
> # ... mocha test suites running

NB: I'm not sure if this makes a difference but the spec file is located on a mounted (encrypted) disk image.