Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript typings errors for ScenarioConfig.config and FeatureConfig.config #4848

Closed
danielrentz opened this issue Feb 11, 2025 · 5 comments · Fixed by #4851
Closed

TypeScript typings errors for ScenarioConfig.config and FeatureConfig.config #4848

danielrentz opened this issue Feb 11, 2025 · 5 comments · Fixed by #4851

Comments

@danielrentz
Copy link
Contributor

In https://codecept.io/advanced/#dynamic-configuration it is documented that Scenario().config can be called with (options), (string, options), or (function).

The type signature in types.d.ts is

    class ScenarioConfig {
        config(helper: string | { [key: string]: any; }, obj?: {[key: string]: any; }): this;
    }

which allows (string), (options), (string, options), or (options, options). The function variant is missing completely.

Better signature would be

    class ScenarioConfig {
        config(obj: {[key: string]: any; }): this;
        config(helper: string, obj: {[key: string]: any; }): this;
        config(fn: (test: TestObject) => unknown): this;
    }

(with the correct type for the test object).

Similar but even worse problem for Feature().config: Documentation only shows (options), but types.d.ts contains

    class FeatureConfig {
        config(helper: string | number, obj: any): this;
    }

Btw, in v3.6.10 the type definition of FeatureConfig.config was equal to ScenarioConfig.config, what was the reason for changing it?

@DavertMik
Copy link
Contributor

@danielrentz Please make Pull Request to fix this!
I will pack it in the next patch release

@danielrentz
Copy link
Contributor Author

@DavertMik
Seems, this issue cannot be solved completely as long as type definitions will be generated from source doc (no support for function overloading). Anyways, will try my best in the MR... :)

@danielrentz
Copy link
Contributor Author

@DavertMik This happens when I follow the steps in CONTRIBUTING.md:

> npm i --force --omit=optional
> npm run docs
...
building @codecepjs/detox helper docs
[#4 REPLACEINFILE] › ℹ  node_modules/@codeceptjs/detox-helper/Detox.js
[#4 REPLACEINFILE] › ✖  Failed with "ENOENT: no such file or directory, open 'node_modules/@codeceptjs/detox-helper/Detox.js'"  in 0 ms
[#4 REPLACEINFILE] › ⚠  warning   Execution stopped

After that, I tried with optional deps, which brings me a few steps further, but still no success:

> npm i --force
> npm run docs
...
[#26 REPLACEINFILE] › ℹ  docs/helpers/Appium.md
[#26 REPLACEINFILE] › ✔  Finished  in 1 ms
[#27 REPLACEINFILE] › ℹ  docs/helpers/Appium.md
[#27 REPLACEINFILE] › ✔  Finished  in 0 ms
[#28 REPLACEINFILE] › ℹ  docs/helpers/Appium.md
[#28 REPLACEINFILE] › ✔  Finished  in 0 ms
~/github/codeceptjs/runok.js:339
    for (const method of webdriverDoc[0].members.instance) {
                                         ^

TypeError: Cannot read properties of undefined (reading 'members')
    at Object.docsAppium (~/github/codeceptjs/runok.js:339:42)
    at async Object.docsHelpers (~/github/codeceptjs/runok.js:245:9)
    at async Promise.all (index 0)
    at async Object.docs (~/github/codeceptjs/runok.js:29:5)

Node.js v20.13.1

Any advice?

@danielrentz
Copy link
Contributor Author

@DavertMik Even committing fails:

> git commit -m "fix #4848 ..."
lib/mocha/featureConfig.js 58ms (unchanged)
lib/mocha/scenarioConfig.js 13ms (unchanged)

> [email protected] dtslint
> npm run types-fix && tsd


> [email protected] types-fix
> node typings/fixDefFiles.js

Error reading the file: Error: ENOENT: no such file or directory, open '~/github/codeceptjs/typings/promiseBasedTypes.d.ts'
Error reading the file: Error: ENOENT: no such file or directory, open '~/github/codeceptjs/typings/types.d.ts'

followed by a ton of unrelated (?) type linter errors

@kobenguyent
Copy link
Collaborator

@danielrentz well, looks like we need to run npm run def before npm run docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants