1

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

从命令行运行良好

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.但不执行测试时

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

4

1 回答 1

0

默认情况下,grunt 同步处理所有任务注册。这可能是因为您忘记调用该this.async方法告诉 Grunt 您的任务是异步的。为简单起见,Grunt 使用同步编码风格,可以通过以下方式将其切换为异步this.async()在任务主体内调用。文档链接

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);
            }
        })();
    });
于 2016-09-07T12:52:29.660 回答