【问题标题】:Why is Mocha not running on travis为什么 Mocha 不能在 travis 上运行
【发布时间】:2015-01-22 05:03:18
【问题描述】:

我的 mocha 测试在本地运行良好。但是在 travis 上没有运行测试,我看到的只是“0 通过”。

我有一个简单的.travis.yml

language: node_js
node_js:
  - "0.10"

我的 package.json 的 scripts 部分是这样配置的

"scripts": {
  "test": "./node_modules/.bin/mocha"
}

如果您需要有关该项目的更多信息,可以查看https://github.com/theblacksmith/typescript-compiler

这是该项目的 travis 页面:https://travis-ci.org/theblacksmith/typescript-compiler

【问题讨论】:

  • SO 编辑实践要求您将与您的问题相关的代码放在问题本身的正文中。允许提供其他信息的链接,前提是它们替换与您的问题相关的代码。如果你有太多代码,这表明你应该创建一个mcve
  • @Louis 据我所知,相关代码在那里。这是 Travis 运行我的测试所需的配置。我实际上发现问题是一个“结构”问题。

标签: node.js typescript mocha.js travis-ci


【解决方案1】:

您可以指定mocha --compilers option,而不是将.ts 文件构建到.js。为此,您应首先将typescript-require module 添加到您的devDependencies

npm install typescript-require --save-dev

然后你就可以将它用作.ts 编译器:

"scripts": {
  "test": "./node_modules/.bin/mocha --compilers ts:typescript-require"
}

【讨论】:

    【解决方案2】:

    问题是我使用的是 TypeScript,并且在运行 mocha 之前没有设置构建过程来将测试编译为 js。因此,如果您使用任何转译器,请确保将构建配置为将它们转换为 js。这是最终的配置代码

    .travis.yml

    language: node_js
    
    node_js:
      - "0.10"
    
    before_script:
      - make build
    

    生成文件

    build:
        @echo "  Building..."
        @cp src/typescript/bin/lib.* lib/
        @node ./src/typescript/bin/tsc.js -m commonjs -t ES5 src/index.ts --out index.js
        @echo "  Done!"
    
    .PHONY: build
    

    package.json(脚本会话)

    "scripts": {
      "build": "make build",
      "test": "node ./src/typescript/bin/tsc.js -m commonjs -t ES5 test/*.ts && ./node_modules/mocha/bin/mocha"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-22
      • 2019-05-27
      • 2013-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多