I am trying to load HTML fixture data into a JsTestDriver test environment. I can get it to work when the jsTestDriver.conf
file is at the top level of my working directory, but I cannot get it to work if I put it in a subdirectory and try to use the basePath
feature of JsTestDriver. Has anyone got this to work? If so, what am I doing wrong?
First the directory structure that works:
├── fixtures
│ └── fix.html
├── jsTestDriver.conf
├── lib
│ └── JsTestDriver-1.3.5.jar
├── server.sh
├── test
│ └── dom.fixture.test.js
└── test.sh
The jsTestDriver.conf looks like this:
server: http://localhost:9876
# files in the server section are only added if explicitly asked for
serve:
- fixtures/fix.html
test:
- test/dom.fixture.test.js
timeout: 10
The server.sh and test.sh invoke the server and test-runner respectively:
server.sh:
PORT=9876
java -jar lib/JsTestDriver-1.3.5.jar --captureConsole --port $PORT --browser "/usr/bin/firefox;%s,/opt/google/chrome/google-chrome;%s;--allow-file-access-from-files"
test.sh
java -jar lib/JsTestDriver-1.3.5.jar --tests all --captureConsole
And I load the fixture in the dom.fixture.test.js code like so:
function getFixtureContent() {
var url = '/test/fixtures/fix.html';
var request = new XMLHttpRequest();
request.open('GET', url, false); // synchronous!
request.send(null);
return request.responseText;
}
This successfully returns the html in fix.html, which I have to then load into the DOM.
But when I push the jsTestDriver.conf file into a conf directory, I can't seem to get the embedded jetty server in JsTestDriver to find the fix.html file without using absolute path (/test//$HOME/javascript/jstd/fixtures/fix.html
), despite numerous variations attempted. By default, JSTD assumes the /test
root for Jetty to be relative to where you put the jsTestDriver.conf file. Supposedly, setting basePath
should allow you to change that.
Here's an attempt that fails:
Directory structure is the same, except jsTestDriver.conf is in a conf dir:
├── conf
│ └── jsTestDriver.conf
the paths in the jsTestDriver.conf have all been adjusted to be down a directory:
server: http://localhost:9876
# files in the server section are only added if explicitly asked for
serve:
- ../fixtures/fix.html
test:
- ../test/dom.fixture.test.js
timeout: 10
and server.sh and test.sh have two additional command line switches:
--basePath .. --config conf/jsTestDriver.conf
The rest is the same.
The error is:
<h2>HTTP ERROR 404</h2>
<p>Problem accessing /test/fixtures/fix.html. Reason:
<pre>NOT_FOUND</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/>
I have tried it with versions 1.3.5 and 1.3.4.b. Same result. Thanks to anyone who can help solve this mystery.