1

I have a Util class where I saved some info for my test classes

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);
  }
}

and I have the following structure

enter image description here

what I am trying to do is to import the TestUtils with import { TestUtils } from "../helpers/TestUtils"

but then I got the error

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

SyntaxError: Unexpected token import

my tsconfig.ts file contains

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

I have changed the app.e2e-spec.js to app.e2e-spec.ts but I still got this error.

E_net4
  • 27,810
  • 13
  • 101
  • 139
FarFarAway
  • 1,017
  • 3
  • 14
  • 35
  • It would be helpful to know what is saying "unexpected token import" - TypeScript? Node.js? Your browser? A test runner? Something else? – Tyler Church Mar 15 '19 at 15:21
  • You might also try setting "target" to "es5" under "compilerOptions" to see if that makes any difference for you. – Tyler Church Mar 15 '19 at 15:22
  • es5 und es6 did not help . i got the error when running by mocha – FarFarAway Mar 15 '19 at 15:24
  • When you run with Mocha, what version of Node.js are you using? Also, are you telling Mocha to run the .ts files directly? Or the compiled .js files? Because it's the compiled .js files that you really want to run (especially when "target" is "es5") – Tyler Church Mar 15 '19 at 15:55

0 Answers0