2017-04-09 5 views
0

Ich habe eine Testdatei wie das, was am Ende ist. Ich habe Knoten FILENAME, npm FILENAME probiert, die mir Fehler bringen. Ich habe auch npm Test versucht, die etwas anderes zu testen scheinen (nach der Testdatei angehängt). Ich bin neu zu eckig und habe mir die Demo angeschaut, aber ich bin mir nicht wirklich sicher, was ich tun soll.Wie wird eine eckige Testdatei verwendet?

-Code von hier: https://github.com/vega/vega-lite-ui (nicht von mir)

Testdatei:

'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 Testergebnisse:

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 

Antwort

0

Ich versuche, mich würde zu erklären, was passiert, wenn Sie Test NPM Ihr Projekt und wie Sie bestimmte Dateien testen können.

Wenn Sie npm test in Ihre Shell eingeben, entspricht dies einem Skript in package.json Datei.

"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" 
}, 

Wie Sie sehen können, gibt es eine gulp test Befehl, der auf npm test läuft.

Also, lass uns jetzt zu gulpfile.js gehen.

In Ende der Datei gibt es eine Zeile

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

All diese Aufgaben hinzugefügt werden hier zu schlucken, und ich sah in Ihrem GitHub repo, dass es ein großen Schluck Verzeichnis drin ist.

Im Innern gibt es unit-tests.js-Datei, die diese Funktion hat

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

Wie Sie sehen können, ist es Karma beginnen den Pfad der Konfigurationsdatei und Rückruf, indem.

Also, die karma.conf.js bewegen lassen,

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' 
]); 

Dies sind die Datei und deps, ist Karma für Sie testen (btw ist Karma ein Test-Framework). Sie können jede Datei hinzufügen, die Sie mit ihren Abhängigkeiten testen möchten.

Ich würde auch vorschlagen, dass Sie zuerst ein Tutorial durchgehen, bevor Sie in den Winkeleinheitstest gehen. This Blog ist wirklich nett dafür.

Verwandte Themen