diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dde268..015f6f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,20 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how :pencil: - chore :microscope: - experimental +## [3.3.0] +- :rocket: added `to satisfy` validation to verify user-defined expectation provided as predicate +```Gherkin +Then I expect '$value' to satisfy '$either(1, 2)' +``` +where `$either` is a function +```typescript +function either(...expected) { + return function (actual) { + return expected.includes(actual) + } +} +``` + ## [3.2.0] - :rocket: Added capability to provide _defaultResolver_ to define default logic to identify element ```typescript diff --git a/package-lock.json b/package-lock.json index b707138..0e50c32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,25 +1,25 @@ { "name": "@qavajs/playwright", - "version": "3.2.0", + "version": "3.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@qavajs/playwright", - "version": "3.2.0", + "version": "3.3.0", "license": "MIT", "dependencies": { - "@playwright/test": "^1.54.1", + "@playwright/test": "^1.55.0", "@qavajs/memory": "^1.10.2", "@qavajs/playwright-runner-adapter": "^1.4.3" }, "devDependencies": { "@types/express": "^5.0.3", - "@types/node": "^24.1.0", - "electron": "^37.2.4", + "@types/node": "^24.3.0", + "electron": "^37.3.1", "express": "^5.1.0", "ts-node": "^10.9.2", - "typescript": "^5.8.3" + "typescript": "^5.9.2" } }, "node_modules/@babel/code-frame": { @@ -561,12 +561,12 @@ } }, "node_modules/@playwright/test": { - "version": "1.54.1", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.54.1.tgz", - "integrity": "sha512-FS8hQ12acieG2dYSksmLOF7BNxnVf2afRJdCuM1eMSxj6QTSE6G4InGF7oApGgDb65MX7AwMVlIkpru0yZA4Xw==", + "version": "1.55.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.55.0.tgz", + "integrity": "sha512-04IXzPwHrW69XusN/SIdDdKZBzMfOT9UNT/YiJit/xpy2VuAoB8NHc8Aplb96zsWDddLnbkPL3TsmrS04ZU2xQ==", "license": "Apache-2.0", "dependencies": { - "playwright": "1.54.1" + "playwright": "1.55.0" }, "bin": { "playwright": "cli.js" @@ -754,13 +754,13 @@ "dev": true }, "node_modules/@types/node": { - "version": "24.1.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.1.0.tgz", - "integrity": "sha512-ut5FthK5moxFKH2T1CUOC6ctR67rQRvvHdFLCD2Ql6KXmMuCrjsSsRI9UsLCm9M18BMwClv4pn327UvB7eeO1w==", + "version": "24.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.3.0.tgz", + "integrity": "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow==", "dev": true, "license": "MIT", "dependencies": { - "undici-types": "~7.8.0" + "undici-types": "~7.10.0" } }, "node_modules/@types/normalize-package-data": { @@ -1354,9 +1354,9 @@ "license": "MIT" }, "node_modules/electron": { - "version": "37.2.4", - "resolved": "https://registry.npmjs.org/electron/-/electron-37.2.4.tgz", - "integrity": "sha512-F1WDDvY60TpFwGyW+evNB5q0Em8PamcDTVIKB2NaiaKEbNC2Fabn8Wyxy5g+Anirr1K40eKGjfSJhWEUbI1TOw==", + "version": "37.3.1", + "resolved": "https://registry.npmjs.org/electron/-/electron-37.3.1.tgz", + "integrity": "sha512-7DhktRLqhe6OJh/Bo75bTI0puUYEmIwSzMinocgO63mx3MVjtIn2tYMzLmAleNIlud2htkjpsMG2zT4PiTCloA==", "dev": true, "hasInstallScript": true, "license": "MIT", @@ -2605,12 +2605,12 @@ "license": "ISC" }, "node_modules/playwright": { - "version": "1.54.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.54.1.tgz", - "integrity": "sha512-peWpSwIBmSLi6aW2auvrUtf2DqY16YYcCMO8rTVx486jKmDTJg7UAhyrraP98GB8BoPURZP8+nxO7TSd4cPr5g==", + "version": "1.55.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.55.0.tgz", + "integrity": "sha512-sdCWStblvV1YU909Xqx0DhOjPZE4/5lJsIS84IfN9dAZfcl/CIZ5O8l3o0j7hPMjDvqoTF8ZUcc+i/GL5erstA==", "license": "Apache-2.0", "dependencies": { - "playwright-core": "1.54.1" + "playwright-core": "1.55.0" }, "bin": { "playwright": "cli.js" @@ -2623,9 +2623,9 @@ } }, "node_modules/playwright-core": { - "version": "1.54.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.54.1.tgz", - "integrity": "sha512-Nbjs2zjj0htNhzgiy5wu+3w09YetDx5pkrpI/kZotDlDUaYk0HVA5xrBVPdow4SAUIlhgKcJeJg4GRKW6xHusA==", + "version": "1.55.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.55.0.tgz", + "integrity": "sha512-GvZs4vU3U5ro2nZpeiwyb0zuFaqb9sUiAJuyrWpcGouD8y9/HLgGbNRjIph7zU9D3hnPaisMl9zG9CgFi/biIg==", "license": "Apache-2.0", "bin": { "playwright-core": "cli.js" @@ -3456,9 +3456,9 @@ } }, "node_modules/typescript": { - "version": "5.8.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", - "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", + "version": "5.9.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.2.tgz", + "integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==", "dev": true, "license": "Apache-2.0", "bin": { @@ -3470,9 +3470,9 @@ } }, "node_modules/undici-types": { - "version": "7.8.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.8.0.tgz", - "integrity": "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==", + "version": "7.10.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.10.0.tgz", + "integrity": "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index ab14d83..9a83ce7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@qavajs/playwright", - "version": "3.2.0", + "version": "3.3.0", "description": "steps to interact with playwright", "main": "./index.js", "scripts": { @@ -26,14 +26,14 @@ "homepage": "https://github.com/qavajs/playwright#readme", "devDependencies": { "@types/express": "^5.0.3", - "@types/node": "^24.1.0", - "electron": "^37.2.4", + "@types/node": "^24.3.0", + "electron": "^37.3.1", "express": "^5.1.0", "ts-node": "^10.9.2", - "typescript": "^5.8.3" + "typescript": "^5.9.2" }, "dependencies": { - "@playwright/test": "^1.54.1", + "@playwright/test": "^1.55.0", "@qavajs/playwright-runner-adapter": "^1.4.3", "@qavajs/memory": "^1.10.2" } diff --git a/src/parameterTypes.ts b/src/parameterTypes.ts index 2860931..8080ca7 100644 --- a/src/parameterTypes.ts +++ b/src/parameterTypes.ts @@ -13,7 +13,7 @@ function transformString(fn: (value: string) => any) { defineParameterType({ name: 'validation', - regexp: /((?:is |do |does |to )?(not |to not )?(?:to )?(?:be )?(softly )?(equal|strictly equal|deeply equal|have member|match|contain|above|below|greater than|less than|have type)(?:s|es)?)/, + regexp: /((?:is |do |does |to )?(not |to not )?(?:to )?(?:be )?(softly )?(equal|strictly equal|deeply equal|have member|match|contain|above|below|greater than|less than|have type|satisfy|case insensitive equal)(?:s|es)?)/, transformer: condition => { const validation: Validation = function (AR: any, ER: any) { return valueExpect(AR, ER, condition); diff --git a/src/validationExpect.ts b/src/validationExpect.ts index d2db00f..d41836b 100644 --- a/src/validationExpect.ts +++ b/src/validationExpect.ts @@ -19,6 +19,13 @@ export const expect = base.extend({ pass } }, + toSatisfy(actual: any, predicate: any) { + const pass = predicate(actual); + return { + message: () => `expected ${actual} ${pass ? 'not ': ''}to satisfy ${this.utils.printReceived(predicate)}`, + pass + } + } }); export const validations = { @@ -35,6 +42,8 @@ export const validations = { HAVE_TYPE: 'have type', INCLUDE_MEMBERS: 'include member', MATCH_SCHEMA: 'match schema', + SATISFY: 'satisfy', + CASE_INSENSITIVE_EQUAL: 'case insensitive equal', }; const isClause = '(?:is |do |does |to )?'; @@ -94,6 +103,11 @@ const expects = { [validations.HAVE_TYPE]: // @ts-ignore ({ expected, actual, reverse, poll, soft }: ExpectOptions) => expectValue({ expected, reverse, poll, soft }).toHaveType(actual), + [validations.CASE_INSENSITIVE_EQUAL]: + ({ expected, actual, reverse, poll, soft }: ExpectOptions) => expectValue({ expected: expected.toLowerCase(), reverse, poll, soft }).toEqual(actual.toLowerCase()), + [validations.SATISFY]: + // @ts-ignore + ({ expected, actual, reverse, poll, soft }: ExpectOptions) => expectValue({ expected, reverse, poll, soft }).toSatisfy(actual), }; export function valueExpect( diff --git a/test-e2e/features/validations.feature b/test-e2e/features/validations.feature index 9b4f188..ff0993f 100644 --- a/test-e2e/features/validations.feature +++ b/test-e2e/features/validations.feature @@ -146,3 +146,24 @@ Feature: validations Then I expect '3' not to equal all of: | 1 | | $two | + + Scenario Outline: validation type () + When I expect '' '' + + Examples: + | argument1 | argument2 | validation | + | 1 | 1 | to equal | + | 1 | 2 | to not equal | + | test | tes | to contain | + | 1 | 1 | to strictly equal | + | $js({ a: 1 }) | $js({ a: 1 }) | to deeply equal | + | Test | test | to case insensitive equal | +# | $js([1, 2, 3]) | $js([3]) | to include members | +# | $js([3, 2, 1]) | $js([1, 2, 3]) | to have members | +# | $js({ a: 1 }) | a | to have property | + | $js(2) | $js(1) | to be greater than | + | $js(1) | $js(2) | to be less than | + | test | tes. | to match | + | $js("Test") | string | to have type | +# | $js({ a: 1 }) | $js({ type: "object", properties: { a: { type: "number" } } }) | to match schema | + | 1 | $js(arg => ["1","2"].includes(arg)) | to satisfy |