Mocha requires make. Can't find a make.exe that works on Windows

后端 未结 4 1949
轮回少年
轮回少年 2020-12-15 23:39

Mocha (test framework for Node.js) uses make.

For the life of me I can\'t find a compatible make.exe for Windows.

Everything works fine on my Mac.

I

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 00:08

    You can use commander to implement your own version in node.js! I use that for my projects, despite that I'm on mac. It'll work anywhere, where node is installed.

    The following script assumes that your cli scripts lie in /path/to/your/app/cli.

    node cli/test.js -u # runs unit tests in /path/to/your/app/tests/unit

    node cli/test.js -f # runs functional tests in /path/to/your/app/tests/functional

    test.js

    /*
     * CLI for execution of the mocha test suite.
     *
     * test.js --help for instructions.
     */
    
    var program = require('commander');
    
    program
        .version('1.0.0')
        .option('-u, --unit', 'Run unit tests.')
        .option('-f, --functional', 'Run functional tests.')
        .on('--help', function(){
            console.log('Executes the mocha testsuite.');
            console.log('');
        })
       .parse(process.argv)
    ;
    
    if(!program.unit && !program.functional) {
        console.log();
        console.log('Specify if you want to run unit tests (-u) or functional tests (-f).');
        console.log('Run help (-h) for detailed instructions.');
        console.log();
    }
    
    if(program.unit) {
         require('child_process').exec(__dirname + '/../node_modules/.bin/mocha -u tdd -R spec --recursive -c ' + __dirname + '/../tests/unit', standardOutput);
    }
    
     if(program.functional) {
    require('child_process').exec(__dirname + '/../node_modules/.bin/mocha -u bdd -R spec --recursive -c ' + __dirname + '/../tests/functional', standardOutput);
    }
    
    /**
     * Standard output.
     *
     * @method standardOutput
     * @param {Object} error
     * @param {String} stdout the cli standard output
     * @param {String} stderr output of errors
     */
    function standardOutput(error, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
    }
    

提交回复
热议问题