Search code examples
typescriptautomated-testsplaywrightcodeceptjs

Intellisense not working for Playwright, REST


I write autotests on the Codeceptjs framework in TypeScript. After adding additional modules to the project, as well as after updating the repository with the command:

npx codeceptjs def

Intellisense is starting to work for me and I'm starting to see methods that I can use. For example, I see methods of such modules as: JSONResponse, DbHelper, ChaiWrapper. image

I also installed Playwright and REST. But for these modules, intelisense does not work.

codecept.conf.ts

import { setHeadlessWhen, setCommonPlugins } from '@codeceptjs/configure';
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);
const env = require('dotenv').config({
path: '.env.test'
})

if (env.error && env.error.code === 'ENOENT') {
throw new Error('Please, recreate env.test file')
}

const base_url = process.env.URL
const currentBrowser = process.env.profile ?? 'chromium'; // 'firefox', 'webkit'

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

export const config: CodeceptJS.MainConfig = {
tests: './tests/\*\_test.ts',
output: './output',
helpers: {
ChaiWrapper: {
require: "codeceptjs-chai"
},
Playwright: {
url: base_url,
show: true,
browser: currentBrowser
},
REST: {
endpoint: base_url,
},
JSONResponse: {},
DbHelper: {
"require": "codeceptjs-dbhelper"
}
},
include: {
"I": "./common/custom_steps",
},
plugins: {
tryTo: {
enabled: true
}
},
name: 'test',
fullPromiseBased: false
}

package.json

{
"name": "codeceptjs-tests",
"version": "0.1.0",
"private": true,
"scripts": {
"codeceptjs": "codeceptjs run --steps",
"codeceptjs:headless": "HEADLESS=true codeceptjs run --steps",
"codeceptjs:ui": "codecept-ui --app",
"codeceptjs:demo": "codeceptjs run --steps -c node_modules/@codeceptjs/examples",
"codeceptjs:demo:headless": "HEADLESS=true codeceptjs run --steps -c node_modules/@codeceptjs/examples",
"codeceptjs:demo:ui": "codecept-ui --app  -c node_modules/@codeceptjs/examples"
},
"devDependencies": {
"@codeceptjs/configure": "^0.10.0",
"@codeceptjs/examples": "^1.2.1",
"@codeceptjs/ui": "^0.4.7",
"@types/node": "^18.11.12",
"codeceptjs": "^3.3.7",
"playwright": "^1.28.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
},
"dependencies": {
"codeceptjs-chai": "^2.3.3",
"codeceptjs-dbhelper": "^1.2.2",
"database-js-mssql": "^0.3.0",
"database-js-mysql": "^1.1.3",
"dateformat": "^5.0.3",
"dotenv": "^16.0.3",
"faker": "^6.6.6",
"object-hash": "^3.0.0",
"randexp": "^0.5.3",
"random-date-generator": "^1.0.2",
"random-mobile-numbers": "^1.0.1",
"underscore": "^1.13.6",
"unique-names-generator": "^4.7.1"
}
}

Reinstalling modules doesn't help.


Solution

  • I found the solution. In steps.d.ts you need to add the transfer of Methods to WithTranslation

    Instead of interface I extends ReturnType<steps_file>, WithTranslation<ChaiWrapper>, WithTranslation<JSONResponse>, WithTranslation<DbHelper> {}

    We are adding interface I extends ReturnType<steps_file>, WithTranslation<Methods> {}