From 6ecc1115b4ee759850bec801a0e8c94c948d1a86 Mon Sep 17 00:00:00 2001 From: Dmitry Sheiko Date: Mon, 8 Jun 2020 11:29:37 +0200 Subject: [PATCH] parse template in assertions --- CHANGELOG.md | 5 ++++ app/main/install-runtime-test.js | 2 +- jest-pkg/package.json | 2 +- package.json | 2 +- project-test/.puppetryrc | 8 ++++-- .../Schema/Assert/AssertAttribute.jsx | 10 ++++++++ .../Schema/Assert/AssertConsoleMessage.jsx | 9 +++++++ src/component/Schema/Assert/AssertDialog.jsx | 9 +++++++ .../Schema/Assert/AssertProperty.jsx | 10 ++++++++ src/component/Schema/Assert/AssertString.jsx | 10 ++++++++ src/component/Schema/Assert/AssertText.jsx | 2 +- .../Schema/Params/Element/assertStyle.js | 4 ++- src/service/assert.js | 25 +++++++++++-------- 13 files changed, 80 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e800ab5..a06b9683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# Puppetry 3.2.3 + +### Bug fixes +- fix: parsing template expressions in TARGET.assertAttribute, page.assertConsoleMessage, page.assertDialog, TARGET.assertProperty, TARGET.assertHtml, TARGET.assertStyle, page.assertContent, page.assertTitle, page.assertUrl, page.assertVar + # Puppetry 3.2.2 ### Features diff --git a/app/main/install-runtime-test.js b/app/main/install-runtime-test.js index ecbc7e22..92312220 100644 --- a/app/main/install-runtime-test.js +++ b/app/main/install-runtime-test.js @@ -124,7 +124,7 @@ exports.installRuntimeTest = ( event, appInstallDirectory ) => { "faker@^4.1.0", "jsonpath@^1.0.2", "node-localstorage@^1.3.1", - "puppeteer@3.1.0", + "puppeteer@3.3.0", "shelljs@^0.8.2", "pixelmatch@^5.1.0", "pngjs@^3.4.0", diff --git a/jest-pkg/package.json b/jest-pkg/package.json index 50082985..68498e5c 100644 --- a/jest-pkg/package.json +++ b/jest-pkg/package.json @@ -25,7 +25,7 @@ "jsonpath": "^1.0.2", "node-fetch": "^2.6.0", "node-localstorage": "^1.3.1", - "puppeteer": "^3.1.0", + "puppeteer": "^3.3.0", "shelljs": "^0.8.2", "pixelmatch": "^5.1.0", "pngjs": "^3.4.0", diff --git a/package.json b/package.json index b55954ce..819f1246 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "puppetry", "description": "Puppetry - codeless end-to-end test automation, integrated with CI/CD pipeline", - "version": "3.2.2", + "version": "3.2.3", "author": "Dmitry Sheiko (http://dsheiko.com)", "engines": { "node": ">=11.7.0" diff --git a/project-test/.puppetryrc b/project-test/.puppetryrc index cb0f0226..bb243425 100644 --- a/project-test/.puppetryrc +++ b/project-test/.puppetryrc @@ -60,6 +60,10 @@ "cgmk6tfbh3v": { "key": "cgmk6tfbh3v", "value": true + }, + "ltbk378vixm": { + "key": "ltbk378vixm", + "value": true } } }, @@ -79,9 +83,9 @@ } } }, - "savedAt": 1590424783, + "savedAt": 1591373051, "modified": false, - "lastOpenSuite": "page.assertRest.json", + "lastOpenSuite": "page.assertDialog.json", "variables": {}, "targets": { "js4k1ukyk9a": { diff --git a/src/component/Schema/Assert/AssertAttribute.jsx b/src/component/Schema/Assert/AssertAttribute.jsx index f1093b62..51b145a2 100644 --- a/src/component/Schema/Assert/AssertAttribute.jsx +++ b/src/component/Schema/Assert/AssertAttribute.jsx @@ -44,6 +44,16 @@ export class AssertAttribute extends AbstractComponent { + + { /* Force template parsing */"" } + + { getFieldDecorator( "assert.assertionType", { + initialValue: "string" + })( + + ) } + + { getFieldDecorator( "assert.assertion", { initialValue: assertion, diff --git a/src/component/Schema/Assert/AssertConsoleMessage.jsx b/src/component/Schema/Assert/AssertConsoleMessage.jsx index 1444f185..c3688ef1 100644 --- a/src/component/Schema/Assert/AssertConsoleMessage.jsx +++ b/src/component/Schema/Assert/AssertConsoleMessage.jsx @@ -62,6 +62,15 @@ export class AssertConsoleMessage extends AbstractComponent { messages sent to the console like the following + { /* Force template parsing */"" } + + { getFieldDecorator( "assert.assertionType", { + initialValue: "string" + })( + + ) } + + diff --git a/src/component/Schema/Assert/AssertDialog.jsx b/src/component/Schema/Assert/AssertDialog.jsx index ed34e42a..71192bb8 100644 --- a/src/component/Schema/Assert/AssertDialog.jsx +++ b/src/component/Schema/Assert/AssertDialog.jsx @@ -45,6 +45,15 @@ export class AssertDialog extends AbstractComponent { value = record.assert.value || ""; return ( + { /* Force template parsing */"" } + + { getFieldDecorator( "assert.assertionType", { + initialValue: "string" + })( + + ) } + + Assert there { getFieldDecorator( "assert.not", { initialValue: not, diff --git a/src/component/Schema/Assert/AssertProperty.jsx b/src/component/Schema/Assert/AssertProperty.jsx index 697651e4..2c15c626 100644 --- a/src/component/Schema/Assert/AssertProperty.jsx +++ b/src/component/Schema/Assert/AssertProperty.jsx @@ -44,6 +44,16 @@ export class AssertProperty extends AbstractComponent { + + { /* Force template parsing */"" } + + { getFieldDecorator( "assert.assertionType", { + initialValue: "string" + })( + + ) } + + { getFieldDecorator( "assert.assertion", { initialValue: assertion, diff --git a/src/component/Schema/Assert/AssertString.jsx b/src/component/Schema/Assert/AssertString.jsx index b3191a22..2a9eea7e 100644 --- a/src/component/Schema/Assert/AssertString.jsx +++ b/src/component/Schema/Assert/AssertString.jsx @@ -39,6 +39,16 @@ export class AssertString extends AbstractComponent { + + { /* Force template parsing */"" } + + { getFieldDecorator( "assert.assertionType", { + initialValue: "string" + })( + + ) } + + { getFieldDecorator( "assert.assertion", { initialValue: assertion, diff --git a/src/component/Schema/Assert/AssertText.jsx b/src/component/Schema/Assert/AssertText.jsx index c74eed6b..ec462776 100644 --- a/src/component/Schema/Assert/AssertText.jsx +++ b/src/component/Schema/Assert/AssertText.jsx @@ -42,7 +42,7 @@ export class AssertText extends AbstractComponent { - { getFieldDecorator( "assert.type", { + { getFieldDecorator( "assert.assertionType", { initialValue: "text" })( diff --git a/src/component/Schema/Params/Element/assertStyle.js b/src/component/Schema/Params/Element/assertStyle.js index 7d0999b9..885b7ee6 100644 --- a/src/component/Schema/Params/Element/assertStyle.js +++ b/src/component/Schema/Params/Element/assertStyle.js @@ -7,7 +7,9 @@ export const assertStyle = { template: ( command ) => buildAssertionTpl( `await bs.page.$eval( '${ command.targetSeletor }', ( el, prop, pseudoEl ) => window.getComputedStyle( el, pseudoEl || null ) - .getPropertyValue( prop ), "${ command.params.name }", "${ command.params.pseudo }" )`, + .getPropertyValue( prop ), "${ command.params.name }", ${ + command.params.pseudo ? JSON.stringify( command.params.pseudo ) : null +} )`, command, `// Asserting that "${ command.params.name }" CSS property's ` + `value of ${ command.target } satisfies the given constraint` diff --git a/src/service/assert.js b/src/service/assert.js index 04020812..2f447963 100644 --- a/src/service/assert.js +++ b/src/service/assert.js @@ -73,13 +73,13 @@ export function justify( text ) { return ( "\n" + text ).split( "\n" ).map( line => " " + line ).join( "\n" ); } -function parseTpl( value, id, type = "string" ) { - // @see ./src/component/Schema/Params/Element/assertText.js - if ( typeof type !== "undefined" || type === "text" ) { - return JSON.stringify( value.replace( /\n+/gm, "\n" ) ); - } +function parseTpl( value, id, type ) { if ( typeof type === "undefined" || type !== "string" ) { return JSON.stringify( value ); + } + // @see ./src/component/Schema/Params/Element/assertText.js + if ( typeof type !== "undefined" && type === "text" ) { + value = value.replace( /\n+/gm, "\n" ); } const parser = new ExpressionParser( id ); return parser.stringify( value ); @@ -135,15 +135,16 @@ function createCbBody({ assert, target, method, id, params }) { + ` ${ getExpectation( method, params, assert ) }, "${ source }" );` ); case "contains": - return justify( `expect( result ).toIncludeSubstring( ${ parseTpl( value, id, options.type ) }` + return justify( `expect( result ).toIncludeSubstring( ${ parseTpl( value, id, options.assertionType ) }` + `, "${ source }" );` ); case "!contains": - return justify( `expect( result ).not.toIncludeSubstring( ${ parseTpl( value, id, options.type ) }` + return justify( `expect( result ).not.toIncludeSubstring( ${ parseTpl( value, id, options.assertionType ) }` + `, "${ source }" );` ); case "equals": - return justify( `expect( result ).toBeEqual( ${ parseTpl( value, id, options.type ) }, "${ source }" );` ); + return justify( `expect( result ).toBeEqual( ${ parseTpl( value, id, options.assertionType ) }, "${ source }" );` ); case "!equals": - return justify( `expect( result ).not.toBeEqual( ${ parseTpl( value, id, options.type ) }, "${ source }" );` ); + return justify( `expect( result )` + + `.not.toBeEqual( ${ parseTpl( value, id, options.assertionType ) }, "${ source }" );` ); case "empty": return justify( `expect( result ).toBeEmpty( "${ source }" );` ); case "!empty": @@ -166,10 +167,12 @@ function createCbBody({ assert, target, method, id, params }) { return justify( `expect( result ).not.toHavePropertyTrue( "${ params.name }", "${ source }" );` ); case "haveString": - return justify( `expect( result )${ negate( not ) }.toHaveString( ${ parseTpl( value, id, options.type ) }` + return justify( `expect( result )${ negate( not ) }` + + `.toHaveString( ${ parseTpl( value, id, options.assertionType ) }` + `, ${ getExpectation( method, params, assert ) }, "${ source }" );` ); case "haveSubstring": - return justify( `expect( result )${ negate( not ) }.toHaveSubstring( ${ parseTpl( value, id, options.type ) }` + return justify( `expect( result )${ negate( not ) }` + + `.toHaveSubstring( ${ parseTpl( value, id, options.assertionType ) }` + `, ${ getExpectation( method, params, assert ) }, "${ source }" );` ); case "position":