2013-05-09 11 views
6

Sto provando a testare Intern per verificare se sarebbe adatto per un framework di test. Sto provando a testare il seguente codice in Intern.Impossibile accedere a Intern per eseguire il modulo 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; 

Il file si trova nella 'JS-test-progetti/node/lib/HelloWorld.js' e Intern si trova a 'js-test-progetti/stagista'. Sto usando il ramo 1.0 di Intern. Ogni volta che cerco di includere il file ed eseguire il test, non ottengo alcun output dopo "Defaulting to console reporter". Ecco il file di test.

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

Per qualcuno non ha familiarità con il nodo. js, suonava come una pubblicazione di stage :) –

+1

Odio quando non riesco a far fare al mio tirocinante ciò che voglio. – AaronLS

risposta

7

1. Supponendo che la seguente struttura di directory (in base alla domanda):

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

2. Il file di configurazione Intern dovrebbe contenere informazioni sulla confezione node e qualsiasi suite da eseguire:

// ... 

// 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' ] 

// ... 

3. Il file di prova s hould carico HelloWorld utilizzando la versione di Intern del Dojo, come questo:

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

Nota: non si hanno di utilizzare la versione di Intern del Dojo per caricare il modulo HelloWorld nodo in questo test AMD, è solo un modo conveniente per farlo. Se disponi di un altro plug-in AMD che richiede un nodo, un modulo nodo è perfettamente funzionante.

4. Infine, per eseguire i test in un ambiente Node.js, utilizzare client.js nodo corridore Intern emettendo il seguente comando all'interno della directory intern:

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

Si noti che se il proprio modulo Nodo è già all'interno di una directory 'node_modules' risolvibile, si utilizza semplicemente' intern/dojo/node! Node/lib/HelloWorld'. –

Problemi correlati