Skip to content

Commit

Permalink
fixed typings
Browse files Browse the repository at this point in the history
  • Loading branch information
DavertMik committed Jan 12, 2025
1 parent 7703147 commit d9af19d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
14 changes: 14 additions & 0 deletions lib/step.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
// refactored step class, moved to helper
/**
* Step is wrapper around a helper method.
* It is used to create a new step that is a combination of other steps.
*/
const BaseStep = require('./step/base')
const StepConfig = require('./step/config')
const Step = require('./step/helper')

/**
* MetaStep is a step that is used to wrap other steps.
* It is used to create a new step that is a combination of other steps.
* It is used to create a new step that is a combination of other steps.
*/
const MetaStep = require('./step/meta')

module.exports = Step
module.exports.MetaStep = MetaStep
module.exports.BaseStep = BaseStep
module.exports.StepConfig = StepConfig
5 changes: 2 additions & 3 deletions lib/step/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const STACK_LINE = 4
/**
* Each command in test executed through `I.` object is wrapped in Step.
* Step allows logging executed commands and triggers hook before and after step execution.
* @param {CodeceptJS.Helper} helper
* @param {string} name
*/
class Step {
Expand All @@ -21,7 +20,7 @@ class Step {
/** @member {Array<*>} */
this.args = []

/** @member {StepConfig} */
/** @member {Record<string,any>} */
this.opts = {}
/** @member {string} */
this.actor = 'I' // I = actor
Expand All @@ -33,7 +32,7 @@ class Step {
this.prefix = this.suffix = ''
/** @member {string} */
this.comment = ''
/** @member {MetaStep} */
/** @member {import('./meta')} */
this.metaStep = undefined
/** @member {string} */
this.stack = ''
Expand Down
22 changes: 21 additions & 1 deletion lib/step/config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
/**
* StepConfig is a configuration object for a step.
* It is used to create a new step that is a combination of other steps.
*/
class StepConfig {
constructor(opts) {
constructor(opts = {}) {
/** @member {{ opts: Record<string, any>, timeout: number|undefined, retry: number|undefined }} */
this.config = {
opts,
timeout: undefined,
retry: undefined,
}
}

/**
* Set the options for the step.
* @param {object} opts - The options for the step.
* @returns {StepConfig} - The step configuration object.
*/
opts(opts) {
this.config.opts = opts
return this
}

/**
* Set the timeout for the step.
* @param {number} timeout - The timeout for the step.
* @returns {StepConfig} - The step configuration object.
*/
timeout(timeout) {
this.config.timeout = timeout
return this
}

/**
* Set the retry for the step.
* @param {number} retry - The retry for the step.
* @returns {StepConfig} - The step configuration object.
*/
retry(retry) {
this.config.retry = retry
return this
Expand Down
4 changes: 2 additions & 2 deletions lib/step/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const event = require('../event')
const { humanizeString } = require('../utils')

class MetaStep extends Step {
constructor(obj, method) {
constructor(actor, method) {
if (!method) method = ''
super(method)
this.actor = obj
this.actor = actor
}

/** @return {boolean} */
Expand Down
3 changes: 0 additions & 3 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,6 @@ declare namespace CodeceptJS {
}

// Extending JSDoc generated typings
interface Step {
isMetaStep(): this is MetaStep
}

// Types who are not be defined by JSDoc
type actor = <T extends { [action: string]: (...args: any[]) => void }>(customSteps?: T & ThisType<WithTranslation<Methods & T>>) => WithTranslation<Methods & T>
Expand Down
5 changes: 4 additions & 1 deletion typings/jsdoc.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module.exports = {
'./lib/recorder.js',
'./lib/secret.js',
'./lib/session.js',
'./lib/step.js',
'./lib/step/config.js',
'./lib/step/base.js',
'./lib/step/helper.js',
'./lib/step/meta.js',
'./lib/store.js',
'./lib/mocha/ui.js',
'./lib/mocha/featureConfig.js',
Expand Down

0 comments on commit d9af19d

Please sign in to comment.