Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After finding a solution here is what I learned: The short answer to the exact above question is <strong>you can't do that</strong>. Node reads absolute paths as absolute paths. So the answer in short was to change my paths from absolute to <em>pseudo-absolute</em> (relative) paths. Here is a quote from <a href="http://titaniumninja.com/testing-titanium-mobile-applications-with-jasmine-and-sinon-part-i/" rel="nofollow">this blog post</a> that sheds some light:</p> <blockquote> <p>the Titanium implementation of CommonJS <code>require()</code> is <a href="https://jira.appcelerator.org/browse/TIDOC-514" rel="nofollow">buggy</a> and doesn’t correctly support relative paths. This represents a major problem when trying to integrate jasmine-node test runners in projects with even minimally complex directory trees.</p> <p>A possible solution to the issue is to not use relative paths in <code>require()</code> in Titanium (but you are free to use them in your jasmine specs run through node). Instead of relative paths we need to use full paths with <code>Resources</code> as the root directory.</p> </blockquote> <p>This is accomplished by setting the <code>NODE_PATH</code> environment variable prior to running any node commands. That way a path such as `require("module/path") is resolved by node <em>and</em> titanium.</p> <p>There are a few caveats. Some module force the need for absolute paths. In this case one needs <a href="https://github.com/thlorenz/proxyquire" rel="nofollow">proxyquire</a> to mock out the absolute paths as long as there are not any circular dependancies this will work. Also since node does not have Titanium API's you also have to include the <a href="https://github.com/russfrank/mockti" rel="nofollow">mockti</a> package to mock out the Titanium API. Use this in your spec_helper.js:</p> <pre><code>global.Ti = require("mockti"); </code></pre> <p>and</p> <pre><code>proxyquire = require("proxyquire"); var myModule = proxyquire("relative/path/to/MyModule", { "/absolute/path/to/some/module": require("absolute/path/to/some/module") }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload