Skip to content

Commit

Permalink
initial implementation for step params
Browse files Browse the repository at this point in the history
  • Loading branch information
DavertMik committed Jan 10, 2025
1 parent 6edc423 commit 99d93f9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/effects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { StepConfig } = require('./step')

function stepConfig(opts) {
return new StepConfig(opts)
}

module.exports = {
stepConfig,
}
6 changes: 6 additions & 0 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -3499,6 +3499,12 @@ async function proceedSee(assertType, text, context, strict = false) {
allText = await Promise.all(els.map(el => el.innerText()))
}

if (store?.currentStep?.opts?.ignoreCase === true) {
description = description.toLowerCase()
text = text.toLowerCase()
allText = allText.map(elText => elText.toLowerCase())
}

if (strict) {
return allText.map(elText => equals(description)[assertType](text, elText))
}
Expand Down
3 changes: 3 additions & 0 deletions lib/listener/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = function () {
event.dispatcher.on(event.step.started, step => {
step.startedAt = +new Date()
step.test = currentTest
store.currentStep = step
if (currentHook && Array.isArray(currentHook.steps)) {
return currentHook.steps.push(step)
}
Expand All @@ -84,5 +85,7 @@ module.exports = function () {
step.finishedAt = +new Date()
if (step.startedAt) step.duration = step.finishedAt - step.startedAt
debug(`Step '${step}' finished; Duration: ${step.duration || 0}ms`)
store.currentStep = null
store.stepOptions = null
})
}
16 changes: 16 additions & 0 deletions lib/step.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Step {
this.metaStep = undefined
/** @member {string} */
this.stack = ''
/** @member {StepConfig} */
this.opts = {}

const timeouts = new Map()
/**
Expand Down Expand Up @@ -114,6 +116,13 @@ class Step {
*/
run() {
this.args = Array.prototype.slice.call(arguments)
const lastArg = this.args[this.args.length - 1]
if (lastArg instanceof StepConfig) {
const config = this.args.pop()
store.stepOptions = config.options
this.opts = config.options
}

if (store.dryRun) {
this.setStatus('success')
return Promise.resolve(new Proxy({}, dryRunResolver()))
Expand Down Expand Up @@ -321,10 +330,17 @@ class MetaStep extends Step {
}
}

class StepConfig {
constructor(opts) {
this.options = opts
}
}

Step.TIMEOUTS = {}

/** @type {Class<MetaStep>} */
Step.MetaStep = MetaStep
Step.StepConfig = StepConfig

module.exports = Step

Expand Down
2 changes: 2 additions & 0 deletions lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const store = {
onPause: false,
/** @type {CodeceptJS.Test | null} */
currentTest: null,
/** @type {any} */
currentStep: null,
}

module.exports = store
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"main": "lib/index.js",
"exports": {
".": "./lib/index.js",
"./els": "./lib/els.js"
"./els": "./lib/els.js",
"./effects": "./lib/effects.js"
},
"types": "typings/index.d.ts",
"bin": {
Expand Down

0 comments on commit 99d93f9

Please sign in to comment.