首页 > 解决方案 > 来自流星测试的乱码测试结果输出:mocha

问题描述

Meteor 1.7 的推荐测试框架似乎是meteortesting:mocha.

使用 Meteor 1.7.0.3,我创建了一个默认应用程序 ( meteor create my-app),它具有以下测试 (in test/main.js)

import assert from "assert";

describe("my-app", function () {
  it("package.json has correct name", async function () {
    const { name } = await import("../package.json");
    assert.strictEqual(name, "noteit");
  });

  if (Meteor.isClient) {
    it("client is not server", function () {
      assert.strictEqual(Meteor.isServer, false);
    });
  }

  if (Meteor.isServer) {
    it("server is not client", function () {
      assert.strictEqual(Meteor.isClient, false);
    });
  }
});

我跑了

meteor add meteortesting:mocha
meteor test --driver-package meteortesting:mocha

并使用meteortesting:mocha@2.4.5_6 我在控制台中得到了这个:

I20180728-12:06:37.729(2)? --------------------------------
I20180728-12:06:37.729(2)? ----- RUNNING SERVER TESTS -----
I20180728-12:06:37.729(2)? --------------------------------
I20180728-12:06:37.729(2)? 
I20180728-12:06:37.730(2)? 
I20180728-12:06:37.731(2)? 
I20180728-12:06:37.737(2)?   the server
    ✓ fails a test.753(2)? 
I20180728-12:06:37.755(2)? 
I20180728-12:06:37.756(2)? 
I20180728-12:06:37.756(2)?   1 passing (26ms)
I20180728-12:06:37.756(2)? 
I20180728-12:06:37.757(2)? Load the app in a browser to run client tests, or set the TEST_BROWSER_DRIVER environment variable. See https://github.com/meteortesting/meteor-mocha/blob/master/README.md#run-app-tests
=> Exited with code: 0
=> Your application is crashing. Waiting for file change.

实际上,它重复了三遍。不漂亮。而且我没想到通过测试会使我的应用程序崩溃。

同样在浏览器中我得到了这个

在此处输入图像描述

根据Meteor 测试指南,我期待的输出更像是漂亮的输出:

在此处输入图像描述

标签: testingmeteormocha.js

解决方案


与大多数 Node.js 一样,几乎任何东西都有许多分支。所以也与meteortesting:mocha.

cultofcoders:mocha似乎有一些提交,这曾经是 Meteor 推荐的practicalmeteor:mocha测试框架。

如果你跑

meteor add cultofcoders:mocha
meteor test --driver-package cultofcoders:mocha

你会得到很好的输出。

出于好奇,我发现cultofcoders:mocha我得到的 ( meteor list | grep mocha) 版本是 2.4.6,这是 github repo 没有的版本...


推荐阅读