6

Intern ユニット テストが、テスト対象のソース コードとは別のディレクトリ ツリーにあるはずのプロジェクトがあります。ややこのように:

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ため、404 である でExternalDep を要求しようとします。src

テストとソース コードの両方の共通スーパー ディレクトリの最上位に intern.js を配置すれば、うまくいくと思います。しかし、私たちのプロジェクトは現在、それを非現実的にする方法で設定されています。Intern 構成ファイルの場所を超えて存在するソースを構成する方法はありますか、それともばかげた間違いを犯したのでしょうか?

ありがとう!

4

1 に答える 1

1

コードの残りの部分とは別のディレクトリにテストを配置しても問題はありませんがprojectRoot、ランナーを開始する作業ディレクトリである必要があり、一致するようにローダーの構成を変更する必要があります。

したがって、今すぐ Intern を開始する場所ではなく、次の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' }
        ]
  },
于 2014-06-08T04:44:04.890 に答える