From f44c05ba6fc0af4f439fdac0c5e4bb7491773373 Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Mon, 11 Dec 2023 15:13:42 +0100 Subject: [PATCH 1/3] feat: use type=module in nightwatch projects nightwatch v3.3.4 fixed https://github.com/nightwatchjs/nightwatch/issues/3959 I removed the custom assertions and commands, as they don't work out-of-the-box, they are not used in the generated tests, and they bring little value compared to the official nightwatch documentation --- playground | 2 +- ...nightwatch.conf.js => nightwatch.conf.cjs} | 4 +- .../custom-assertions/elementHasCount.js | 45 ------------------- .../custom-assertions/elementHasCount.ts | 43 ------------------ .../nightwatch/custom-commands/strictClick.js | 19 -------- .../nightwatch/custom-commands/strictClick.ts | 18 -------- template/config/nightwatch/package.json | 1 - 7 files changed, 3 insertions(+), 129 deletions(-) rename template/config/nightwatch/{nightwatch.conf.js => nightwatch.conf.cjs} (97%) delete mode 100644 template/config/nightwatch/nightwatch/custom-assertions/elementHasCount.js delete mode 100644 template/config/nightwatch/nightwatch/custom-assertions/elementHasCount.ts delete mode 100644 template/config/nightwatch/nightwatch/custom-commands/strictClick.js delete mode 100644 template/config/nightwatch/nightwatch/custom-commands/strictClick.ts diff --git a/playground b/playground index fae0d6ad..371a1995 160000 --- a/playground +++ b/playground @@ -1 +1 @@ -Subproject commit fae0d6adddbdc8790cf09ae65631628c4f34e8da +Subproject commit 371a1995e07a71328c3163917479a9e30d9ba1a4 diff --git a/template/config/nightwatch/nightwatch.conf.js b/template/config/nightwatch/nightwatch.conf.cjs similarity index 97% rename from template/config/nightwatch/nightwatch.conf.js rename to template/config/nightwatch/nightwatch.conf.cjs index 05889c61..542647e5 100644 --- a/template/config/nightwatch/nightwatch.conf.js +++ b/template/config/nightwatch/nightwatch.conf.cjs @@ -21,10 +21,10 @@ module.exports = { page_objects_path: [], // See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-commands.html - custom_commands_path: ['nightwatch/custom-commands'], + custom_commands_path: [], // See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-assertions.html - custom_assertions_path: ['nightwatch/custom-assertions'], + custom_assertions_path: [], // See https://nightwatchjs.org/guide/extending-nightwatch/adding-plugins.html plugins: ['@nightwatch/vue'], diff --git a/template/config/nightwatch/nightwatch/custom-assertions/elementHasCount.js b/template/config/nightwatch/nightwatch/custom-assertions/elementHasCount.js deleted file mode 100644 index 1ac2aa2c..00000000 --- a/template/config/nightwatch/nightwatch/custom-assertions/elementHasCount.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * A custom Nightwatch assertion. The assertion name is the filename. - * - * Example usage: - * browser.assert.elementHasCount(selector, count) - * - * For more information on custom assertions see: - * https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-assertions.html - * - * @param {string} selector - * @param {number} count - */ - -exports.assertion = function elementHasCount(selector, count) { - // Message to be displayed on the console while running this assertion. - this.message = `Testing if element <${selector}> has count: ${count}` - - // Expected value of the assertion, to be displayed in case of failure. - this.expected = count - - // Given the result value (from `this.value` below), this function will - // evaluate if the assertion has passed. - this.evaluate = function (value) { - return value === count - } - - // Retrieve the value from the result object we got after running the - // assertion command (defined below), which is to be evaluated against - // the value passed into the assertion as the second argument. - this.value = function (result) { - return result.value - } - - // Script to be executed in the browser to find the actual element count. - function elementCountScript(_selector) { - // eslint-disable-next-line - return document.querySelectorAll(_selector).length - } - - // The command to be executed by the assertion runner, to find the actual - // result. Nightwatch API is available as `this.api`. - this.command = function (callback) { - this.api.execute(elementCountScript, [selector], callback) - } -} diff --git a/template/config/nightwatch/nightwatch/custom-assertions/elementHasCount.ts b/template/config/nightwatch/nightwatch/custom-assertions/elementHasCount.ts deleted file mode 100644 index 13577288..00000000 --- a/template/config/nightwatch/nightwatch/custom-assertions/elementHasCount.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** - * A custom Nightwatch assertion. The assertion name is the filename. - * - * Example usage: - * browser.assert.elementHasCount(selector, count) - * - * For more information on custom assertions see: - * https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-assertions.html - * - */ - -exports.assertion = function elementHasCount(selector: string, count: number) { - // Message to be displayed on the console while running this assertion. - this.message = `Testing if element <${selector}> has count: ${count}` - - // Expected value of the assertion, to be displayed in case of failure. - this.expected = count - - // Given the result value (from `this.value` below), this function will - // evaluate if the assertion has passed. - this.evaluate = function (value: any) { - return value === count - } - - // Retrieve the value from the result object we got after running the - // assertion command (defined below), which is to be evaluated against - // the value passed into the assertion as the second argument. - this.value = function (result: Record) { - return result.value - } - - // Script to be executed in the browser to find the actual element count. - function elementCountScript(_selector: string) { - // eslint-disable-next-line - return document.querySelectorAll(_selector).length - } - - // The command to be executed by the assertion runner, to find the actual - // result. Nightwatch API is available as `this.api`. - this.command = function (callback: () => void) { - this.api.execute(elementCountScript, [selector], callback) - } -} diff --git a/template/config/nightwatch/nightwatch/custom-commands/strictClick.js b/template/config/nightwatch/nightwatch/custom-commands/strictClick.js deleted file mode 100644 index f342044d..00000000 --- a/template/config/nightwatch/nightwatch/custom-commands/strictClick.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * A non-class-based custom-command in Nightwatch. The command name is the filename. - * - * Usage: - * browser.strictClick(selector) - * - * This command is not used yet used in any of the examples. - * - * For more information on working with custom-commands see: - * https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-commands.html - * - * @param {string} selector - */ - -module.exports = { - command: function (selector) { - return this.waitForElementVisible(selector).click(selector) - } -} diff --git a/template/config/nightwatch/nightwatch/custom-commands/strictClick.ts b/template/config/nightwatch/nightwatch/custom-commands/strictClick.ts deleted file mode 100644 index 37b49209..00000000 --- a/template/config/nightwatch/nightwatch/custom-commands/strictClick.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * A non-class-based custom-command in Nightwatch. The command name is the filename. - * - * Usage: - * browser.strictClick(selector) - * - * This command is not used yet used in any of the examples. - * - * For more information on working with custom-commands see: - * https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-commands.html - * - */ - -module.exports = { - command: function (selector: string) { - return this.waitForElementVisible(selector).click(selector) - } -} diff --git a/template/config/nightwatch/package.json b/template/config/nightwatch/package.json index 62828e38..ce5fa758 100644 --- a/template/config/nightwatch/package.json +++ b/template/config/nightwatch/package.json @@ -1,5 +1,4 @@ { - "type": "commonjs", "scripts": { "test:e2e": "nightwatch tests/e2e/*" }, From 12802b386ba94b52edf06159c2c1e7efacfa6758 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 13 Dec 2023 15:27:42 +0800 Subject: [PATCH 2/3] chore: revert submodule to the previous release It only needs to be updated when a new release is made. --- playground | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground b/playground index 371a1995..fae0d6ad 160000 --- a/playground +++ b/playground @@ -1 +1 @@ -Subproject commit 371a1995e07a71328c3163917479a9e30d9ba1a4 +Subproject commit fae0d6adddbdc8790cf09ae65631628c4f34e8da From 0df87715398f63249c1423d0fdaf654c31102003 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 13 Dec 2023 16:07:25 +0800 Subject: [PATCH 3/3] chore: comment out custom commands and assertions types --- template/config/nightwatch/nightwatch/nightwatch.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/template/config/nightwatch/nightwatch/nightwatch.d.ts b/template/config/nightwatch/nightwatch/nightwatch.d.ts index ea1f6066..616e63f9 100644 --- a/template/config/nightwatch/nightwatch/nightwatch.d.ts +++ b/template/config/nightwatch/nightwatch/nightwatch.d.ts @@ -2,10 +2,12 @@ import { NightwatchCustomAssertions, NightwatchCustomCommands } from 'nightwatch declare module 'nightwatch' { interface NightwatchCustomAssertions { - elementHasCount: (selector: string, count: number) => NightwatchBrowser + // Add your custom assertions' types here + // elementHasCount: (selector: string, count: number) => NightwatchBrowser } interface NightwatchCustomCommands { - strictClick: (selector: string) => NightwatchBrowser + // Add your custom commands' types here + // strictClick: (selector: string) => NightwatchBrowser } }