2014-09-26 8 views
2

각도 응용 프로그램을 테스트 할 수 있도록 Intern.io를 설정하려고합니다. 나는 Grunt and Bower도 사용하고 있습니다. 나는 barebones가 자동으로 테스트를 실행하는 작업을 보게하려고 노력하고 있습니다. 내 문제는 내가 테스트를 실행하려고 나는 다음과 같은 오류 메시지가 있습니다 :각과 intern.io가 함께 작동 함

// Learn more about configuring this file at <https://github.com/theintern/intern/wiki/Configuring-Intern>. 
// These default settings work OK for most people. The options that *must* be changed below are the 
// packages, suites, excludeInstrumentation, and (if you want functional tests) functionalSuites. 
define({ 
    // The port on which the instrumenting proxy will listen 
    proxyPort: 9000, 

    // A fully qualified URL to the Intern proxy 
    proxyUrl: 'http://localhost:9000/', 

    // Default desired capabilities for all environments. Individual capabilities can be overridden by any of the 
    // specified browser environments in the `environments` array below as well. See 
    // https://code.google.com/p/selenium/wiki/DesiredCapabilities for standard Selenium capabilities and 
    // https://saucelabs.com/docs/additional-config#desired-capabilities for Sauce Labs capabilities. 
    // Note that the `build` capability will be filled in with the current commit ID from the Travis CI environment 
    // automatically 
    capabilities: { 
     'selenium-version': '2.41.0' 
    }, 

    // Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce 
    // OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other 
    // capabilities options specified for an environment will be copied as-is 
    environments: [ 
     { browserName: 'internet explorer', version: '11', platform: 'Windows 8.1' }, 
     { browserName: 'internet explorer', version: '10', platform: 'Windows 8' }, 
     { browserName: 'internet explorer', version: '9', platform: 'Windows 7' }, 
     { browserName: 'firefox', version: '28', platform: [ 'OS X 10.9', 'Windows 7', 'Linux' ] }, 
     { browserName: 'chrome', version: '34', platform: [ 'OS X 10.9', 'Windows 7', 'Linux' ] }, 
     { browserName: 'safari', version: '6', platform: 'OS X 10.8' }, 
     { browserName: 'safari', version: '7', platform: 'OS X 10.9' } 
    ], 

    // Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service 
    maxConcurrency: 3, 

    // Name of the tunnel class to use for WebDriver tests 
    tunnel: 'SauceLabsTunnel', 

    // The desired AMD loader to use when running unit tests (client.html/client.js). Omit to use the default Dojo 
    // loader 
    // useLoader: { 
    // 'host-node': 'dojo/dojo', 
    // 'host-browser': 'node_modules/dojo/dojo.js' 
    // }, 

    // Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader 
    // can be used here 
    loader: { 
     packages: [ 
      { name: 'angular', location: 'vendor/src/angular/angular' }, 
      { name: 'angular-mocks', location: 'vendor/src/angular/angular-mocks' } 
     ] 
    }, 

    // Non-functional test suite(s) to run in each browser 
    suites: [ 'src/app.test.js' ], 

    // Functional test suite(s) to run in each browser once non-functional tests are completed 
    functionalSuites: [ /* 'myPackage/tests/functional' */ ], 

    // A regular expression matching URLs to files that should not be included in code coverage analysis 
    excludeInstrumentation: /^node_modules/ 
}); 
:

여기
angular.module('ngNomi', [ 

]) 

.config(function myAppConfig() { 

}) 

.run(function run() { 

}) 

.controller('AppCtrl', function AppCtrl ($scope, $location) { 

}); 

내 intern.js 파일입니다 같은

Running "intern:app" (intern) task 
ReferenceError: window is not defined 
    at /Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/vendor/src/angular/angular.js:19288:3 
    at Function.vm.runInThisContext (/Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/node_modules/intern/node_modules/istanbul/lib/hook.js:163:16) 
    at /Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/node_modules/intern/node_modules/dojo/dojo.js:760:8 
    at fs.js:271:14 
    at Object.oncomplete (fs.js:107:15) 
Warning: ReferenceError: window is not defined 
    at /Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/vendor/src/angular/angular.js:19288:3 
    at Function.vm.runInThisContext (/Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/node_modules/intern/node_modules/istanbul/lib/hook.js:163:16) 
    at /Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/node_modules/intern/node_modules/dojo/dojo.js:760:8 
    at fs.js:271:14 
    at Object.oncomplete (fs.js:107:15) Use --force to continue. 

내 app.js

보인다

기본적으로 테스트를 실행할 때 해당 파일에 창을 정의하려면 어떻게해야합니까?

+0

라인 24699 분명히 :}) (window, document); 그래서 iffy로 보내지는 윈도우 컨텍스트를 기대하고 있고, node.js 컨텍스트에 윈도우가 없다. – httpete

+0

타일에 "intern.js"라고 쓰여진 것 같아요. @Evan – httpete

답변

5

나는 intern.js가 테스트 환경을 어떻게 바라 볼지 기대하고 있습니다. Angular는 브라우저 컨텍스트에서 본질적으로 실행되므로 전역 적 창이 필요합니다. 24699 줄의 주요 iffe 않습니다 (창). 우리는 인턴 - 러너가 아닌 인턴 - 클라이언트를 사용하여 창 컨텍스트가있는 브라우저를 구동 할 수 있어야합니다.

하지만 당신은 아마 카르마 예제처럼 머리가없고 빠르게 달리고 싶을 것입니다. 그래서 우리는 intern.js가 intern-runner와 함께 단원 테스트를 실행하기 위해 phantomjs를 사용하도록 구성합니다. Phantomjs와 같은 브라우저 컨텍스트에서 실행되어야하는 인턴 세계의 "스위트"(단위 테스트)입니다. 이것은 브라우저에서 신속한 화재 테스트가 필요한 개발자에게 적합하지만 데스크탑 OS에서 브라우저를 실행하지 않으려 고합니다. 팬텀을 구동하려면 셀렌 서버가 필요합니다. 그래서 :

1.) 실행 셀렌 - 서버 독립형, 나는 https://www.npmjs.org/package/selenium-standalone 로컬로 사용합니다. 별도의 cmd 콘솔에서 시작하십시오. 인턴-config 파일에서

selenium-standalone start

2) NPM 설치 phantomjs

3.

)을 수행

 environments: [ 
     { browserName: 'phantomjs' } 
     ], 
    loader: { 
     // Packages that should be registered with the loader in each testing environment 
     packages: [ 
      { name: 'angular', location: 'bower_components/angular' }, 
      { name: 'angular-mocks', location: 'bower_components/angular-mocks' } 
     ] 

    }, 

4) 실행 $ 노드 node_modules \ 인턴 \ 빈 \ 인턴 주자 config = your/config suites = angular-test

그리고 당신은 황금색이 될 것입니다.

여기 내 아기 단계 단위 테스트이며 각 하중을 입증합니다. 거기에서, 당신은 앵글 모글 (angle mock) 또는 무엇이든간에 당신이 바라는 무엇이든 할 수 있습니다.

define([ 
     'intern/chai!expect', 
     'intern!bdd', 
     'intern/order!angular/angular' 
    ], function (expect, bdd) { 

     function inject (fn) { 
      return function() { 
       angular.injector(['ng']).invoke(fn); 
      } 
     } 

     bdd.describe('Scope Test', function() { 
      var ctrl, scope; 

      bdd.beforeEach(inject(function ($controller, $rootScope) { 
       scope = $rootScope.$new(); 
      })); 

      bdd.it('should have an angular object', function() { 

       expect(angular).to.be.an('object'); 
      }); 


      }); 


}); 
+0

@csnover 댓글을 달 수 있습니까? – httpete

+0

당신은 올바른 생각을 가지고 있습니다. 테스트에서 브라우저 환경 ('window','document' 등)을 예상하면 Node.js 클라이언트 ('intern-client')는 작동하지 않습니다. 브라우저 클라이언트 (client.html) 또는 'intern-runner'를 사용하여 브라우저에서 테스트를 실행하십시오. 원래 포스터가 꿀꿀 거리는 소리를 사용하는 것을 감안할 때, '인턴 주자'가 갈 길입니다. – jason0x43

+0

도움말 httpete 및 @ jason0x43에 감사드립니다. 숫자 4를 실행하면 다음 오류가 발생합니다. 0.0.0.0:9000에서 듣기 터널 시작 중 ... 오류 : [POST http : // localhost : 4444/wd/hub/session]에 연결 함 ECONNREFUSED 연결 오류 : ECONNREFUSED 연결 at errnoException at Object.afterConnect [ascomplete] TOTAL : 테스트 된 0 플랫폼, 0/0 테스트가 실패했습니다. 치명적인 오류가 발생했습니다 – Evan