【问题标题】:Mocha tests run fine locally, but fail on Travis due to destructuring syntax?Mocha 测试在本地运行良好,但由于解构语法而在 Travis 上失败?
【发布时间】:2020-09-16 01:10:20
【问题描述】:

我有一个 NodeJS + Express 应用程序正在运行,我正在尝试通过 Mocha 测试来测试我的 API。这些测试通过 npm 脚本在本地运行良好(这也是 Travis 调用的同一脚本),但是在 Travis 上运行时,我遇到以下错误:

> mocha --exit
/home/travis/build/tristonpang/restful-web-cs3219/node_modules/mocha/bin/mocha:13
const {deprecate} = require('../lib/utils');
      ^
SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:54:16)
    at Module._compile (module.js:429:25)
    at Object.Module._extensions..js (module.js:464:10)
    at Module.load (module.js:341:32)
    at Function.Module._load (module.js:296:12)
    at Function.Module.runMain (module.js:487:10)
    at startup (node.js:111:16)
    at node.js:809:3
npm ERR! Test failed.  See above for more details.
The command "npm test" exited with 1.

我的package.json如下:

{
  "name": "task-b",
  "version": "1.0.0",
  "description": "App demonstrating RESTful implentation.",
  "main": "index.js",
  "scripts": {
    "start": "nodemon index",
    "test": "mocha --exit"
  },
  "keywords": [
    "restful"
  ],
  "author": "Triston Pang Erh Syen",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.19.0",
    "chai-http": "^4.3.0",
    "express": "^4.17.1",
    "mongoose": "^5.10.3"
  },
  "devDependencies": {
    "chai": "^4.2.0",
    "chai-like": "^1.1.1",
    "mocha": "^8.1.3"
  },
  "babel": {
    "presets": [
      "es2015"
    ]
  }
}

到处搜索并没有找到任何解决方案,我很困惑为什么会这样,任何帮助将不胜感激!

【问题讨论】:

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


    【解决方案1】:

    我发现了问题,这是在引入解构之前将节点版本设置为 1.0.0 的 .travis.yml 文件中的拼写错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      相关资源
      最近更新 更多