From 4b15ee7f7ce32ca12303aac5381fac4e12cbec03 Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Sat, 29 Jun 2019 22:10:53 +0200 Subject: [PATCH 1/9] initial version of platform-verification-plugin (not dynamic, fails all) --- .../platform-verification-plugin/package.json | 14 +++++++ spec/platform-verification-plugin/plugin.xml | 26 ++++++++++++ .../tests/package.json | 11 +++++ .../tests/plugin.xml | 29 +++++++++++++ .../tests/tests.js | 42 +++++++++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 spec/platform-verification-plugin/package.json create mode 100644 spec/platform-verification-plugin/plugin.xml create mode 100644 spec/platform-verification-plugin/tests/package.json create mode 100644 spec/platform-verification-plugin/tests/plugin.xml create mode 100644 spec/platform-verification-plugin/tests/tests.js diff --git a/spec/platform-verification-plugin/package.json b/spec/platform-verification-plugin/package.json new file mode 100644 index 00000000..9f666aff --- /dev/null +++ b/spec/platform-verification-plugin/package.json @@ -0,0 +1,14 @@ +{ + "name": "platform-verification-plugin", + "version": "1.0.0", + "description": "", + "main": "index.js", + "directories": { + "test": "tests" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "" +} diff --git a/spec/platform-verification-plugin/plugin.xml b/spec/platform-verification-plugin/plugin.xml new file mode 100644 index 00000000..549ad0a7 --- /dev/null +++ b/spec/platform-verification-plugin/plugin.xml @@ -0,0 +1,26 @@ + + + + + Platform Verification Plugin + diff --git a/spec/platform-verification-plugin/tests/package.json b/spec/platform-verification-plugin/tests/package.json new file mode 100644 index 00000000..b290ec1c --- /dev/null +++ b/spec/platform-verification-plugin/tests/package.json @@ -0,0 +1,11 @@ +{ + "name": "platform-verification-plugin-tests", + "version": "1.0.0", + "description": "", + "main": "tests.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "Apache-2.0" +} diff --git a/spec/platform-verification-plugin/tests/plugin.xml b/spec/platform-verification-plugin/tests/plugin.xml new file mode 100644 index 00000000..c894eb57 --- /dev/null +++ b/spec/platform-verification-plugin/tests/plugin.xml @@ -0,0 +1,29 @@ + + + + + Cordova Testable Plugin Tests + + + + diff --git a/spec/platform-verification-plugin/tests/tests.js b/spec/platform-verification-plugin/tests/tests.js new file mode 100644 index 00000000..f5793331 --- /dev/null +++ b/spec/platform-verification-plugin/tests/tests.js @@ -0,0 +1,42 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +/* eslint-env jasmine */ + +exports.defineAutoTests = function () { + describe('Platform-Verification: windows.device', function () { + + it('.platform should be correct', function () { + expect(window.device.platform).toEqual('foo'); + }); + + it('.version should be correct', function () { + expect(window.device.version).toEqual('1.2.3'); + }); + + it('.model should be correct', function () { + expect(window.device.model).toEqual('bar'); + }); + + }); +}; + +exports.defineManualTests = function () {}; From 7261dac406639fa1acbafca601b536ba3dda84cd Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Sat, 29 Jun 2019 22:15:56 +0200 Subject: [PATCH 2/9] install plugin and its tests by default --- lib/ParamedicApp.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ParamedicApp.js b/lib/ParamedicApp.js index 887bb420..e8717d78 100644 --- a/lib/ParamedicApp.js +++ b/lib/ParamedicApp.js @@ -86,6 +86,9 @@ class ParamedicApp { additionalPlugins.push(path.join(__dirname, '..', 'ci-plugin')); } + additionalPlugins.push(path.join(__dirname, '..', 'spec/platform-verification-plugin')); + additionalPlugins.push(path.join(__dirname, '..', 'spec/platform-verification-plugin/tests')); + pluginsManager.installPlugins(additionalPlugins); } From d532dfe78fa209135235998a97650ca25b8ed88c Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Sat, 29 Jun 2019 22:49:23 +0200 Subject: [PATCH 3/9] log results --- lib/paramedic.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/paramedic.js b/lib/paramedic.js index 677ccbb9..4632f3c5 100644 --- a/lib/paramedic.js +++ b/lib/paramedic.js @@ -370,7 +370,10 @@ class ParamedicRunner { isTestPassed = result; }) .then(() => this.runAppiumTests(true)) - .then(isAppiumTestPassed => isTestPassed === utilities.TEST_PASSED && isAppiumTestPassed === utilities.TEST_PASSED); + .then(isAppiumTestPassed => { + logger.normal(`cordova-paramedic results (SauceLabs): isTestPassed = ${isTestPassed}, isAppiumTestPassed = ${isAppiumTestPassed}`); + return isTestPassed === utilities.TEST_PASSED && isAppiumTestPassed === utilities.TEST_PASSED; + }); // Not Sauce Labs } else { return this.runLocalTests() @@ -378,7 +381,10 @@ class ParamedicRunner { isTestPassed = result; }) .then(() => this.runAppiumTests()) - .then(isAppiumTestPassed => isTestPassed === utilities.TEST_PASSED && isAppiumTestPassed === utilities.TEST_PASSED); + .then(isAppiumTestPassed => { + logger.normal(`cordova-paramedic results (local): isTestPassed = ${isTestPassed}, isAppiumTestPassed = ${isAppiumTestPassed}`); + return isTestPassed === utilities.TEST_PASSED && isAppiumTestPassed === utilities.TEST_PASSED; + }); } } From 5e3ebed762205ed9180b1cf04f8f909ac58cc6a2 Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Sat, 29 Jun 2019 23:06:09 +0200 Subject: [PATCH 4/9] more debug --- lib/paramedic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paramedic.js b/lib/paramedic.js index 4632f3c5..f2f63786 100644 --- a/lib/paramedic.js +++ b/lib/paramedic.js @@ -104,7 +104,7 @@ class ParamedicRunner { logger.warn('---------------------------------------------------------'); isTestPassed = result; - logger.normal('Completed tests at ' + (new Date()).toLocaleTimeString()); + logger.normal('Completed tests at ' + (new Date()).toLocaleTimeString() + ' with result: ' + isTestPassed); // If we run --shouldUseSauce immedatly fetch and return Sauce details. if (this.config.shouldUseSauce()) { From b263365c1c45b1489f46571c93cfc6b16ae6e858 Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Sun, 30 Jun 2019 01:07:17 +0200 Subject: [PATCH 5/9] add preferences to plugin add hook better expect comparisons fix plugin name and id supply values as varaibles during install of plugin --- lib/ParamedicApp.js | 6 +++- .../tests/package.json | 5 ++- .../tests/plugin.xml | 11 ++++-- .../replacePlatformVersionInTestsJs.js | 35 +++++++++++++++++++ .../tests/tests.js | 4 +-- 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 spec/platform-verification-plugin/tests/scripts/replacePlatformVersionInTestsJs.js diff --git a/lib/ParamedicApp.js b/lib/ParamedicApp.js index e8717d78..8083bdee 100644 --- a/lib/ParamedicApp.js +++ b/lib/ParamedicApp.js @@ -87,7 +87,11 @@ class ParamedicApp { } additionalPlugins.push(path.join(__dirname, '..', 'spec/platform-verification-plugin')); - additionalPlugins.push(path.join(__dirname, '..', 'spec/platform-verification-plugin/tests')); + var config = this.config.getAll(); + var platform = config.platform; + var version = config.saucePlatformVersion; + var model = config.sauceDeviceName; + additionalPlugins.push(path.join(__dirname, '..', 'spec/platform-verification-plugin/tests --variable PLATFORM=' + platform + ' --variable VERSION=' + version + ' --variable MODEL=' + model)); pluginsManager.installPlugins(additionalPlugins); } diff --git a/spec/platform-verification-plugin/tests/package.json b/spec/platform-verification-plugin/tests/package.json index b290ec1c..d1a30b0c 100644 --- a/spec/platform-verification-plugin/tests/package.json +++ b/spec/platform-verification-plugin/tests/package.json @@ -7,5 +7,8 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", - "license": "Apache-2.0" + "license": "Apache-2.0", + "dependencies": { + "parse-json": "^4.0.0" + } } diff --git a/spec/platform-verification-plugin/tests/plugin.xml b/spec/platform-verification-plugin/tests/plugin.xml index c894eb57..2550be39 100644 --- a/spec/platform-verification-plugin/tests/plugin.xml +++ b/spec/platform-verification-plugin/tests/plugin.xml @@ -20,10 +20,17 @@ - Cordova Testable Plugin Tests + Platform Verification Plugin Tests + + + + + + + diff --git a/spec/platform-verification-plugin/tests/scripts/replacePlatformVersionInTestsJs.js b/spec/platform-verification-plugin/tests/scripts/replacePlatformVersionInTestsJs.js new file mode 100644 index 00000000..6ba5c21c --- /dev/null +++ b/spec/platform-verification-plugin/tests/scripts/replacePlatformVersionInTestsJs.js @@ -0,0 +1,35 @@ +const fs = require('fs'); +const parseJson = require('parse-json'); +const path = require('path'); + +module.exports = async function (ctx) { + const filePath = path.resolve(ctx.opts.projectRoot, 'plugins', 'fetch.json'); + const json = parseJson(fs.readFileSync(filePath, { encoding: 'utf-8' })); + + var platform = json['platform-verification-plugin-tests'].variables.PLATFORM; + var version = json['platform-verification-plugin-tests'].variables.VERSION; + var model = json['platform-verification-plugin-tests'].variables.MODEL; + + const filePath2 = path.resolve(ctx.opts.plugin.dir, 'tests.js'); + var testsJs = fs.readFileSync(filePath2, { encoding: 'utf-8' }); + + // replace comparison values in test + testsJs = testsJs.replace('foo', platform); + testsJs = testsJs.replace('1.2', version); + testsJs = testsJs.replace('bar', model); + + // disable tests where we have no useful comparison value + if (platform === 'undefined') { + testsJs = testsJs.replace("it('.platform", "xit('.platform"); + } + if (version === 'undefined') { + testsJs = testsJs.replace("it('.version", "xit('.version"); + } + if (model === 'undefined') { + testsJs = testsJs.replace("it('.model", "xit('.model"); + } + + fs.writeFileSync(filePath2, testsJs); + + console.log('hook: updated `platform` and `version` in `tests.json`: ', platform, version, model); +}; diff --git a/spec/platform-verification-plugin/tests/tests.js b/spec/platform-verification-plugin/tests/tests.js index f5793331..cf46bac1 100644 --- a/spec/platform-verification-plugin/tests/tests.js +++ b/spec/platform-verification-plugin/tests/tests.js @@ -25,11 +25,11 @@ exports.defineAutoTests = function () { describe('Platform-Verification: windows.device', function () { it('.platform should be correct', function () { - expect(window.device.platform).toEqual('foo'); + expect(window.device.platform.toLowerCase()).toEqual('foo'); }); it('.version should be correct', function () { - expect(window.device.version).toEqual('1.2.3'); + expect(window.device.version).toContain('1.2'); }); it('.model should be correct', function () { From 1cd14cbea9962b52961291f3eaa56f7a6513d6fc Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Sun, 30 Jun 2019 01:16:06 +0200 Subject: [PATCH 6/9] fix model comparison --- spec/platform-verification-plugin/tests/tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/platform-verification-plugin/tests/tests.js b/spec/platform-verification-plugin/tests/tests.js index cf46bac1..9d98c274 100644 --- a/spec/platform-verification-plugin/tests/tests.js +++ b/spec/platform-verification-plugin/tests/tests.js @@ -33,7 +33,7 @@ exports.defineAutoTests = function () { }); it('.model should be correct', function () { - expect(window.device.model).toEqual('bar'); + expect(window.device.model.toLowerCase()).toEqual('bar'); }); }); From 579c04bd528abead12c4fcfee843a7fa36cf62d0 Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Sun, 30 Jun 2019 01:18:36 +0200 Subject: [PATCH 7/9] quote the variable values --- lib/ParamedicApp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ParamedicApp.js b/lib/ParamedicApp.js index 8083bdee..ad8c365a 100644 --- a/lib/ParamedicApp.js +++ b/lib/ParamedicApp.js @@ -91,7 +91,7 @@ class ParamedicApp { var platform = config.platform; var version = config.saucePlatformVersion; var model = config.sauceDeviceName; - additionalPlugins.push(path.join(__dirname, '..', 'spec/platform-verification-plugin/tests --variable PLATFORM=' + platform + ' --variable VERSION=' + version + ' --variable MODEL=' + model)); + additionalPlugins.push(path.join(__dirname, '..', 'spec/platform-verification-plugin/tests --variable PLATFORM="' + platform + '" --variable VERSION="' + version + '" --variable MODEL="' + model + '"')); pluginsManager.installPlugins(additionalPlugins); } From f420f5a641564ea96a93fa39fb2cbd0ec54605d5 Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Tue, 2 Jul 2019 10:06:51 +0200 Subject: [PATCH 8/9] output combined test result for debugging --- lib/paramedic.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/paramedic.js b/lib/paramedic.js index f2f63786..0beeb7de 100644 --- a/lib/paramedic.js +++ b/lib/paramedic.js @@ -371,8 +371,9 @@ class ParamedicRunner { }) .then(() => this.runAppiumTests(true)) .then(isAppiumTestPassed => { - logger.normal(`cordova-paramedic results (SauceLabs): isTestPassed = ${isTestPassed}, isAppiumTestPassed = ${isAppiumTestPassed}`); - return isTestPassed === utilities.TEST_PASSED && isAppiumTestPassed === utilities.TEST_PASSED; + var result = isTestPassed === utilities.TEST_PASSED && isAppiumTestPassed === utilities.TEST_PASSED; + logger.normal(`cordova-paramedic results (SauceLabs): isTestPassed = ${isTestPassed}, isAppiumTestPassed = ${isAppiumTestPassed}: result = ${result}`); + return result; }); // Not Sauce Labs } else { @@ -382,8 +383,9 @@ class ParamedicRunner { }) .then(() => this.runAppiumTests()) .then(isAppiumTestPassed => { - logger.normal(`cordova-paramedic results (local): isTestPassed = ${isTestPassed}, isAppiumTestPassed = ${isAppiumTestPassed}`); - return isTestPassed === utilities.TEST_PASSED && isAppiumTestPassed === utilities.TEST_PASSED; + var result = isTestPassed === utilities.TEST_PASSED && isAppiumTestPassed === utilities.TEST_PASSED; + logger.normal(`cordova-paramedic results (local): isTestPassed = ${isTestPassed}, isAppiumTestPassed = ${isAppiumTestPassed}: result = ${result}`); + return result; }); } } From 17416f86db8ea1b6de1b0e1909fb65faa82e47f1 Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Wed, 3 Jul 2019 12:21:26 +0200 Subject: [PATCH 9/9] fix: typo --- spec/platform-verification-plugin/tests/tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/platform-verification-plugin/tests/tests.js b/spec/platform-verification-plugin/tests/tests.js index 9d98c274..5176088c 100644 --- a/spec/platform-verification-plugin/tests/tests.js +++ b/spec/platform-verification-plugin/tests/tests.js @@ -22,7 +22,7 @@ /* eslint-env jasmine */ exports.defineAutoTests = function () { - describe('Platform-Verification: windows.device', function () { + describe('Platform-Verification: window.device', function () { it('.platform should be correct', function () { expect(window.device.platform.toLowerCase()).toEqual('foo');