【问题标题】:How do you serve svg and fixtures with Karma Runner (aka Testacular)您如何使用 Karma Runner(又名 Testacular)提供 svg 和固定装置
【发布时间】:2013-04-10 23:57:13
【问题描述】:

过去两个小时我一直在尝试让 Karma runner 提供一个 svg 文件和一个 html 固定装置,但到目前为止还没有成功。

在此线程上的第二个答案之后:Error while integrating html with testacularjs 我一直在尝试使用served 来表示我的固定装置和 svg 文件应该由服务器分发,但我仍然得到“未找到”

files = [
  JASMINE,
  JASMINE_ADAPTER,
  REQUIRE,
  REQUIRE_ADAPTER,

  // put all components in requirejs 'paths' config here (included: false)
  { pattern: 'preview/public/components/**/*.js', included: false },
  { pattern: 'preview/public/js/**/*.js', included: false },

  // assets
  { pattern: 'preview/public/img/svg/*.svg', included: false, served: true },

  // helpers & fixtures for jasmine-jquery
  { pattern: 'test/libs/**/*.js', included: true },
  { pattern: 'test/fixtures/**/*.html', included: false, served: true },

  // all src and test modules (included: false)
  { pattern: 'test/specs/**/*.spec.js', included: false },

  // test main require module last
  'test/test-main.js'
];

我将jasmine.getFixtures().fixturesPath 设置为/fixtures,我可以看到它使用了正确的路径,但我最终还是...

GET http://localhost:9876/img/svg/directional-pad-gradients.svg 404 (Not Found) GET http://localhost:9876/fixtures/directional-pad.html 404 (Not Found)

如果有人有使用 Karma runner 加载固定装置和/或 svg 的示例,我会真的看看。谢谢!

【问题讨论】:

    标签: angularjs karma-runner


    【解决方案1】:

    在这里回答我自己的问题...

    我试图在http://localhost:9876/fixtures/directional-pad.html 加载我的装置

    相反,我应该尝试通过 http://localhost:9876/base/test/fixtures/directional-pad.html 访问它们

    Karma 将所有内容存储在 base/ 路由下,因此您添加的任何静态文件路由都需要从该路由开始。

    【讨论】:

    • 既然你使用的是 karma 和灯具,你能帮帮我吗? -> stackoverflow.com/questions/16209749/… 在此先感谢 :)
    • 只有当你在 karma 配置中使用 basePath 选项时才这样吗?我注意到 Karma 还可以将东西存储在 absolute/ 目录中。
    【解决方案2】:

    一种方法是设置代理服务器。

    使用代理服务器的测试系统的一个很好的例子是 https://github.com/yearofmoo-articles/AngularJS-Testing-Article

    这是来自 Moo 伟大测试教程的示例。 http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-testacular.html

    您在 karma 配置文件中设置了代理

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

    那你需要在8100上设置服务器

    这可以使用 http-server 来完成

    npm install http-server --save-dev

    然后创建两个文件

    ./server.sh

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

    ./config/Procfile.server

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

    然后你需要运行你的服务器

    ./server.sh
    

    然后,当您运行测试时,代理将提供您的文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-20
      • 2013-05-15
      • 2019-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多