2013-05-09 6 views
6

인턴을 테스트하여 테스트 프레임 워크에 적합한 지 확인하려고합니다. 인턴에서 다음 코드를 테스트하려고합니다.Node.js 모듈을 실행하기위한 인턴을받을 수 없습니다.

var HelloWorld; 

HelloWorld = (function() { 

    function HelloWorld (name) { 
    this.name = name || "N/A"; 
    } 

    HelloWorld.prototype.printHello = function() { 
    console.log('Hello, ' + this.name); 
    }; 

    HelloWorld.prototype.changeName = function(name) { 
    if (name === null || name === undefined) { 
     throw new Error('Name is required'); 
    } 
    this.name = name; 
    }; 

    return HelloWorld; 

})(); 

exports = module.exports = HelloWorld; 

파일은 'JS-테스트 프로젝트/인턴'에서 'JS-테스트 프로젝트/노드/lib 디렉토리 /하고 helloworld.js'및 인턴이 위치에 있습니다. 나는 Intern의 1.0.0 분기를 사용하고 있습니다. 파일을 포함시키고 테스트를 실행하려고 할 때마다 "콘솔 리포터를 기본값으로 설정"한 후에 출력을 얻지 못합니다. 다음은 테스트 파일입니다. (질문에 따라) 다음과 같은 디렉토리 구조를 가정

define([ 
    'intern!tdd', 
    'intern/chai!assert', 
    'dojo/node!../lib/HelloWorld' 
], function (tdd, assert, HelloWorld) { 
    console.log(HelloWorld); 
}); 
+1

노드에 익숙하지 않은 사람. js, 이것은 인턴쉽 게시처럼 들렸습니다 :) –

+1

내가 원하는 것을 실행하기 위해 인턴을 얻을 수 없을 때 나는 싫어. – AaronLS

답변

7

1 :

js-test-projects/ 
    node/ 
     lib/ 
      HelloWorld.js - `HelloWorld` Node module 
     tests/ 
      HelloWorld.js - Tests for `HelloWorld` 
      intern.js  - Intern configuration file 
    intern/ 

2. node 패키지 및 실행할 수있는 스위트 룸에 대한 정보를 포함해야합니다 귀하의 인턴 구성 파일 :

3. 테스트 파일의

// ... 

// Configuration options for the module loader 
loader: { 
    // Packages that should be registered with the loader in each testing environment 
    packages: [ 'node' ] 
}, 

// Non-functional test suite(s) to run 
suites: [ 'node/tests/HelloWorld' ] 

// ... 
이 같은 도장의 인턴의 버전을 사용 hould 부하 HelloWorld :

define([ 
    'intern!tdd', 
    'intern/chai!assert', 
    'intern/dojo/node!./node/lib/HelloWorld.js' 
], function (tdd, assert, HelloWorld) { 
    console.log(HelloWorld); 
}); 

참고 : 당신은 이 AMD 테스트에 HelloWorld 노드 모듈을로드 도장의 인턴의 버전을 사용이없는, 그것은이다 그렇게하는 편리한 방법. node-node 모듈을 필요로하는 다른 AMD 플러그인이 있다면, 그것은 완벽합니다. 마지막으로

4.

가하는 Node.js를 환경에서 테스트를 실행하려면 intern 디렉토리 내에서 다음 명령을 실행하여 인턴의 client.js 노드 러너를 사용

node client.js config=node/tests/intern 
+2

노드 모듈이 이미 해결 가능한'node_modules' 디렉토리 안에 있다면'intern/dojo/node! node/lib/HelloWorld'를 사용하십시오. –

관련 문제