由Mocha运行时从其他ts文件导入时意外导入令牌

时间:2019-03-15 15:03:01

标签: javascript typescript electron mocha spectron

我有一个Util类,其中保存了一些有关测试类的信息

import * as electron from "electron";
import { Application } from "spectron";

export class TestUtils {
  public app: Application;
  public windowsCount = 2;

  public windowByIndex() { return this.windowsCount - 1; }

  public setUp() {
    // start application
    this.app = new Application({
      // path to electron app
      args: ["./dist/main.js"],
      path: "" + electron,
      startTimeout: 30000,
      waitTimeout: 30000,
    });
    return this.app.start();
  }

  public tearDown() {
    // close browser
    const windows = this.app.client.windowHandles() as any;
    this.app.client.close(windows.sessionId);
  }
}

我有以下结构

enter image description here

我想做的是用import { TestUtils } from "../helpers/TestUtils"

导入TestUtils

但是我得到了错误

import { TestUtils } from "../helpers/TestUtils"
^^^^^^

SyntaxError: Unexpected token import

我的tsconfig.ts文件包含

{
  "compilerOptions": {
    "module": "commonjs",
    "lib": [
      "es2017"
    ],
    "noImplicitAny": false,
    "skipLibCheck": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*"]
    }
  },
  "include": [
    "src/**/*"
  ]
}

我已将app.e2e-spec.js更改为app.e2e-spec.ts,但仍然出现此错误。

0 个答案:

没有答案
相关问题