I have some tests running with RequireJS and Jasmine. I have a Jasmine test harness file that looks like this:
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="./Scripts/jasmine/jasmine.css" />
<script type="text/javascript" src="./Scripts/jasmine/jasmine.js"></script>
<script type="text/javascript" src="./Scripts/jasmine/jasmine-html.js"></script>
<script type="text/javascript" src="./Scripts/jasmine/boot.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js"></script>
<script type="text/javascript">
require(["fakeTest"], function () {
window.onload();
});
</script>
</head>
<body>
</body>
</html>
My fakeTest file is very simple:
define(["require", "exports"], function (require, exports) {
describe("fake test", function () {
it("test nothing", function () {
expect(1).toEqual(1);
});
});
});
If I run this in FireFox/Chrome then everything works fine; I see one test and that it passed. If I run this with PhantomJS though, I start getting problems. Running it with the remote debugger flag I get the error:
Error: Cannot find module 'fakeTest'
phantomjs://bootstrap.js:299 in require
phantomjs://bootstrap.js:263 in require
If I try changing my harness file so that it says requirejs[("fakeTest"...... instead of just require, I get this error:
Error: Script error for "fakeTest" http://requirejs.org/docs/errors.html#scripterror
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:140 in defaultOnError
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:544 in onError
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:1732 in onScriptError :0 in appendChild
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:1952 in load
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:1679 in load
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:829 in load
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:819 in fetch
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:851 in check
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:1177 in enable
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:1550 in enable
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:1162 https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:131 https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:56 in each
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:1114 in enable
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:783 in init
https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js:1453
If I put in a completely invalid module name, I get the same errors in both cases.
I'm totally lost as to why this is happening. I've played around with changing the path for fakeTest in the harness file but nothing changes. I've simplified the harness file as much as I could, but since I'm still seeing this i'm not sure what else to try. Anyone have any ideas?
edit
I've removed everything to do with Jasmine and just have fakeTest do an alert. Now I get errors saying
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.20/require.js"></script>
<script type="text/javascript">
require(["fakeTest"], function () {});
</script>
</head>
<body>
</body>
</html>
and
define(["require", "exports"], function (require, exports) {
alert('foo');
});
"ReferenceError: Can't find variable: requirejs"