2014-04-25 2 views
0

인턴을 사용하여 테스트 한 모든 모듈은 이스탄불의 코드 범위에 자동으로 적용됩니다. 내게 알려지지 않은 이유 때문에, 제 모듈이 포함되지 않았습니다.단위 테스트를위한 코드 적용 범위에 모듈을 포함시키는 방법은 무엇입니까?

가 나는 :

  • 실행 인턴 1.6.2 콜백을 사용하여
  • 테스트 NodeJS 코드
  • (로컬 NPM 설치)하지 약속
  • CommonJS 모듈이 아닌 AMD 모듈
  • 를 사용하여

디렉토리 구조 (관련 파일 만 표시) :

,
plister 
| 
|--libraries 
| |--file-type-support.js 
| 
|--tests 
| |--intern.js 
| |--unit 
|  |--file-type-support.js 
| 
|--node_modules 
    |--intern 

plister/테스트/intern.js

define({ 
    useLoader: { 
     'host-node': 'dojo/dojo' 
    }, 
    loader: { 
     packages: [ 
      {name: 'libraries', location: 'libraries'} 
     ]   
    }, 
    reporters: ['console'], 
    suites: ['tests/unit/file-type-support'], 
    functionalSuites: [], 
    excludeInstrumentation: /^(tests|node_modules)\// 
}); 

plister/테스트/유닛/파일 형식 support.js

define([ 
    'intern!bdd', 
    'intern/chai!expect', 
    'intern/dojo/node!fs', 
    'intern/dojo/node!path', 
    'intern/dojo/node!stream-equal', 
    'intern/dojo/node!../../libraries/file-type-support' 
], function (bdd, expect, fs, path, streamEqual, fileTypeSupport) { 
    'use strict'; 

    bdd.describe('file-type-support', function doTest() { 
     bdd.it('should show that the example output.plist matches the ' + 
       'temp.plist generated by the module', function() { 
      var deferred = this.async(), 
       input  = path.normalize('tests/resources/input.plist'), 
       output = path.normalize('tests/resources/output.plist'), 
       temporary = path.normalize('tests/resources/temp.plist'); 

      // Test deactivate function by checking output produced by 
      // function against test output. 
      fileTypeSupport.deactivate(fs.createReadStream(input), 
        fs.createWriteStream(temporary), 
        deferred.rejectOnError(function onFinish() { 
       streamEqual(fs.createReadStream(output), 
         fs.createReadStream(temporary), 
         deferred.callback(function checkEqual(error, equal) { 
        expect(equal).to.be.true;  
       })); 
      })); 
     }); 
    }); 
}); 

출력 :

PASS: main - file-type-support - should show that the example output.plist matches the temp.plist generated by the module (29ms) 
1/1 tests passed 
1/1 tests passed 

출력 (실패시) :

(excludeInstrumentation를 제거한 후)

출력 :

PASS: main - file-type-support - should show that the example output.plist matches the temp.plist generated by the module (25ms) 
1/1 tests passed 
1/1 tests passed 

------------------------------------------+-----------+-----------+-----------+-----------+ 
File          | % Stmts |% Branches | % Funcs | % Lines | 
------------------------------------------+-----------+-----------+-----------+-----------+ 
    node_modules/intern/     |  70 |  50 |  100 |  70 | 
     chai.js        |  70 |  50 |  100 |  70 | 
    node_modules/intern/lib/    |  79.71 |  42.86 |  72.22 |  79.71 | 
     Test.js        |  79.71 |  42.86 |  72.22 |  79.71 | 
    node_modules/intern/lib/interfaces/ |  80 |  50 |  63.64 |  80 | 
     bdd.js        |  100 |  100 |  100 |  100 | 
     tdd.js        |  76.19 |  50 |  55.56 |  76.19 | 
    node_modules/intern/lib/reporters/  |  56.52 |  35 |  57.14 |  56.52 | 
     console.js       |  56.52 |  35 |  57.14 |  56.52 | 
    node_modules/intern/node_modules/chai/ |  37.9 |  8.73 |  26.38 |  39.34 | 
     chai.js        |  37.9 |  8.73 |  26.38 |  39.34 | 
    tests/unit/       |  100 |  100 |  100 |  100 | 
     file-type-support.js    |  100 |  100 |  100 |  100 | 
------------------------------------------+-----------+-----------+-----------+-----------+ 
All files         |  42.14 |  11.35 |  33.45 |  43.63 | 
------------------------------------------+-----------+-----------+-----------+-----------+ 

내 모듈이 테스트를 통과하고 내가 너무 실패 할 수 있습니다. 코드 적용 범위에는 표시되지 않습니다. 나는 GitHub에서 아무런 문제없이 호스팅 된 튜토리얼을 끝냈다.

나는 이스탄불과 인턴의 의존성을 분석해 보았습니다. console.log 어디에 덮어 씌워 질 파일이 보이지만 내 모듈은 전달되지 않습니다. 코드 범위와 차이가없는 deferred.callbackdeferred.rejectOnError의 모든 변형을 시도했습니다.

또한 deferred.callbackdeferred.rejectOnError을 사용하는 것에 대한 모든 의견을 크게 환영 할 것입니다. 나는 아직도 그들의 사용법에 대해 조금 불확실하다.

감사합니다.

답변

0

인턴 1.6의 경우 만 후킹되어 require이 아니라 코드 적용 데이터를 추가합니다. Instrumentation of require은 Intern 2.0에 추가되었습니다.

위의 코드에서 callback/rejectOnError를 사용하는 것이 정확합니다.

+0

문제 추적기에 명확한 요청을 표현할 수 있기 때문에 CommonJS 모듈에 대한 코드 커버리지 지원을 요청하고 있습니까? – Dale

+0

예! 그럴 것입니다. –