首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spectron和mocha和chai不工作

Spectron和mocha和chai不工作
EN

Stack Overflow用户
提问于 2019-10-11 18:42:04
回答 1查看 1.1K关注 0票数 0

我正在尝试为我们的电子应用程序编写一个Spectron测试,但我遇到了设置问题。我使用chai的经典设置。我有一个包含安装代码的文件:

代码语言:javascript
复制
const path = require("path");
const { Application } = require("spectron");

module.exports = {
  initialiseSpectron: () => {
    let electronPath = path.join(__dirname, "../../node_modules", ".bin", "electron");

    if (process.platform == "win32") {
      electronPath += ".cmd";
    }

    return new Application({
      path: electronPath,
      args: [path.join(__dirname, "../index.ts"), path.join(__dirname, "../../package.json")],
      env: {
        ELECTRON_ENABLE_LOGGING: true,
        ELECTRON_ENABLE_STACK_DUMPING: true,
        NODE_ENV: "development"
      },
      startTimeout: 10000,
      chromeDriverLogPath: "../chromedriverlog.txt"
    });
  },
  sleep: time => new Promise(resolve => setTimeout(resolve, time))
};

然后是测试本身:

代码语言:javascript
复制
const chaiAsPromised = require("chai-as-promised");
const chai = require("chai");
chai.should();
chai.use(chaiAsPromised);

const testHelper = require("./initialise");
const app = testHelper.initialiseSpectron();

// Setup Promises and start Application
before(() => app.start());

// Tear down App after Tests are finished
after(() => {
  if (app && app.isRunning()) {
    return app.stop();
  }
});

describe("Login", () => {
  it("opens a window", function() {
    return app.client
      .waitUntilWindowLoaded()
      .getWindowCount()
      .should.eventually.equal(1);
  });

  it("tests the title", () =>
    app.client
      .waitUntilWindowLoaded()
      .getTitle()
      .should.eventually.equal("VIPFY"));
});

我的问题是我总是得到这样的错误:

代码语言:javascript
复制
 1) "before all" hook in "{root}"

  0 passing (2s)
  1 failing

  1) "before all" hook in "{root}":
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

因此,看起来应用程序没有启动。但事实并非如此。应用程序窗口打开,但测试似乎无法识别这一点。我已经尝试过使用各种语法来更改路径。但都不管用。我遗漏了什么?

EN

回答 1

Stack Overflow用户

发布于 2019-10-17 03:45:35

你有没有试过增加摩卡的超时时间?

有时我让它第一次失败,然后在第二次尝试时工作。

在这里查看Electron 6的工作示例:

https://github.com/florin05/electron-spectron-example

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58339543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档