Search code examples
javascriptfedoranodeunit

Webstorm UT - cannot find module


I'm trying to test simple code:

function div2(a, b) {
    return a/b;
}

module.exports.div = div2;

And in examplesTestUnit.js file:

var calculator = require("./examples");

module.exports["div test"] = function(test) {
    test.equal(calculator.div(6,2), 3);
    test.equal(calculator.div(12,0), Infinity);
    test.equal(calculator.div(0,3), 0);
    test.done();
};

When I try to run test in Webstorm I got errors:

/usr/bin/node /tmp/nodeunit-intellij-starter.js /usr/lib/node_modules/nodeunit examplesTestUnit.js
Testing started at 02:42 ...

module.js:340
    throw err;
          ^
Error: Cannot find module '/usr/lib/node_modules/nodeunit/deps/async'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at resolveAsyncModule (/tmp/nodeunit-intellij-starter.js:304:20)
    at testIt (/tmp/nodeunit-intellij-starter.js:308:21)
    at run (/tmp/nodeunit-intellij-starter.js:335:9)
    at Object.<anonymous> (/tmp/nodeunit-intellij-starter.js:365:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

Process finished with exit code 8

I installed mocha for tests and mocha didnt gives me an errors, but there's still no results:

[DzikiChrzan@DzikiLaptopF untitled]$ mocha examplesTestUnit.js 


  0 passing (1ms)

[DzikiChrzan@DzikiLaptopF untitled]$ 

I have installed nodeunit in 0.8.6 version and I already tried to reinstall it. Plus another error I recive in terminal:

[DzikiChrzan@DzikiLaptopF untitled]$ nodeunit --

/usr/lib/node_modules/nodeunit/lib/nodeunit.js:72
        if (err) throw err;
                       ^
Error: ENOENT, stat '/home/DzikiChrzan/WebstormProjects/untitled/--'

I'm using Fedora 22. How can I fix this?


Solution

  • Okay, I did it. I downloaded and installed nodeunit using npm.

    npm install -g n
    n stable
    

    Next thing I needed to do was manually indicate path to nodeunit module in WebStorm. In my case it was:

    /home/DzikiChrzan/node_modules/nodeunit