2

I have to create a testing framework using CodeceptJS. I am trying to use typescript instead of javascript to write my page objects and tests. Can someone help with what configuration is required in conf.js or steps.ts file

I have added below in conf file but not sure what else to add require: ["ts-node/register", "should"]

eyllanesc
  • 190,383
  • 15
  • 87
  • 142
Mithun
  • 23
  • 1
  • 7

2 Answers2

4
  1. Add package ts-node to your package.json dev dependencies. And install dependencies
  2. Add require: ["ts-node/register"] to config.
  3. Make sure, your tests regexp in configuration supports ts files: for example tests: "./tests/*.spec.ts"

Definitions for codeceptjs are generated by command codeceptjs def. https://codecept.io/commands#typescript-definitions

You should add this definitions in your tsconfig.

P.S. There are an example for TS&CodeceptJS integration: https://github.com/elukoyanov/codecept-typescript-example

Pay attention, it has one tsconfig for main project (in project directory) and second tsconfig for codeceptjs only (in src/specs/e2e path)

  • Hi Evgeny, Thanks for the help. However i could see below error and in the sample shared i see this has been removed. I honestly don't know what this is for (looks like for test events like start etc). Dont we need this steps.d.ts:77:15 - error TS2304: Cannot find name 'EventEmitter'. 77 dispatcher: EventEmitter – Mithun Aug 15 '19 at 11:30
  • I see it was added 3 weeks ago. It was later, than repo created. https://github.com/Codeception/CodeceptJS/pull/1800/files#diff-b38e49bd02b239814a0c2fa24175ecd4R87 I\ll try to search solution – Evgeny Lukoyanov Aug 15 '19 at 13:50
  • Try to manually change `EventEmitter` on `NodeJS.EventEmitter`. I'll make a fix for one of the next releases. – Evgeny Lukoyanov Aug 15 '19 at 13:53
  • Thanks alot Evgeny – Mithun Aug 15 '19 at 14:07
  • Codeceptjs 2.3.0, released today, includes this fix – Evgeny Lukoyanov Aug 16 '19 at 08:34
  • Hi Lukoyanov, i just updated the codeceptjs to 2.3.0 but tsc -w still gives the same error. Is there something i am missing – Mithun Aug 18 '19 at 06:15
  • What about Gherkin? It doesn't seem to support typescript. only JS – evanjmg Sep 02 '19 at 14:16
0

There is now a TypeScript example from the CodeceptJS developers on Github.

The official documentation also has step-by-step instructions for configuring TypeScript support.

Patrick Kenny
  • 1,251
  • 1
  • 15
  • 27