【问题标题】:newman execution throwing TypeError: newman.run is not a functionnewman 执行抛出 TypeError: newman.run is not a function
【发布时间】:2018-08-13 13:13:54
【问题描述】:

我的 ubuntu 机器上安装了 newman 3.9.3 版本。想从一个文件夹中执行多个集合,但通过我执行 js 文件的有线错误说

TypeError: newman.run 不是函数。

这是我的执行脚本。任何帮助将不胜感激。

#!/usr/bin/env node
var newman = require(process.env.NVM_BIN+'/newman');
var fs = require('fs');

fs.readdir('./collections', function (err, files) {
    if (err) { throw err; }

    files = files.filter(function (file) {
        return (file.substr(-5) === '.json');
    });

    // now wer iterate on each file name and call newman.run using each file name
    files.forEach(function (file) {
        newman.run({
            environment: require(`${__dirname}/live.postmane_environment.json`),
            collection: require(`${__dirname}/collections/${file}`),
            reporters: ['cli']
        }, function (err) {
            console.info(`${file}: ${err ? err.name : 'ok'}!`);
        });
    });
});

以下是确切的错误。

/app/postman/execute:15 新人运行({ ^

TypeError: newman.run 不是函数 在 /app/postman/execute:15:16 在 Array.forEach (本机) 在 /app/postman/execute:14:11 在 FSReqWrap.oncomplete (fs.js:123:15)

【问题讨论】:

  • 如果您删除 process.env.NVM_BIN+ 并对模块执行正常要求,它会运行吗?
  • 不,即使我尝试使用 newman 实用程序的绝对路径。它没有帮助。

标签: postman newman


【解决方案1】:

我收到相同的错误消息并解决了安装 nodejs 包的问题:

npm install --save newman

基本上,当您将 bin 作为参考时,nodejs 不知道如何运行:

代替:

var newman = require(process.env.NVM_BIN+'/newman');

应该是:

var newman = require('newman');

【讨论】:

    【解决方案2】:

    目前,我已经解决了这个问题,方法是使用 bash 脚本运行文件夹中的所有可用集合。这已经完成了这项工作。但最初我不明白为什么“newman”对象不能使用“run”。

    【讨论】:

      猜你喜欢
      • 2021-05-30
      • 2015-11-06
      • 2014-01-31
      • 2021-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      相关资源
      最近更新 更多