Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Test plugin that verifies platform and version #178

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/ParamedicApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class ParamedicApp {
additionalPlugins.push(path.join(__dirname, '..', 'ci-plugin'));
}

additionalPlugins.push(path.join(__dirname, '..', 'spec/platform-verification-plugin'));
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);
}

Expand Down
14 changes: 11 additions & 3 deletions lib/paramedic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -370,15 +370,23 @@ class ParamedicRunner {
isTestPassed = result;
})
.then(() => this.runAppiumTests(true))
.then(isAppiumTestPassed => isTestPassed === utilities.TEST_PASSED && isAppiumTestPassed === utilities.TEST_PASSED);
.then(isAppiumTestPassed => {
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 {
return this.runLocalTests()
.then((result) => {
isTestPassed = result;
})
.then(() => this.runAppiumTests())
.then(isAppiumTestPassed => isTestPassed === utilities.TEST_PASSED && isAppiumTestPassed === utilities.TEST_PASSED);
.then(isAppiumTestPassed => {
var result = isTestPassed === utilities.TEST_PASSED && isAppiumTestPassed === utilities.TEST_PASSED;
logger.normal(`cordova-paramedic results (local): isTestPassed = ${isTestPassed}, isAppiumTestPassed = ${isAppiumTestPassed}: result = ${result}`);
return result;
});
}
}

Expand Down
14 changes: 14 additions & 0 deletions spec/platform-verification-plugin/package.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
26 changes: 26 additions & 0 deletions spec/platform-verification-plugin/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="platform-verification-plugin"
version="0.0.1">
<name>Platform Verification Plugin</name>
</plugin>
14 changes: 14 additions & 0 deletions spec/platform-verification-plugin/tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"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",
"dependencies": {
"parse-json": "^4.0.0"
}
}
36 changes: 36 additions & 0 deletions spec/platform-verification-plugin/tests/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="platform-verification-plugin-tests"
version="0.0.1">
<name>Platform Verification Plugin Tests</name>

<js-module src="tests.js" name="tests">
</js-module>

<dependency id="cordova-plugin-device" />

<preference name="PLATFORM" />
<preference name="VERSION" />
<preference name="MODEL" />
<hook type="after_plugin_add" src="scripts/replacePlatformVersionInTestsJs.js" />
</plugin>
Original file line number Diff line number Diff line change
@@ -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);
};
42 changes: 42 additions & 0 deletions spec/platform-verification-plugin/tests/tests.js
Original file line number Diff line number Diff line change
@@ -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: window.device', function () {

it('.platform should be correct', function () {
expect(window.device.platform.toLowerCase()).toEqual('foo');
});

it('.version should be correct', function () {
expect(window.device.version).toContain('1.2');
});

it('.model should be correct', function () {
expect(window.device.model.toLowerCase()).toEqual('bar');
});

});
};

exports.defineManualTests = function () {};