From 75f0c64f7c71edddc7c332fc55622ff5b5542ca8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 31 Mar 2023 13:47:21 +0200 Subject: [PATCH 1/4] Add `null` argument support for `assert-document-property*` and `assert-window-property*` commands --- src/commands/assert.js | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/commands/assert.js b/src/commands/assert.js index 392316c2..f64b6302 100644 --- a/src/commands/assert.js +++ b/src/commands/assert.js @@ -179,7 +179,8 @@ function parseAssertObjPropertyInner(parser, assertFalse, objName) { json_dict = elems[0].getRaw(); } - const entries = validateJson(json_dict, {'string': [], 'number': []}, 'property'); + const entries = validateJson( + json_dict, {'string': [], 'number': [], 'ident': ['null']}, 'property'); if (entries.error !== undefined) { return entries; } @@ -201,8 +202,13 @@ function parseAssertObjPropertyInner(parser, assertFalse, objName) { const varValue = varName + 'Value'; // JSON.stringify produces a problematic output so instead we use this. const values = []; + const undefProps = []; for (const [k, v] of Object.entries(entries.values)) { - values.push(`"${k}":"${v.value}"`); + if (v.kind !== 'ident') { + values.push(`"${k}":"${v.value}"`); + } else { + undefProps.push(`"${k}"`); + } } const checks = []; @@ -272,6 +278,9 @@ if (Number.isNaN(${objName}[${varKey}])) { }`); } } + + // eslint-disable-next-line no-extra-parens + const hasSpecialChecks = (enabled_checks['ALL'] && checks.length > 1) || checks.length !== 0; // If no check was enabled. if (checks.length === 0) { if (assertFalse) { @@ -287,18 +296,38 @@ if (String(${objName}[${varKey}]) != ${varValue}) { }`); } } + if (undefProps.length > 0 && hasSpecialChecks) { + const k = Object.entries(enabled_checks) + .filter(([k, v]) => v && k !== 'ALL') + .map(([k, _]) => k); + warnings.push(`Special checks (${k.join(', ')}) will be ignored for \`null\``); + } let err = ''; + let unexpectedPropError = ''; + let expectedPropError = ''; if (!assertFalse) { err = '\n'; err += indentString(`nonMatchingProps.push('Unknown ${objName} property \`' + ${varKey} + \ '\`');`, 3); + unexpectedPropError = ` + nonMatchingProps.push("Expected property \`" + prop + "\` to not exist, found: \ +\`" + ${objName}[prop] + "\`");`; + } else { + expectedPropError = ` + nonMatchingProps.push("Property named \`" + prop + "\` doesn't exist");`; } const instructions = [`\ await page.evaluate(() => { const nonMatchingProps = []; const ${varDict} = {${values.join(',')}}; + const undefProps = [${undefProps.join(',')}]; + for (const prop of undefProps) { + if (${objName}[prop] !== undefined) {${unexpectedPropError} + continue; + }${expectedPropError} + } for (const [${varKey}, ${varValue}] of Object.entries(${varDict})) { if (${objName}[${varKey}] === undefined) {${err} continue; @@ -531,7 +560,7 @@ the check will be performed on the element itself`); \`" + e[prop] + "\`");`; } else { expectedPropError = ` - nonMatchingProps.push("Property named \`" + prop + "\` doesn't exist");`; + nonMatchingProps.push("Property named \`" + prop + "\` doesn't exist");`; } const checkAllElements = enabled_checks['ALL'] === true; From 18b89fc0d972b586423716220c2f531b9d45d169 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 31 Mar 2023 13:46:40 +0200 Subject: [PATCH 2/4] Update API test for `assert-document-property*` and `assert-window-property*` commands --- .../parseAssertDocumentProperty/basic-1.toml | 7 ++++ .../parseAssertDocumentProperty/basic-2.toml | 7 ++++ .../parseAssertDocumentProperty/extra-1.toml | 7 ++++ .../parseAssertDocumentProperty/extra-2.toml | 7 ++++ .../parseAssertDocumentProperty/extra-3.toml | 7 ++++ .../parseAssertDocumentProperty/extra-4.toml | 7 ++++ .../parseAssertDocumentProperty/extra-5.toml | 7 ++++ .../parseAssertDocumentProperty/null-1.toml | 1 + .../parseAssertDocumentProperty/null-2.toml | 28 +++++++++++++++ .../parseAssertDocumentProperty/null-3.toml | 31 ++++++++++++++++ .../parseAssertDocumentProperty/null-4.toml | 36 +++++++++++++++++++ .../parseAssertDocumentProperty/null-5.toml | 36 +++++++++++++++++++ .../basic-1.toml | 7 ++++ .../basic-2.toml | 7 ++++ .../extra-1.toml | 7 ++++ .../extra-2.toml | 7 ++++ .../extra-3.toml | 7 ++++ .../extra-4.toml | 7 ++++ .../extra-5.toml | 7 ++++ .../null-1.toml | 1 + .../null-2.toml | 27 ++++++++++++++ .../null-3.toml | 30 ++++++++++++++++ .../null-4.toml | 35 ++++++++++++++++++ .../null-5.toml | 35 ++++++++++++++++++ .../parseAssertPropertyFalse/basic-1.toml | 2 +- .../parseAssertPropertyFalse/basic-2.toml | 2 +- .../parseAssertPropertyFalse/basic-3.toml | 2 +- .../parseAssertPropertyFalse/extra-1.toml | 2 +- .../parseAssertPropertyFalse/extra-2.toml | 2 +- .../parseAssertPropertyFalse/extra-3.toml | 2 +- .../parseAssertPropertyFalse/multiline-2.toml | 2 +- .../parseAssertPropertyFalse/pseudo-1.toml | 2 +- .../parseAssertPropertyFalse/pseudo-2.toml | 2 +- .../parseAssertPropertyFalse/pseudo-3.toml | 2 +- .../parseAssertPropertyFalse/pseudo-4.toml | 2 +- .../parseAssertPropertyFalse/pseudo-5.toml | 2 +- .../parseAssertPropertyFalse/pseudo-6.toml | 2 +- .../parseAssertPropertyFalse/undef-1.toml | 2 +- .../parseAssertPropertyFalse/undef-2.toml | 2 +- .../parseAssertPropertyFalse/xpath-1.toml | 2 +- .../parseAssertPropertyFalse/xpath-2.toml | 2 +- .../parseAssertPropertyFalse/xpath-3.toml | 2 +- .../parseAssertWindowProperty/basic-1.toml | 7 ++++ .../parseAssertWindowProperty/basic-2.toml | 7 ++++ .../parseAssertWindowProperty/extra-1.toml | 7 ++++ .../parseAssertWindowProperty/extra-2.toml | 7 ++++ .../parseAssertWindowProperty/extra-3.toml | 7 ++++ .../parseAssertWindowProperty/extra-4.toml | 7 ++++ .../parseAssertWindowProperty/extra-5.toml | 7 ++++ .../parseAssertWindowProperty/null-1.toml | 1 + .../parseAssertWindowProperty/null-2.toml | 28 +++++++++++++++ .../parseAssertWindowProperty/null-3.toml | 31 ++++++++++++++++ .../parseAssertWindowProperty/null-4.toml | 36 +++++++++++++++++++ .../parseAssertWindowProperty/null-5.toml | 36 +++++++++++++++++++ .../basic-1.toml | 7 ++++ .../basic-2.toml | 7 ++++ .../extra-1.toml | 7 ++++ .../extra-2.toml | 7 ++++ .../extra-3.toml | 7 ++++ .../extra-4.toml | 7 ++++ .../extra-5.toml | 7 ++++ .../null-1.toml | 1 + .../null-2.toml | 27 ++++++++++++++ .../null-3.toml | 30 ++++++++++++++++ .../null-4.toml | 35 ++++++++++++++++++ .../null-5.toml | 35 ++++++++++++++++++ tests/test-js/api.js | 6 ++++ 67 files changed, 740 insertions(+), 18 deletions(-) create mode 100644 tests/test-js/api-output/parseAssertDocumentProperty/null-1.toml create mode 100644 tests/test-js/api-output/parseAssertDocumentProperty/null-2.toml create mode 100644 tests/test-js/api-output/parseAssertDocumentProperty/null-3.toml create mode 100644 tests/test-js/api-output/parseAssertDocumentProperty/null-4.toml create mode 100644 tests/test-js/api-output/parseAssertDocumentProperty/null-5.toml create mode 100644 tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-1.toml create mode 100644 tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-2.toml create mode 100644 tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-3.toml create mode 100644 tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-4.toml create mode 100644 tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-5.toml create mode 100644 tests/test-js/api-output/parseAssertWindowProperty/null-1.toml create mode 100644 tests/test-js/api-output/parseAssertWindowProperty/null-2.toml create mode 100644 tests/test-js/api-output/parseAssertWindowProperty/null-3.toml create mode 100644 tests/test-js/api-output/parseAssertWindowProperty/null-4.toml create mode 100644 tests/test-js/api-output/parseAssertWindowProperty/null-5.toml create mode 100644 tests/test-js/api-output/parseAssertWindowPropertyFalse/null-1.toml create mode 100644 tests/test-js/api-output/parseAssertWindowPropertyFalse/null-2.toml create mode 100644 tests/test-js/api-output/parseAssertWindowPropertyFalse/null-3.toml create mode 100644 tests/test-js/api-output/parseAssertWindowPropertyFalse/null-4.toml create mode 100644 tests/test-js/api-output/parseAssertWindowPropertyFalse/null-5.toml diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/basic-1.toml b/tests/test-js/api-output/parseAssertDocumentProperty/basic-1.toml index fb6a56e1..aeb1cf88 100644 --- a/tests/test-js/api-output/parseAssertDocumentProperty/basic-1.toml +++ b/tests/test-js/api-output/parseAssertDocumentProperty/basic-1.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + document[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown document property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/basic-2.toml b/tests/test-js/api-output/parseAssertDocumentProperty/basic-2.toml index fb6a56e1..aeb1cf88 100644 --- a/tests/test-js/api-output/parseAssertDocumentProperty/basic-2.toml +++ b/tests/test-js/api-output/parseAssertDocumentProperty/basic-2.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + document[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown document property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/extra-1.toml b/tests/test-js/api-output/parseAssertDocumentProperty/extra-1.toml index 23f6df6d..d7446071 100644 --- a/tests/test-js/api-output/parseAssertDocumentProperty/extra-1.toml +++ b/tests/test-js/api-output/parseAssertDocumentProperty/extra-1.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + document[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown document property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/extra-2.toml b/tests/test-js/api-output/parseAssertDocumentProperty/extra-2.toml index 6374e362..a8b3cdb1 100644 --- a/tests/test-js/api-output/parseAssertDocumentProperty/extra-2.toml +++ b/tests/test-js/api-output/parseAssertDocumentProperty/extra-2.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + document[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown document property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/extra-3.toml b/tests/test-js/api-output/parseAssertDocumentProperty/extra-3.toml index 93194907..2caa8e52 100644 --- a/tests/test-js/api-output/parseAssertDocumentProperty/extra-3.toml +++ b/tests/test-js/api-output/parseAssertDocumentProperty/extra-3.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + document[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown document property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/extra-4.toml b/tests/test-js/api-output/parseAssertDocumentProperty/extra-4.toml index 9bb51686..32469439 100644 --- a/tests/test-js/api-output/parseAssertDocumentProperty/extra-4.toml +++ b/tests/test-js/api-output/parseAssertDocumentProperty/extra-4.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + document[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown document property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/extra-5.toml b/tests/test-js/api-output/parseAssertDocumentProperty/extra-5.toml index 548ac3c6..1bb978b2 100644 --- a/tests/test-js/api-output/parseAssertDocumentProperty/extra-5.toml +++ b/tests/test-js/api-output/parseAssertDocumentProperty/extra-5.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + document[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown document property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/null-1.toml b/tests/test-js/api-output/parseAssertDocumentProperty/null-1.toml new file mode 100644 index 00000000..ad54caec --- /dev/null +++ b/tests/test-js/api-output/parseAssertDocumentProperty/null-1.toml @@ -0,0 +1 @@ +error = """Forbidden `ident` used (`undefined`). Allowed idents: [null]""" diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/null-2.toml b/tests/test-js/api-output/parseAssertDocumentProperty/null-2.toml new file mode 100644 index 00000000..f9ed5207 --- /dev/null +++ b/tests/test-js/api-output/parseAssertDocumentProperty/null-2.toml @@ -0,0 +1,28 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + document[prop] + \"`\"); + continue; + } + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (document[parseAssertDictPropKey] === undefined) { + nonMatchingProps.push('Unknown document property `' + parseAssertDictPropKey + '`'); + continue; + } + if (String(document[parseAssertDictPropKey]) != parseAssertDictPropValue) { + nonMatchingProps.push('Expected `' + parseAssertDictPropValue + '` for property `' + parseAssertDictPropKey + '`, found `' + document[parseAssertDictPropKey] + '`'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +checkResult = true diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/null-3.toml b/tests/test-js/api-output/parseAssertDocumentProperty/null-3.toml new file mode 100644 index 00000000..09eda20f --- /dev/null +++ b/tests/test-js/api-output/parseAssertDocumentProperty/null-3.toml @@ -0,0 +1,31 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + document[prop] + \"`\"); + continue; + } + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (document[parseAssertDictPropKey] === undefined) { + nonMatchingProps.push('Unknown document property `' + parseAssertDictPropKey + '`'); + continue; + } + if (!String(document[parseAssertDictPropKey]).endsWith(parseAssertDictPropValue)) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + document[parseAssertDictPropKey] + '`) does not end with `' + parseAssertDictPropValue + '`'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (ENDS_WITH) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/null-4.toml b/tests/test-js/api-output/parseAssertDocumentProperty/null-4.toml new file mode 100644 index 00000000..ae3b1a24 --- /dev/null +++ b/tests/test-js/api-output/parseAssertDocumentProperty/null-4.toml @@ -0,0 +1,36 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + document[prop] + \"`\"); + continue; + } + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (document[parseAssertDictPropKey] === undefined) { + nonMatchingProps.push('Unknown document property `' + parseAssertDictPropKey + '`'); + continue; + } + if (!String(document[parseAssertDictPropKey]).startsWith(parseAssertDictPropValue)) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + document[parseAssertDictPropKey] + '`) does not start with `' + parseAssertDictPropValue + '`'); + } + if (Number.isNaN(document[parseAssertDictPropKey])) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + document[parseAssertDictPropKey] + '`) is NaN (for NEAR check)'); + } else if (Math.abs(document[parseAssertDictPropKey] - parseAssertDictPropValue) > 1) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + document[parseAssertDictPropKey] + '`) is not within 1 of `' + parseAssertDictPropValue + '` (for NEAR check)'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (STARTS_WITH, NEAR) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api-output/parseAssertDocumentProperty/null-5.toml b/tests/test-js/api-output/parseAssertDocumentProperty/null-5.toml new file mode 100644 index 00000000..ad949b96 --- /dev/null +++ b/tests/test-js/api-output/parseAssertDocumentProperty/null-5.toml @@ -0,0 +1,36 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {\"b\":\"12\"}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + document[prop] + \"`\"); + continue; + } + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (document[parseAssertDictPropKey] === undefined) { + nonMatchingProps.push('Unknown document property `' + parseAssertDictPropKey + '`'); + continue; + } + if (!String(document[parseAssertDictPropKey]).startsWith(parseAssertDictPropValue)) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + document[parseAssertDictPropKey] + '`) does not start with `' + parseAssertDictPropValue + '`'); + } + if (Number.isNaN(document[parseAssertDictPropKey])) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + document[parseAssertDictPropKey] + '`) is NaN (for NEAR check)'); + } else if (Math.abs(document[parseAssertDictPropKey] - parseAssertDictPropValue) > 1) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + document[parseAssertDictPropKey] + '`) is not within 1 of `' + parseAssertDictPropValue + '` (for NEAR check)'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (STARTS_WITH, NEAR) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/basic-1.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/basic-1.toml index f0f7c06f..edd7ed31 100644 --- a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/basic-1.toml +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/basic-1.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/basic-2.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/basic-2.toml index f0f7c06f..edd7ed31 100644 --- a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/basic-2.toml +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/basic-2.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-1.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-1.toml index fb07d720..4e4c13f6 100644 --- a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-1.toml +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-1.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-2.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-2.toml index 17714a0d..8bc9f1d2 100644 --- a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-2.toml +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-2.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-3.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-3.toml index 41cd70ee..66e937fd 100644 --- a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-3.toml +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-3.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-4.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-4.toml index 254991aa..bcdc2327 100644 --- a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-4.toml +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-4.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-5.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-5.toml index 55e97233..97b3c6ac 100644 --- a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-5.toml +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/extra-5.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (document[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-1.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-1.toml new file mode 100644 index 00000000..ad54caec --- /dev/null +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-1.toml @@ -0,0 +1 @@ +error = """Forbidden `ident` used (`undefined`). Allowed idents: [null]""" diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-2.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-2.toml new file mode 100644 index 00000000..f89c1bf1 --- /dev/null +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-2.toml @@ -0,0 +1,27 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (document[parseAssertDictPropKey] === undefined) { + continue; + } + if (String(document[parseAssertDictPropKey]) == parseAssertDictPropValue) { + nonMatchingProps.push(\"assert didn't fail for property `\" + parseAssertDictPropKey + '`'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +checkResult = true diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-3.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-3.toml new file mode 100644 index 00000000..820129a5 --- /dev/null +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-3.toml @@ -0,0 +1,30 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (document[parseAssertDictPropKey] === undefined) { + continue; + } + if (String(document[parseAssertDictPropKey]).endsWith(parseAssertDictPropValue)) { + nonMatchingProps.push(\"assert didn't fail for property `\" + parseAssertDictPropKey + '` (for ENDS_WITH check)'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (ENDS_WITH) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-4.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-4.toml new file mode 100644 index 00000000..acc6c8be --- /dev/null +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-4.toml @@ -0,0 +1,35 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (document[parseAssertDictPropKey] === undefined) { + continue; + } + if (String(document[parseAssertDictPropKey]).startsWith(parseAssertDictPropValue)) { + nonMatchingProps.push(\"assert didn't fail for property `\" + parseAssertDictPropKey + '` (for STARTS_WITH check)'); + } + if (Number.isNaN(document[parseAssertDictPropKey])) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + document[parseAssertDictPropKey] + '`) is NaN (for NEAR check)'); + } else if (Math.abs(document[parseAssertDictPropKey] - parseAssertDictPropValue) <= 1) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + document[parseAssertDictPropKey] + '`) is within 1 of `' + parseAssertDictPropValue + '` (for NEAR check)'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (STARTS_WITH, NEAR) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-5.toml b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-5.toml new file mode 100644 index 00000000..cec00004 --- /dev/null +++ b/tests/test-js/api-output/parseAssertDocumentPropertyFalse/null-5.toml @@ -0,0 +1,35 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {\"b\":\"12\"}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (document[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (document[parseAssertDictPropKey] === undefined) { + continue; + } + if (String(document[parseAssertDictPropKey]).startsWith(parseAssertDictPropValue)) { + nonMatchingProps.push(\"assert didn't fail for property `\" + parseAssertDictPropKey + '` (for STARTS_WITH check)'); + } + if (Number.isNaN(document[parseAssertDictPropKey])) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + document[parseAssertDictPropKey] + '`) is NaN (for NEAR check)'); + } else if (Math.abs(document[parseAssertDictPropKey] - parseAssertDictPropValue) <= 1) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + document[parseAssertDictPropKey] + '`) is within 1 of `' + parseAssertDictPropValue + '` (for NEAR check)'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (STARTS_WITH, NEAR) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/basic-1.toml b/tests/test-js/api-output/parseAssertPropertyFalse/basic-1.toml index 4cc7fbd3..188bd594 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/basic-1.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/basic-1.toml @@ -9,7 +9,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/basic-2.toml b/tests/test-js/api-output/parseAssertPropertyFalse/basic-2.toml index f5ffe0f0..5dd1d21b 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/basic-2.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/basic-2.toml @@ -9,7 +9,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/basic-3.toml b/tests/test-js/api-output/parseAssertPropertyFalse/basic-3.toml index da3ae959..1c8936bf 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/basic-3.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/basic-3.toml @@ -10,7 +10,7 @@ for (let i = 0, len = parseAssertElemProp.length; i < len; ++i) { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/extra-1.toml b/tests/test-js/api-output/parseAssertPropertyFalse/extra-1.toml index 32f2f6bb..3f4a4865 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/extra-1.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/extra-1.toml @@ -9,7 +9,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/extra-2.toml b/tests/test-js/api-output/parseAssertPropertyFalse/extra-2.toml index d8ce4003..c74e720a 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/extra-2.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/extra-2.toml @@ -9,7 +9,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/extra-3.toml b/tests/test-js/api-output/parseAssertPropertyFalse/extra-3.toml index a865fca2..5f3e7170 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/extra-3.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/extra-3.toml @@ -9,7 +9,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/multiline-2.toml b/tests/test-js/api-output/parseAssertPropertyFalse/multiline-2.toml index 438b1ac2..bf124629 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/multiline-2.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/multiline-2.toml @@ -10,7 +10,7 @@ for (let i = 0, len = parseAssertElemProp.length; i < len; ++i) { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-1.toml b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-1.toml index f615ddb9..533ddf3a 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-1.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-1.toml @@ -9,7 +9,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-2.toml b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-2.toml index 89edb80f..6e4d16f9 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-2.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-2.toml @@ -10,7 +10,7 @@ for (let i = 0, len = parseAssertElemProp.length; i < len; ++i) { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-3.toml b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-3.toml index ac886f08..dcde292b 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-3.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-3.toml @@ -9,7 +9,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-4.toml b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-4.toml index 1cf6ec4e..9cc51e3a 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-4.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-4.toml @@ -10,7 +10,7 @@ for (let i = 0, len = parseAssertElemProp.length; i < len; ++i) { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-5.toml b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-5.toml index c39f2a63..95da295c 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-5.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-5.toml @@ -9,7 +9,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-6.toml b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-6.toml index 2fe80840..331834b0 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-6.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/pseudo-6.toml @@ -10,7 +10,7 @@ for (let i = 0, len = parseAssertElemProp.length; i < len; ++i) { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/undef-1.toml b/tests/test-js/api-output/parseAssertPropertyFalse/undef-1.toml index e009f8c0..0b653ee9 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/undef-1.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/undef-1.toml @@ -9,7 +9,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/undef-2.toml b/tests/test-js/api-output/parseAssertPropertyFalse/undef-2.toml index 04d60f43..6ef35d77 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/undef-2.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/undef-2.toml @@ -9,7 +9,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/xpath-1.toml b/tests/test-js/api-output/parseAssertPropertyFalse/xpath-1.toml index 4aaad0f5..9a9d0235 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/xpath-1.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/xpath-1.toml @@ -10,7 +10,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/xpath-2.toml b/tests/test-js/api-output/parseAssertPropertyFalse/xpath-2.toml index 220f7152..70a42b2f 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/xpath-2.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/xpath-2.toml @@ -10,7 +10,7 @@ await page.evaluate(e => { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertPropertyFalse/xpath-3.toml b/tests/test-js/api-output/parseAssertPropertyFalse/xpath-3.toml index 438b1ac2..bf124629 100644 --- a/tests/test-js/api-output/parseAssertPropertyFalse/xpath-3.toml +++ b/tests/test-js/api-output/parseAssertPropertyFalse/xpath-3.toml @@ -10,7 +10,7 @@ for (let i = 0, len = parseAssertElemProp.length; i < len; ++i) { if (e[prop] !== undefined) { continue; } - nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); } for (const [parseAssertElemPropKey, parseAssertElemPropValue] of Object.entries(parseAssertElemPropDict)) { if (e[parseAssertElemPropKey] === undefined) { diff --git a/tests/test-js/api-output/parseAssertWindowProperty/basic-1.toml b/tests/test-js/api-output/parseAssertWindowProperty/basic-1.toml index 02ec04e6..761b2567 100644 --- a/tests/test-js/api-output/parseAssertWindowProperty/basic-1.toml +++ b/tests/test-js/api-output/parseAssertWindowProperty/basic-1.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + window[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown window property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertWindowProperty/basic-2.toml b/tests/test-js/api-output/parseAssertWindowProperty/basic-2.toml index 02ec04e6..761b2567 100644 --- a/tests/test-js/api-output/parseAssertWindowProperty/basic-2.toml +++ b/tests/test-js/api-output/parseAssertWindowProperty/basic-2.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + window[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown window property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertWindowProperty/extra-1.toml b/tests/test-js/api-output/parseAssertWindowProperty/extra-1.toml index d1fc9306..27d36407 100644 --- a/tests/test-js/api-output/parseAssertWindowProperty/extra-1.toml +++ b/tests/test-js/api-output/parseAssertWindowProperty/extra-1.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + window[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown window property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertWindowProperty/extra-2.toml b/tests/test-js/api-output/parseAssertWindowProperty/extra-2.toml index 6af13703..d8e1ca92 100644 --- a/tests/test-js/api-output/parseAssertWindowProperty/extra-2.toml +++ b/tests/test-js/api-output/parseAssertWindowProperty/extra-2.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + window[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown window property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertWindowProperty/extra-3.toml b/tests/test-js/api-output/parseAssertWindowProperty/extra-3.toml index e77c1748..f24d7774 100644 --- a/tests/test-js/api-output/parseAssertWindowProperty/extra-3.toml +++ b/tests/test-js/api-output/parseAssertWindowProperty/extra-3.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + window[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown window property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertWindowProperty/extra-4.toml b/tests/test-js/api-output/parseAssertWindowProperty/extra-4.toml index 87c313d6..b637683c 100644 --- a/tests/test-js/api-output/parseAssertWindowProperty/extra-4.toml +++ b/tests/test-js/api-output/parseAssertWindowProperty/extra-4.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + window[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown window property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertWindowProperty/extra-5.toml b/tests/test-js/api-output/parseAssertWindowProperty/extra-5.toml index 1b354985..8de47955 100644 --- a/tests/test-js/api-output/parseAssertWindowProperty/extra-5.toml +++ b/tests/test-js/api-output/parseAssertWindowProperty/extra-5.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + window[prop] + \"`\"); + continue; + } + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { nonMatchingProps.push('Unknown window property `' + parseAssertDictPropKey + '`'); diff --git a/tests/test-js/api-output/parseAssertWindowProperty/null-1.toml b/tests/test-js/api-output/parseAssertWindowProperty/null-1.toml new file mode 100644 index 00000000..ad54caec --- /dev/null +++ b/tests/test-js/api-output/parseAssertWindowProperty/null-1.toml @@ -0,0 +1 @@ +error = """Forbidden `ident` used (`undefined`). Allowed idents: [null]""" diff --git a/tests/test-js/api-output/parseAssertWindowProperty/null-2.toml b/tests/test-js/api-output/parseAssertWindowProperty/null-2.toml new file mode 100644 index 00000000..c960ee9d --- /dev/null +++ b/tests/test-js/api-output/parseAssertWindowProperty/null-2.toml @@ -0,0 +1,28 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + window[prop] + \"`\"); + continue; + } + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (window[parseAssertDictPropKey] === undefined) { + nonMatchingProps.push('Unknown window property `' + parseAssertDictPropKey + '`'); + continue; + } + if (String(window[parseAssertDictPropKey]) != parseAssertDictPropValue) { + nonMatchingProps.push('Expected `' + parseAssertDictPropValue + '` for property `' + parseAssertDictPropKey + '`, found `' + window[parseAssertDictPropKey] + '`'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +checkResult = true diff --git a/tests/test-js/api-output/parseAssertWindowProperty/null-3.toml b/tests/test-js/api-output/parseAssertWindowProperty/null-3.toml new file mode 100644 index 00000000..c58afbfc --- /dev/null +++ b/tests/test-js/api-output/parseAssertWindowProperty/null-3.toml @@ -0,0 +1,31 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + window[prop] + \"`\"); + continue; + } + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (window[parseAssertDictPropKey] === undefined) { + nonMatchingProps.push('Unknown window property `' + parseAssertDictPropKey + '`'); + continue; + } + if (!String(window[parseAssertDictPropKey]).endsWith(parseAssertDictPropValue)) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + window[parseAssertDictPropKey] + '`) does not end with `' + parseAssertDictPropValue + '`'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (ENDS_WITH) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api-output/parseAssertWindowProperty/null-4.toml b/tests/test-js/api-output/parseAssertWindowProperty/null-4.toml new file mode 100644 index 00000000..e1290d06 --- /dev/null +++ b/tests/test-js/api-output/parseAssertWindowProperty/null-4.toml @@ -0,0 +1,36 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + window[prop] + \"`\"); + continue; + } + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (window[parseAssertDictPropKey] === undefined) { + nonMatchingProps.push('Unknown window property `' + parseAssertDictPropKey + '`'); + continue; + } + if (!String(window[parseAssertDictPropKey]).startsWith(parseAssertDictPropValue)) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + window[parseAssertDictPropKey] + '`) does not start with `' + parseAssertDictPropValue + '`'); + } + if (Number.isNaN(window[parseAssertDictPropKey])) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + window[parseAssertDictPropKey] + '`) is NaN (for NEAR check)'); + } else if (Math.abs(window[parseAssertDictPropKey] - parseAssertDictPropValue) > 1) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + window[parseAssertDictPropKey] + '`) is not within 1 of `' + parseAssertDictPropValue + '` (for NEAR check)'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (STARTS_WITH, NEAR) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api-output/parseAssertWindowProperty/null-5.toml b/tests/test-js/api-output/parseAssertWindowProperty/null-5.toml new file mode 100644 index 00000000..e4b2c845 --- /dev/null +++ b/tests/test-js/api-output/parseAssertWindowProperty/null-5.toml @@ -0,0 +1,36 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {\"b\":\"12\"}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + nonMatchingProps.push(\"Expected property `\" + prop + \"` to not exist, found: `\" + window[prop] + \"`\"); + continue; + } + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (window[parseAssertDictPropKey] === undefined) { + nonMatchingProps.push('Unknown window property `' + parseAssertDictPropKey + '`'); + continue; + } + if (!String(window[parseAssertDictPropKey]).startsWith(parseAssertDictPropValue)) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + window[parseAssertDictPropKey] + '`) does not start with `' + parseAssertDictPropValue + '`'); + } + if (Number.isNaN(window[parseAssertDictPropKey])) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + window[parseAssertDictPropKey] + '`) is NaN (for NEAR check)'); + } else if (Math.abs(window[parseAssertDictPropKey] - parseAssertDictPropValue) > 1) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + window[parseAssertDictPropKey] + '`) is not within 1 of `' + parseAssertDictPropValue + '` (for NEAR check)'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (STARTS_WITH, NEAR) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/basic-1.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/basic-1.toml index 422cc0b9..e0df0f1a 100644 --- a/tests/test-js/api-output/parseAssertWindowPropertyFalse/basic-1.toml +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/basic-1.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/basic-2.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/basic-2.toml index 422cc0b9..e0df0f1a 100644 --- a/tests/test-js/api-output/parseAssertWindowPropertyFalse/basic-2.toml +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/basic-2.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-1.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-1.toml index 909060e5..c17c854d 100644 --- a/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-1.toml +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-1.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-2.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-2.toml index b96cd0de..8404f8d1 100644 --- a/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-2.toml +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-2.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-3.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-3.toml index e3d5faa8..46cb7fe7 100644 --- a/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-3.toml +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-3.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-4.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-4.toml index ed27d459..51da3965 100644 --- a/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-4.toml +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-4.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-5.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-5.toml index 80c69c06..80e0c900 100644 --- a/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-5.toml +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/extra-5.toml @@ -2,6 +2,13 @@ instructions = [ """await page.evaluate(() => { const nonMatchingProps = []; const parseAssertDictPropDict = {\"a\":\"b\"}; + const undefProps = []; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { if (window[parseAssertDictPropKey] === undefined) { continue; diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-1.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-1.toml new file mode 100644 index 00000000..ad54caec --- /dev/null +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-1.toml @@ -0,0 +1 @@ +error = """Forbidden `ident` used (`undefined`). Allowed idents: [null]""" diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-2.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-2.toml new file mode 100644 index 00000000..0f0b30f9 --- /dev/null +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-2.toml @@ -0,0 +1,27 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (window[parseAssertDictPropKey] === undefined) { + continue; + } + if (String(window[parseAssertDictPropKey]) == parseAssertDictPropValue) { + nonMatchingProps.push(\"assert didn't fail for property `\" + parseAssertDictPropKey + '`'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +checkResult = true diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-3.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-3.toml new file mode 100644 index 00000000..5b24b0f5 --- /dev/null +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-3.toml @@ -0,0 +1,30 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (window[parseAssertDictPropKey] === undefined) { + continue; + } + if (String(window[parseAssertDictPropKey]).endsWith(parseAssertDictPropValue)) { + nonMatchingProps.push(\"assert didn't fail for property `\" + parseAssertDictPropKey + '` (for ENDS_WITH check)'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (ENDS_WITH) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-4.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-4.toml new file mode 100644 index 00000000..9781eff2 --- /dev/null +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-4.toml @@ -0,0 +1,35 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (window[parseAssertDictPropKey] === undefined) { + continue; + } + if (String(window[parseAssertDictPropKey]).startsWith(parseAssertDictPropValue)) { + nonMatchingProps.push(\"assert didn't fail for property `\" + parseAssertDictPropKey + '` (for STARTS_WITH check)'); + } + if (Number.isNaN(window[parseAssertDictPropKey])) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + window[parseAssertDictPropKey] + '`) is NaN (for NEAR check)'); + } else if (Math.abs(window[parseAssertDictPropKey] - parseAssertDictPropValue) <= 1) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + window[parseAssertDictPropKey] + '`) is within 1 of `' + parseAssertDictPropValue + '` (for NEAR check)'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (STARTS_WITH, NEAR) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-5.toml b/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-5.toml new file mode 100644 index 00000000..d4ac5bdc --- /dev/null +++ b/tests/test-js/api-output/parseAssertWindowPropertyFalse/null-5.toml @@ -0,0 +1,35 @@ +instructions = [ + """await page.evaluate(() => { + const nonMatchingProps = []; + const parseAssertDictPropDict = {\"b\":\"12\"}; + const undefProps = [\"a\"]; + for (const prop of undefProps) { + if (window[prop] !== undefined) { + continue; + } + nonMatchingProps.push(\"Property named `\" + prop + \"` doesn't exist\"); + } + for (const [parseAssertDictPropKey, parseAssertDictPropValue] of Object.entries(parseAssertDictPropDict)) { + if (window[parseAssertDictPropKey] === undefined) { + continue; + } + if (String(window[parseAssertDictPropKey]).startsWith(parseAssertDictPropValue)) { + nonMatchingProps.push(\"assert didn't fail for property `\" + parseAssertDictPropKey + '` (for STARTS_WITH check)'); + } + if (Number.isNaN(window[parseAssertDictPropKey])) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + window[parseAssertDictPropKey] + '`) is NaN (for NEAR check)'); + } else if (Math.abs(window[parseAssertDictPropKey] - parseAssertDictPropValue) <= 1) { + nonMatchingProps.push('Property `' + parseAssertDictPropKey + '` (`' + window[parseAssertDictPropKey] + '`) is within 1 of `' + parseAssertDictPropValue + '` (for NEAR check)'); + } + } + if (nonMatchingProps.length !== 0) { + const props = nonMatchingProps.join(\", \"); + throw \"The following errors happened: [\" + props + \"]\"; + } +});""", +] +wait = false +warnings = [ + """Special checks (STARTS_WITH, NEAR) will be ignored for `null`""", +] +checkResult = true diff --git a/tests/test-js/api.js b/tests/test-js/api.js index 1deeb1ed..888fbb7c 100644 --- a/tests/test-js/api.js +++ b/tests/test-js/api.js @@ -230,6 +230,12 @@ function checkAssertObjProperty(x, func) { func('({"a": "b"}, ENDS_WITH)', 'extra-3'); func('({"a": "b"}, [STARTS_WITH, ENDS_WITH])', 'extra-4'); func('({"a": "b"}, [STARTS_WITH, NEAR])', 'extra-5'); + + func('({"a": undefined})', 'null-1'); + func('({"a": null})', 'null-2'); + func('({"a": null}, ENDS_WITH)', 'null-3'); + func('({"a": null}, [STARTS_WITH, NEAR])', 'null-4'); + func('({"a": null, "b": "12"}, [STARTS_WITH, NEAR])', 'null-5'); } function checkAssertVariable(x, func) { From aa5f2044f86c44dd3d04d8e028093a91681e83ce Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 31 Mar 2023 14:00:50 +0200 Subject: [PATCH 3/4] Add ui tests for `assert-document-property*` and `assert-window-property*` commands --- tests/ui-tests/assert-null.goml | 26 ++++++++++++++++++++++++++ tests/ui-tests/assert-null.output | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/tests/ui-tests/assert-null.goml b/tests/ui-tests/assert-null.goml index 74e05dd5..550e04b1 100644 --- a/tests/ui-tests/assert-null.goml +++ b/tests/ui-tests/assert-null.goml @@ -35,3 +35,29 @@ assert-property: ("header", {"yolo": null}, ALL) assert-property: ("header", {"yolo": null}, CONTAINS) // Should warn. assert-property: ("header", {"yolo": null}, [ALL, CONTAINS]) + +// +// assert-document-property +// +assert-document-property: {"yolo": null} +// Should fail. +assert-document-property: {"bgColor": null} +assert-document-property-false: {"bgColor": null} +// Should fail. +assert-document-property-false: {"yolo": null} + +// Checking the warnings. +assert-document-property: ({"yolo": null}, CONTAINS) + +// +// assert-window-property +// +assert-window-property: {"yolo": null} +// Should fail. +assert-window-property: {"innerHeight": null} +assert-window-property-false: {"innerHeight": null} +// Should fail. +assert-window-property-false: {"yolo": null} + +// Checking the warnings. +assert-window-property: ({"yolo": null}, CONTAINS) diff --git a/tests/ui-tests/assert-null.output b/tests/ui-tests/assert-null.output index bc7a1db4..68904ede 100644 --- a/tests/ui-tests/assert-null.output +++ b/tests/ui-tests/assert-null.output @@ -5,11 +5,17 @@ assert-null... FAILED [WARNING] Special checks (CONTAINS) will be ignored for `null` [WARNING] Special checks (CONTAINS) will be ignored for `null` [WARNING] Special checks (CONTAINS) will be ignored for `null` +[WARNING] Special checks (CONTAINS) will be ignored for `null` +[WARNING] Special checks (CONTAINS) will be ignored for `null` [ERROR] (line 8) Error: Evaluation failed: The following errors happened (for selector `.content`): [Expected `null` for attribute `nb-value`, found: `12`]: for command `assert-attribute: (".content", {"nb-value": null})` [ERROR] (line 11) Error: Evaluation failed: The following errors happened (for selector `header`): [Attribute named `whatever` doesn't exist]: for command `assert-attribute-false: ("header", {"whatever": null})` [ERROR] (line 27) Error: Evaluation failed: The following errors happened (for selector `header`): [Property named `bgColor` doesn't exist]: for command `assert-property-false: ("header", {"bgColor": null})` [ERROR] (line 29) Error: Evaluation failed: The following errors happened (for selector `header`): [Property named `yolo` doesn't exist]: for command `assert-property-false: ("header", {"yolo": null})` +[ERROR] (line 44) Error: Evaluation failed: The following errors happened: [Expected property `bgColor` to not exist, found: ``]: for command `assert-document-property: {"bgColor": null}` +[ERROR] (line 47) Error: Evaluation failed: The following errors happened: [Property named `yolo` doesn't exist]: for command `assert-document-property-false: {"yolo": null}` +[ERROR] (line 57) Error: Evaluation failed: The following errors happened: [Expected property `innerHeight` to not exist, found: `600`]: for command `assert-window-property: {"innerHeight": null}` +[ERROR] (line 60) Error: Evaluation failed: The following errors happened: [Property named `yolo` doesn't exist]: for command `assert-window-property-false: {"yolo": null}` <= doc-ui tests done: 0 succeeded, 1 failed \ No newline at end of file From f32d1f9c0569eb3ff2979833b17ce89919683d12 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 31 Mar 2023 14:04:40 +0200 Subject: [PATCH 4/4] Update documentation for `null` attribute for `assert-document-property*` and `assert-window-property*` commands --- goml-script.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/goml-script.md b/goml-script.md index 655b293a..775fe8a8 100644 --- a/goml-script.md +++ b/goml-script.md @@ -335,6 +335,13 @@ assert-document-property: ({"URL": "https://some.where", "title": "a title"}) assert-document-property: {"URL": "https://some.where", "title": "a title"} ``` +If you want to check that a property doesn't exist, you can use `null`: + +``` +// Checking that "property-name" doesn't exist. +assert-document-property: {"property-name": null} +``` + You can use more specific checks as well by using one of the following identifiers: "CONTAINS", "ENDS_WITH", "STARTS_WITH", or "NEAR". ``` @@ -357,6 +364,13 @@ assert-document-property-false: ({"URL": "https://some.where", "title": "a title assert-document-property-false: {"URL": "https://some.where", "title": "a title"} ``` +If you want to check that a property does exist, you can use `null`: + +``` +// Checking that "property-name" does exist. +assert-document-property-false: {"property-name": null} +``` + You can use more specific checks as well by using one of the following identifiers: "CONTAINS", "ENDS_WITH", "STARTS_WITH" or "NEAR". @@ -625,6 +639,13 @@ assert-window-property: ({"pageYOffset": "0", "location": "https://some.where"}) assert-window-property: {"pageYOffset": "0", "location": "https://some.where"} ``` +If you want to check that a property doesn't exist, you can use `null`: + +``` +// Checking that "property-name" doesn't exist. +assert-window-property-false: {"property-name": null} +``` + You can use more specific checks as well by using one of the following identifiers: "CONTAINS", "ENDS_WITH", "STARTS_WITH", or "NEAR". ``` @@ -653,6 +674,13 @@ assert-window-property-false: ({"location": "https://some.where", "pageYOffset": assert-window-property-false: {"location": "https://some.where", "pageYOffset": "10"} ``` +If you want to check that a property does exist, you can use `null`: + +``` +// Checking that "property-name" does exist. +assert-window-property-false: {"property-name": null} +``` + You can use more specific checks as well by using one of the following identifiers: "CONTAINS", "ENDS_WITH", "STARTS_WITH" or "NEAR". ```