【问题标题】:Protractor / Typescript - Cannot find name 'allure' in "mocha-allure-reporter"量角器/打字稿 - 在“mocha-allure-reporter”中找不到名称“allure”
【发布时间】:2020-04-08 23:39:42
【问题描述】:

基本上我有this 的问题,但在 mocha-allure-reporter 和 typescript 中。我正在使用量角器和摩卡咖啡,并决定添加魅力报告

无法全局访问使用 mocha-allure 的“allure”对象。

这是 protractor.conf.js

mochaOpts: {
    bail: false,
    ui: 'bdd',
    reporter: 'spec',
    compiler: 'ts:ts-node/register'
}

这是 package.json 中的 devDependencies

"devDependencies": {
    "chai": "^4.0.2",
    "mocha": "^6.2.2",
    "allure-commandline": "^2.0.0",
    "mocha-allure-reporter": "^1.4.0",
    "mocha-tags": "^1.0.1"
  }

以及依赖项

"dependencies": {
    "@types/mocha": "^7.0.1",
    "@types/node": "^13.7.6",
    "chai": "^4.2.0",
    "mocha-allure-reporter": "^1.4.0",
    "chai-as-promised": "^7.1.1",
    "graphviz": "0.0.9",
    "lodash": "^4.17.15",
    "minimist": "^1.2.0",
    "mocha": "^6.2.2",
    "npm-failsafe": "^0.4.1",
    "protractor": "^5.4.2",
    "rimraf": "^2.7.1",
    "ts-node": "^8.5.4",
    "tslint": "^5.20.1",
    "typescript": "^3.8.2",
    "typescript-logging": "^0.6.4",
    "webdriver-manager": "^12.1.7",
    "yargs": "^13.3.0"
}

这是无法全局访问“allure”的ts文件:

当我尝试添加 declare const allure: any; 时, 注意:请在打字稿中,我没有太多的javascript背景

【问题讨论】:

  • 你试过const allure = require("mocha-allure-reporter")吗?

标签: typescript ecmascript-6 protractor mocha.js allure


【解决方案1】:
 require("mocha-allure-reporter");
 declare const allure: any;

 describe("Initial Test", function() {
 it("Add Feature" async function() {
    allure.feature("Sample Feature");
  })
 })

【讨论】:

  • 我已经做到了。它会引发错误TypeError: allure.feature is not a function
  • @miel-yan 好吧,我已经更新了答案。如果它不起作用。我们会在任何屏幕共享平台上讨论这个问题
  • 我也试过了。当然!我很乐意这样做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-01
  • 1970-01-01
  • 2020-04-21
  • 2018-01-25
  • 2016-09-15
  • 2019-02-25
  • 1970-01-01
相关资源
最近更新 更多