创建摩卡测试套件即可一次启动应用程序

时间:2019-06-07 08:49:41

标签: mocha jestjs spectron

我有以下文件

test1.ts
test2.ts
test3.ts
test4.ts
test5.ts

我想在前后统一启动一次测试,以便我只启动一次应用程序并运行测试,然后关闭它。

每个测试文件都有其自己的描述

1 个答案:

答案 0 :(得分:0)

我能够通过在我的test/目录中添加一个名为setup.spec.ts的文件来执行此操作,该文件使用Hook在钩子之前和之后进行设置和拆除。这些挂钩在您其他测试文件中的任何describe块之前/之后运行。

import {setupApp, teardownApp} from '../src/helpers/app';

before(async () => {
  await setupApp();
});

after(async () => {
  await teardownApp();
});