newman.run 在 NodeJS 模块中不起作用

newman.run in NodeJS module does not work

我想从 node.js 模块执行 newman 但它不起作用。并且没有显示错误。

从命令行运行良好

newman run postman-tests/collection.json -e postman-tests/environment.json
// newman installed globally for this command

但是下面的节点模块代码不起作用:

var newman = require('newman'),
    Promise = require('bluebird'),
    newmanRun = Promise.promisify(newman.run);

//.. other working grunt task here ...
// added new task postman-test

grunt.registerTask('postman-test','postman task running ',  function() {
    Promise.coroutine(function*() {
        try {
            console.log('test start-----');
            var response = yield newmanRun({
                collection: require('./postman-tests/collection.json'),
                environment: require('./postman-tests/environment.json'),
                reporters: 'cli'
            });
            console.log('run complete-----', response);
        } catch (e) {
            console.log('postman test catch error: ', e);
        }
    })();
});

当我 运行 "grunt postman-test" 命令仅在控制台 "test start-----" 中显示并显示 Done, without errors. 但没有测试执行时

我的代码有什么问题?谁能帮帮我?

默认情况下,grunt 处理所有任务注册 synchronously.Chances 发生这种情况是因为您忘记调用 this.async 方法来告诉 Grunt 您的任务是 asynchronous.For 简单起见, Grunt 使用同步编码风格,可以通过在任务主体中调用 this.async() 将其切换为异步。文档 link

grunt.registerTask('postman-test', function() {
        var done = this.async();// added this line
        Promise.coroutine(function*() {
            try {
                yield newmanRun({
                    collection: "./postman-tests/0.8/Meed-Services-0.8.postman_collection.json",
                    environment: "./postman-tests/0.8/local.postman_environment.json",
                    reporters: 'cli'
                });
                console.log('*******postman test complete********');
                done();
            } catch (e) {
                console.log('postman test catch error: ', e);
                done(false);
            }
        })();
    });