2017-04-09 7 views
0

私は最後にあるもののようなテストファイルを持っています。私はノードFILENAME、npm FILENAMEを試してきましたが、エラーが出ます。また、何かをテストするように見えるnpm test(テストファイルの後ろに添付)を試しました。私は角度をつけて新しく、デモを見ましたが、私は何をすべきかわかりません。ここから角度テストファイルの使用方法は?

コード:https://github.com/vega/vega-lite-ui(ない鉱山)

テストファイル:

'use strict'; 

/* global vl:true */ 

describe('Directive: bookmarkList', function() { 
    var element, 
    scope; 

    afterEach(inject(function(Modals) { 
    // Remove any modals registered during the tests 
    Modals.empty(); 
    })); 

    beforeEach(module('vlui', function($provide) { 
    // mock vega lite 
    $provide.constant('vl', vl); 
    })); 

    beforeEach(inject(function ($rootScope) { 
    scope = $rootScope.$new(); 
    scope.active = true; 
    })); 

    it('requires a parent modal directive', inject(function ($compile) { 
    // This is a side-effect of the modalCloseButton directive inside bookmarkList 
    element = angular.element('<bookmark-list></bookmark-list>'); 
    expect(function() { 
     $compile(element)(scope); 
    }).to.throw; 
    element = angular.element('<modal><bookmark-list></bookmark-list></modal>'); 
    expect(function() { 
     $compile(element)(scope); 
    }).not.to.throw; 
    })); 

    describe('when opened', function() { 
    beforeEach(inject(function(Modals, $compile) { 
     var template = '<modal id="test-bookmarks"><bookmark-list></bookmark-list></modal>'; 
     element = $compile(angular.element(template))(scope); 
     Modals.open('test-bookmarks'); 
     scope.$digest(); 
    })); 

    // TODO: Tests that validate the directive works properly 
    }); 
}); 

NPMのテスト結果:

START: 
09 04 2017 01:03:39.411:WARN [watcher]: Pattern "/Users/me/psa/polestar/src/vendor/*.js" does not match any file. 
09 04 2017 01:03:39.522:INFO [karma]: Karma v1.6.0 server started at http://0.0.0.0:9875/ 
09 04 2017 01:03:39.523:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency 
09 04 2017 01:03:39.531:INFO [launcher]: Starting browser PhantomJS 
09 04 2017 01:03:40.644:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket BU46HqpjWzeEkmYvAAAA with id 72055404 
    Service: Spec 
    ✔ should be defined 
    ✔ functions should be defined 
    _removeEmptyFieldDefs 
     empty spec 
     ✔ should be cleaned 
    Directive: configurationEditor 
    ✔ should insert form 
    ✔ should attach config to scope 
    Directive: jsonInput 
    ✔ should make hidden element visible 
    Directive: lyraExport 
    ✔ should make hidden element visible 
    Directive: vgSpecEditor 
    ✔ should show source code 
    Directive: vlSpecEditor 
    ✔ should show source code 

Finished in 0.26 secs/0.066 secs 

SUMMARY: 
✔ 9 tests completed 
[01:03:41] Finished 'test' after 2.17 s 

答えて

0

私はつもりあなたがテストをNPM時に何が起こっているかを説明しようとしていますプロジェクト、および特定のファイルをテストする方法について説明します。

シェルにnpm testと入力すると、これに対応するpackage.jsonファイルにスクリプトがあります。

"scripts": { 
    "postinstall": "bower install", 
    "deploy": "npm run lint && npm run test && scripts/deploy.sh", 
    "watch": "gulp watch", 
    "build": "gulp build", 
    "lint": "gulp jshint", 
    "test": "gulp test" 
}, 

あなたが見ることができるように、npm test上で実行されますgulp testコマンドがあります。

だから、今度はgulpfile.jsに移動しましょう。

は、ファイルの一番下では、これらのすべてのタスクはここに飲み込むために追加された行

gulp.task('default', ['jshint', 'test', 'build', 'watch']); 

あります、と私はそれで一気ディレクトリがあることを、あなたのGitHub repoで見ました。その中

、あなたが見ることができるように

function runTests (singleRun, done) { 
karma.start({ 
    configFile: __dirname + '/../karma.conf.js', 
    singleRun: singleRun 
    }, function() { done(); }); 
} 

この機能を持っているunit-tests.jsファイルは、そこにある、それは設定ファイルやコールバックのパスを渡すことでカルマを開始しています。

ので、これらのファイルとDEPSある

var testFiles = [ 
    // add bind polyfill since Function.prototype.bind is missing from PhantomJS 
    './node_modules/phantomjs-polyfill/bind-polyfill.js', 
].concat(bowerDeps.js).concat([ 
    src + '/vendor/*.js', 
    src + '/index.js', 
    src + '/**/*.js', 
    tmp + '/partials/templateCacheHtml.js', 
    tmp + '/schema/vl-schema.js' 
]); 

、の karma.conf.jsを移動させ、カルマ(ところでカルマテストフレームワークである)あなたのためにテストしています。テストするファイルを依存関係とともに追加することができます。

角度単位テストに入る前に、最初にチュートリアルを進めることをお勧めします。 Thisブログは本当に素晴らしいです。

関連する問題