【问题标题】:Loading dependencies outside of the Intern directory when running tests through Selenium通过 Selenium 运行测试时在 Intern 目录之外加载依赖项
【发布时间】:2014-05-15 13:36:40
【问题描述】:

我有一个项目,实习生单元测试应该位于与被测源代码不同的目录树中。有点像这样:

projectRoot
projectRoot/src
projectRoot/tests
projectRoot/tests/intern.js
projectRoot/tests/node_modules/intern
projectRoot/tests/MyTestSuite.js

在 Intern 配置文件中,我定义了一个 AMD 程序包,它使用带有 ../ 的相对路径从单元测试套件到达 src。这是一个示例配置:

define({
  environments: [ { browserName: 'chrome', platform: 'WINDOWS' }],
  webdriver: { host: 'localhost', port: 4444 },
  useSauceConnect: false,
  loader: {
    packages: [
          { name: 'testSuites', location: '.' },
          { name: 'externalDep', location: '../src' }
        ]
  },
  suites: [ 'testSuites/MyTestSuite' ]
});

还有一个匹配的单元测试套件

define([ "intern!tdd", "intern/chai!assert","externalDep/ExternalDep"],
  function(tdd, assert, ExternalDep) {
    tdd.suite("Suite that has external dependency", function() {
      tdd.test("Test if external dependency is loaded correctly", function() {
        assert(ExternalDep === "hello");
      });
    });
  }
);

当直接在浏览器 (client.html) 或节点 (client.js) 中测试时,这可以正常工作。但是,当通过 Selenium 服务器(使用 runner.js)启动时,在由 Selenium 启动的浏览器中运行的 client.html 找不到外部依赖项。在上面的例子中,它尝试在http://localhost:9000/__intern/src/ExternalDep.js 请求ExternalDep,这是一个404,因为src 目录不在intern 中。

我想如果我将 intern.js 放在测试和源代码的最高公共超级目录中,它会起作用。但是我们的项目目前的设置方式使其不切实际。有没有办法配置超出 Intern 配置文件位置的源,或者我只是犯了一个愚蠢的错误?

谢谢!

【问题讨论】:

标签: intern


【解决方案1】:

将测试放在与其余代码不同的目录中没有问题,但projectRoot 需要是您启动运行程序的工作目录,并且您需要更改加载程序配置以匹配。

所以,不是现在你从projectRoot/tests 开始实习生,而是这样:

…/projectRoot/tests$ ./.bin/intern-runner config=intern

你需要从projectRoot开始:

…/projectRoot$ ./tests/.bin/intern-runner config=tests/intern

...并更改您的加载程序配置:

  loader: {
    packages: [
          { name: 'testSuites', location: 'tests' },
          { name: 'externalDep', location: 'src' }
        ]
  },

【讨论】:

    猜你喜欢
    • 2016-02-03
    • 2013-12-07
    • 2020-10-28
    • 1970-01-01
    • 2014-05-01
    • 1970-01-01
    • 2015-10-29
    • 1970-01-01
    • 2021-10-26
    相关资源
    最近更新 更多