【问题标题】:Getting mocha error in command prompt在命令提示符下出现 mocha 错误
【发布时间】:2016-12-20 05:20:00
【问题描述】:

当我在 CMD 中运行示例 js 文件时。它显示错误,例如错误:找不到测试框架“mocha”。请帮我解决这个问题。

运行测试后出错:

basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") 
       ^^^^^^^  
SyntaxError: missing ) after argument list 
at exports.runInThisContext (vm.js:53:16) 
at Module._compile (module.js:373:25) 
at Object.Module._extensions..js (module.js:416:10) 
at Module.load (module.js:343:32) 
at Function.Module._load (module.js:300:12) 
at Function.Module.runMain (module.js:441:10) 
at startup (node.js:139:18) 
at node.js:968:3

Package.json:

{
    "name": "macaca-test-sample",
    "version": "0.1.0",
    "description": "macaca-test-sample",
    "keywords": [
        "sample"
    ],
    "main": "index.js",
    "repository": {
        "type": "git",
        "url": "git://github.com/xudafeng/macaca-test-sample.git"
    },
    "dependencies": {
        "mocha": "^3.2.0"
    },
    "devDependencies": {
        "jshint": "*",
        "mocha": "^3.2.0",
        "pre-commit": "1.1.1",
        "webdriver-client": "~1.0.0"
    },
    "scripts": {
        "test": "mocha",
        "jshint": "make jshint"
    },
    "pre-commit": [
        "jshint"
    ],
    "homepage": "github.com/xudafeng/macaca-test-sample";,
    "author": "xudafeng",
    "email": "xudafeng@126.com",
    "blog": "xdf.me";,
    "license": "MIT"
}

【问题讨论】:

  • 请分享代码。
  • 安装摩卡 globally
  • Shaharyar,我该怎么做
  • npm install --global mocha
  • 嗨 Shaharyar ,感谢它的帮助。但是再次运行它会显示另一个问题,例如 "basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") ^^^^^^^ SyntaxError: missing ) 在模块的 Object.Module._extensions..js (module.js:416:10) 的 Module._compile (module.js:373:25) 的参数列表之后.load (module.js:343:32) 在 Function.Module._load (module.js:300:12) 在 Function.Module.runMain (module.js:441:10) 在启动时 (node.js:139: 18) 在 node.js:968:3"

标签: node.js mocha.js


【解决方案1】:

这是 Windows 上 istanbul 的问题,您在 macacajs 中有这个 npm 作为依赖项:

here解释为:

伊斯坦布尔假定传递给它的命令是一个 JS 文件(例如 茉莉花,誓言等),但在 npm 的 Windows 上却不是这样 将 bin 文件包装在 .cmd 文件中。由于伊斯坦布尔无法解析 .cmd 文件 你需要手动引用bin文件。

这是一个使用 Jasmine 2 的示例:

istanbul cover node_modules\jasmine\bin\jasmine.js

为了使用这个跨平台(例如 Linux、Mac 和 Windows),您可以将上述行插入到您的脚本对象中 package.json 文件,但带有普通斜杠。

"scripts": {
    "test": "istanbul cover node_modules/jasmine/bin/jasmine.js"
}

所以简单的解决方案是将上面的 sn-p 添加到你的 package.json 中。

【讨论】:

    【解决方案2】:

    编辑package.json/node_modules/.bin/mocha 文件,但没有用。

    到目前为止,对我来说唯一的解决方案是全局安装 mocha:

    npm install -g mocha
    

    【讨论】:

      猜你喜欢
      • 2019-11-13
      • 1970-01-01
      • 2016-02-13
      • 1970-01-01
      • 2020-10-31
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      相关资源
      最近更新 更多