Including libraries fails - what is document root?

只愿长相守 提交于 2019-12-24 16:00:23

问题


I have a file (src/inc.js) that loads certain files into my browser using jquery's ajax:

$.ajax({url: 'somefile.js', async: false, dataType: 'script', 
    error: function(qXHR, textStatus, errorThrown) {
        console.log(
            '[' + textStatus + '] ' 
            + errorThrown + ' with: ' + this.url
        );
    }
});

and this file gets included via browserification into my browser (phantomjs). Gruntfile.js:

browserify: {
    libs: {
        src: ['src/*.js'],
        dest: 'test/libs.js'
    }
}

and handed to karma (in Gruntfile.js):

karma: {
    options: {
        files: ['test/libs.js']
    }
}

but when it runs the file can't be found:

aprilis:test ekkis$ grunt test-web

Running "browserify:libs" (browserify) task

Bundle test/libs.js created.

Running "karma:phantom" (karma) task 25 01 2016 18:36:56.498:INFO [karma]: Karma v0.13.16 server started at http://localhost:9877/

25 01 2016 18:36:56.506:INFO [launcher]: Starting browser PhantomJS

25 01 2016 18:36:58.424:INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket wqi-DFYcij9hs0_6AAAA with id 61800957

25 01 2016 18:36:58.489:WARN [web-server]: 404: /somefile.js?=1453775818448 PhantomJS 1.9.8 (Mac OS X 0.0.0) LOG: '[error] Not Found with: ./somefile.js?=1453775818448'

PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 128 of 128 (1 FAILED) (0.029 secs / 0.047 secs) Warning: Task "karma:phantom" failed. Use --force to continue.

Aborted due to warnings.

(do notice that the server complains about /somefile.js but the path (logged) was provided as ./somefile.js. this also happens if the path provided is ../somefile.js ends up as /somefile.js as well)

I'm assuming that when phantomjs runs the document root is the root of the project? so in that case perhaps $.ajax({url: 'test/somefile.js' should work? it doesn't. what is the document root when the run is made (where am I supposed to put the file so I can access it)?

来源:https://stackoverflow.com/questions/35006306/including-libraries-fails-what-is-document-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!