How do you serve svg and fixtures with Karma Runner (aka Testacular)

后端 未结 2 1947
小鲜肉
小鲜肉 2020-12-31 06:56

I\'ve been trying for the past two hours to get Karma runner to serve an svg file and an html fixture but so far no luck.

Following the second answer on this thread:

相关标签:
2条回答
  • 2020-12-31 06:59

    Answering my own question here...

    I was trying to load my fixtures athttp://localhost:9876/fixtures/directional-pad.html

    Instead I should have tried accessing them at http://localhost:9876/base/test/fixtures/directional-pad.html

    Karma stores everything under the base/ route, so any static file routes you add will need to start with that.

    0 讨论(0)
  • 2020-12-31 07:21

    One way to do this is to set-up a proxy server.

    A good example of a test system using a proxy server is https://github.com/yearofmoo-articles/AngularJS-Testing-Article

    which is the example from Year of Moo's great testing tutorial. http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-testacular.html

    You set the proxy up in the karma config file

    proxies = {
      '/': 'http://localhost:8100/'
    };
    

    Then you need to set-up the server on 8100

    this can be done using http-server

    npm install http-server --save-dev

    then create two files

    ./server.sh

    nf --procfile ./config/Procfile.server start
    

    ./config/Procfile.server

    web_server: ./node_modules/http-server/bin/http-server -p 8100 preview/public
    

    Then you need to run you server

    ./server.sh
    

    Then when you run the tests, the proxy will serve up your files.

    0 讨论(0)
提交回复
热议问题