【发布时间】:2019-07-24 22:36:45
【问题描述】:
我正在尝试按照https://webdriver.io/docs/typescript.html 将我的 webdriver.io + cucumber 项目转换为 Typescript,并收到错误消息“Unexpected toke {”。 我正在使用 WebDriver.io + TypeScript + Cucumber。
在 wdio.conf.js 中,我有 cucumberOpts 如下
cucumberOpts: {
requireModule: [
'tsconfig-paths/register',
() => { require('ts-node').register({files: true}) },
],
require: ['./src/step_definitions/*.ts'],
backtrace: false,
requireModule: [],
dryRun: false,
failFast: false,
format: ['pretty'],
colors: true,
snippets: true,
source: true,
profile: [],
strict: false,
tags: [],
timeout: 60000,
ignoreUndefinedDefinitions: false,
},
我的 tsconfig.json 如下所示
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"removeComments": true,
"noImplicitAny": false,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [ "./*" ],
"src/*": ["./src/*"]
},
"types": ["node", "@wdio/sync","jest"]
},
"include": [
"./src/**/*"
]
}
我的文件夹结构如下
src/features/
src/step_definitions
src/pageObjects
我的步骤定义如下作为第一条语句
step.ts
import { Given, When, Then } from "cucumber";
包.json
"scripts": {
"test":"./node_modules/.bin/wdio wdio.conf.js"
},
当我运行测试时,我在 step.ts 的上述第一行收到错误消息“SyntaxError: Unexpected token {”。
如何解决此错误。
【问题讨论】:
-
你好!你会得到 ES6
import语句的错误原因。看起来编译器不批准包含的库版本。我会尝试起草一个答案,但如果您使用相关的package.json依赖项(ts-node、所有@types等)更新答案,我将不胜感激。
标签: typescript cucumber webdriver-io cucumberjs