【问题标题】:How can I avoid "No test specified" errors in npm?如何避免 npm 中的“未指定测试”错误?
【发布时间】:2018-07-29 04:18:07
【问题描述】:

我在 Mac High Sierra 上使用 npm@5.6.0。我想运行在这个Stratum client project 中设置的测试。我已经成功运行npm install。但是当我尝试运行单个测试时,我得到了错误:

no test specified

什么给了?我在根项目目录中,测试在我的“测试”文件夹中。这是发生了什么:

localhost:stratum-client-master davea$ npm install
up to date in 0.381s
localhost:stratum-client-master davea$ npm test test/callbacks.js

> stratum-client@1.0.1 test /Users/davea/Documents/workspace/stratum-client-master
> echo "Error: no test specified" && exit 1 "test/callbacks.js"

Error: no test specified
sh: line 0: exit: too many arguments
npm ERR! Test failed.  See above for more details.

【问题讨论】:

    标签: testing npm


    【解决方案1】:

    您输出的正是package.json file 被告知要输出的内容。在scripts 下偷看。

    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "int-test": "mocha --require babel-core/register --recursive test"
    },
    

    试试int-test,那里的另一个命令。

    【讨论】:

    • 我确实按照他们的文档推荐尝试了“npm int-test”,但得到了错误“Usage: npm ...你的意思是其中之一吗?测试安装测试”所以我迁移到我上面的内容。
    • 为了运行script 标签中的命令,您必须指定run 子命令。 npm run int-testnpm test 只是 npm run test 的简写。将test 命令替换为int-test 可能是个好主意,这样您就可以运行npm test
    【解决方案2】:

    尝试替换

    "scripts": {
      "test": "mocha"
    },
    

    在你的package.json

    【讨论】:

      【解决方案3】:

      将此添加到您的 packages.json 文件中:

      "scripts":{
          "test": "mocha --ui tdd tests/callbacks.js",
      }
      

      然后在控制台上npm test

      【讨论】:

        【解决方案4】:

        如果您使用 Jest 和酶进行单元测试,并且您有一个 jest.config.json 配置文件,您可以将脚本下的 package.json 更新为以下内容:

        "scripts":{    
          "test": "jest --config=./jest.config.json --coverage",
        }
        

        【讨论】:

          【解决方案5】:

          错误可能是“退出 1”

          "scripts": {
            "test": "echo \"Error: no test specified\" && exit 1"
          },
          

          改成这样:

          "scripts": {
            "test": "echo \"No test specified\""
          },
          

          此更改有效,因为出口 1 会产生错误。

          【讨论】:

            【解决方案6】:

            在您的 package.json 中查找并进行更改

            “脚本”:{ “测试”:“摩卡” }

            【讨论】:

              【解决方案7】:

              您没有指定您使用的测试框架,例如 JestMocha

              如果是 Jest,请将其添加到您的 package.json

              "scripts" : { 
                  "test" : "jest" 
               }
              

              mocha的情况请参考@Divyeshpal的回答。

              【讨论】:

              • 嗨,我正在使用 Jasmine 框架,而不是开玩笑,我需要添加什么?
              【解决方案8】:

              错误可能是“退出 1”

              "scripts": {
                "test": "echo \"Error: no test specified\" && exit 1"
              },
              

              改成这样:

              "scripts": {
                "test": "echo \"No test specified\""
              },
              

              此更改对我有用,因为出口 1 产生了错误。

              【讨论】:

                【解决方案9】:

                替换
                echo \"Error: no test specified\" && exit 1 在你的 package.jsonmocha.

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 2016-03-12
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2020-06-01
                  • 2021-01-17
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多