2017-06-26 2 views
0

VisualStudioソリューションでkarma.jsrequire.jsを使用しています。私のソリューションには、コード用とテスト用の2つのプロジェクトがあります。カルマとrequirejs:requirejs.configの別のプロジェクトからのパスを指定するには?

- Solution 
    + Code.Project 
    * App 
    * bower_components1 
    + Test.Project 
    * App 
    * bower_components2 
    * karma.conf.js 

私が希望:

ここ
requirejs.config({ 
    baseUrl: '/base', 

    paths: { 
    'jquery': 'bower_components2/jquery/dist/jquery'  
    }, 

    deps: tests, 
    callback: window.__karma__.start 
}); 

が私のフォルダ構造の一部である:私は私のTest.Projectに配置されているライブラリを参照する場合は、次の

は、設定が私のために正常に動作が必要ですCode.Projectではなく、からjqueryを参照してください。

requirejs.config({ 
    baseUrl: '/base', 

    paths: { 
    'jquery': '../Code.Project/bower_components1/jquery/dist/jquery'  
    }, 

    deps: tests, 
    callback: window.__karma__.start 
}); 

しかし、これは機能しません。 jQueryが見つからないと、私は次のエラーを取得する:

Uncaught Error: Script error for "jquery", needed by: App/app.spec.js 
    http://requirejs.org/docs/errors.html#scripterror 
    at node_modules/requirejs/require.js:143 

=>私は/ベースから上方に行くことができない制限がありますか?私はbaseUrlとは違う何かを使うべきですか(私は/と./を試しましたが、うまく動作しませんでした)?あるいは、私の相対的な道に間違いがありますか?

(ここで私は出発点として使用カルマとrequirejsを使用する方法の完全な例です:https://github.com/kjbekkelund/karma-requirejs

答えて

0

私は、関連する答えを見つけました(下記参照)。

また、karma.conf.jsをテストプロジェクト内ではなくSolutionフォルダに直接置くことも意味があります。それから私はコンソールに直接 "カルマスタート"を入力することができます。 (NuGetパッケージマネージャコンソール/ PowerShell用のデフォルトのパスは、ソリューションフォルダです。)Karma and RequireJS getting files outside base url

As you wrote it yourself

// Karma serves files under /base, which is the basePath from your config file baseUrl: '../',

So it means if you want to be able to access files deeper than that you need to shift all your url with a:

baseUrl: '../..',

You could also use base/ which will be understood by karma as the basePath of your karmaConf.js

For a better understanding on how the basePath of karma.conf and test-main.js works you can have a look at this: http://monicalent.com/blog/2015/02/11/karma-tests-angular-js-require-j/

から

関連する問題