{"id":14384265,"url":"https://github.com/apache/cordova-plugin-test-framework","last_synced_at":"2025-04-06T16:11:21.060Z","repository":{"id":830476,"uuid":"21642555","full_name":"apache/cordova-plugin-test-framework","owner":"apache","description":"Apache Cordova","archived":false,"fork":false,"pushed_at":"2024-08-16T01:39:09.000Z","size":2975,"stargazers_count":75,"open_issues_count":9,"forks_count":34,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-03T04:16:52.630Z","etag":null,"topics":["cordova","cplusplus","csharp","java","javascript","library","mobile","nodejs","objective-c"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apache.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-07-09T07:00:07.000Z","updated_at":"2024-08-16T01:38:24.000Z","dependencies_parsed_at":"2025-03-16T01:15:17.056Z","dependency_job_id":null,"html_url":"https://github.com/apache/cordova-plugin-test-framework","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcordova-plugin-test-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcordova-plugin-test-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcordova-plugin-test-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcordova-plugin-test-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apache","download_url":"https://codeload.github.com/apache/cordova-plugin-test-framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247509221,"owners_count":20950232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cordova","cplusplus","csharp","java","javascript","library","mobile","nodejs","objective-c"],"created_at":"2024-08-28T18:01:15.668Z","updated_at":"2025-04-06T16:11:21.044Z","avatar_url":"https://github.com/apache.png","language":"HTML","readme":"\u003c!--\n#\n# Licensed to the Apache Software Foundation (ASF) under one\n# or more contributor license agreements.  See the NOTICE file\n# distributed with this work for additional information\n# regarding copyright ownership.  The ASF licenses this file\n# to you under the Apache License, Version 2.0 (the\n# \"License\"); you may not use this file except in compliance\n# with the License.  You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing,\n# software distributed under the License is distributed on an\n# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n#  KIND, either express or implied.  See the License for the\n# specific language governing permissions and limitations\n# under the License.\n#\n--\u003e\n\n[![Node CI](https://github.com/apache/cordova-plugin-test-framework/workflows/Node%20CI/badge.svg?branch=master)](https://github.com/apache/cordova-plugin-test-framework/actions?query=branch%3Amaster)\n[![GitHub version](https://badge.fury.io/gh/apache%2Fcordova-plugin-test-framework.svg)](https://github.com/apache/cordova-plugin-test-framework/releases)\n[![npm version](https://badge.fury.io/js/cordova-plugin-test-framework.svg)](https://www.npmjs.com/package/cordova-plugin-test-framework) \n\n# Cordova Plugin Test Framework\n\nThe `cordova-plugin-test-framework` plugin allows plugin authors to add tests (manual and automated) to their plugins. To achieve this it\n\n1. [defines the interface for Cordova plugins to write tests](#interface) and \n2. [provides a test harness for actually running those tests](#harness)\n\nTests run directly inside existing Cordova projects, so you can rapidly switch between testing and development. You can also be sure that your test suite is testing the exact versions of plugins and platforms that your app is using.\n\n# TLDR; Try it\n\n1. Use your existing Cordova app, or create a new one.\n2. Plugins bundle their tests using a nested plugin in a `/tests` directory. Here are a few examples how install both:\n\n\t```shell\n\tcordova plugin add cordova-plugin-device\n\tcordova plugin add plugins/cordova-plugin-device/tests\n\n\tcordova plugin add cordova-plugin-device-motion\n\tcordova plugin add plugins/cordova-plugin-device-motion/tests\n\n\tcordova plugin add cordova-plugin-geolocation\n\tcordova plugin add plugins/cordova-plugin-geolocation/tests\n\t```\n\t\n\tTo install the plugin from `master` on GitHub instead of npm, replace e.g. `cordova-plugin-device` with `https://github.com/apache/cordova-plugin-device.git`\n\n3. Follow the docs for [Setting up the test harness](#harness).\n\n\n\u003ca name=\"interface\" /\u003e\n\n## Writing Plugin Tests\n\n### Where do tests live?\n\nAdd a directory named `tests` to the root of your plugin. Within this directory, create a nested `plugin.xml` for the tests plugin. It should have a plugin id with the form `pluginid-tests` (e.g. the `cordova-plugin-device` plugin has the nested id `cordova-plugin-device-tests`) and should contain a `\u003cjs-module\u003e` named `tests`. E.g:\n\n```\n\u003cjs-module src=\"tests/tests.js\" name=\"tests\"\u003e\n\u003c/js-module\u003e\n```\n\nFor example, the `cordova-plugin-device` plugin has this nested [`plugin.xml`](https://github.com/apache/cordova-plugin-device/blob/master/tests/plugin.xml).\n\nCreate a `package.json` inside your project's `tests/` folder. Plugins require a `package.json` now and tests are considered their own plugins. The latest version of the tools ensure to run `npm install` on any plugin added to a project and pull in any dependencies. Therefore, plugin authors can now put npm dependencies around their tests into the `package.json` file.\n\nFor example, the `cordova-plugin-device` plugin contains a [`package.json`](https://github.com/apache/cordova-plugin-device/blob/master/tests/package.json).\n\nThe `cordova-plugin-test-framework` plugin will automatically find all `tests` modules across all plugins for which the nested tests plugin is installed.\n\n### Defining Auto Tests\n\nExport a function named `defineAutoTests`, which defines your auto-tests when run. Use the [`jasmine-2.9`](https://jasmine.github.io/2.9/introduction.html) format. E.g.:\n\n```\nexports.defineAutoTests = function() {\n\n  describe('awesome tests', function() {\n    it('do something sync', function() {\n      expect(1).toBe(1);\n      ...\n    });\n\n    it('do something async using callbacks', function(done) {\n      setTimeout(function() {\n        expect(1).toBe(1);\n        ...\n        done();\n      }, 100);\n    });\n\n    it(\"do something async using promises\", function() {\n      return soon().then(function() {\n        value++;\n        expect(value).toBeGreaterThan(0);\n      });\n    });\n\n    it(\"do something async using async/await\", async function() {\n      await soon();\n      value++;\n      expect(value).toBeGreaterThan(0);\n    });\n  });\n\n  describe('more awesome tests', function() {\n    ...\n  });\n\n};\n```\n\nNote: Your tests will automatically be labeled with your plugin id, so do not prefix your test descriptions.\n\n\n### Defining Manual Tests\n\nExport a function named `defineManualTests`, which defines your manual-tests when run. Manual tests do *not* any test runner, and success/failure results are not officially reported in any standard way. Instead, create buttons to run arbitrary javascript when clicked, and display output to user using `console` or by manipulating a provided DOM element. E.g.:\n\n```\nexports.defineManualTests = function(contentEl, createActionButton) {\n\n  createActionButton('Simple Test', function() {\n    console.log(JSON.stringify(foo, null, '\\t'));\n  });\n\n  createActionButton('Complex Test', function() {\n    contentEl.innerHTML = ...;\n  });\n\n};\n```\n\nMake sure to document the expected outcome. \n\nNote: Your tests will automatically be labeled with your plugin id, so do not prefix your test descriptions.\n\n\n\u003ca name=\"example\"\u003e\n\n### Example\n\nSee: [`cordova-plugin-device` tests](https://github.com/apache/cordova-plugin-device/blob/master/tests/tests.js).\n\n\u003ca name=\"harness\" /\u003e\n\n## Running Plugin Tests\n\n1. Use your existing Cordova app, or create a new one.\n2. Add this plugin:\n\n\t```\n\tcordova plugin add cordova-plugin-test-framework\n\t// or\n\tcordova plugin add https://github.com/apache/cordova-plugin-test-framework.git\n\t```\n\n3. Change the start page in `config.xml` with `\u003ccontent src=\"cdvtests/index.html\" /\u003e` or add a link to `cdvtests/index.html` from within your app.\n4. Thats it!\n\n\n## FAQ\n\n* Q: Should I add `cordova-plugin-test-framework` as a `\u003cdependency\u003e` of my plugin?\n  * A: No. The end-user should decide if they want to install the test framework, not your plugin (most users won't).\n\n* Q: What do I do if my plugin tests must have very large assets?\n  * A: Don't bundle those assets with your plugin. If you can, have your tests fail gracefully if those assets don't don't exist (perhaps log a warning, perhaps fail a single asset-checking test, and skip the rest). Then, ideally download those assets automatically into local storage the first time tests run. Or create a manual test step to download and install assets. As a final alternative, split those test assets into a separate plugin, and instruct users to install that plugin to run your full test suite.\n\n* Q: Should I ship my app with the test framework plugin installed?\n  * A: Not likely. If you want, you can. Then your app could even embed a link to the test page (`cdvtests/index.html`) from a help section of your app, to give end users a way to run your test suite out in the feild. That may help diagnose causes of issues within your app. Maybe.\n","funding_links":[],"categories":["HTML"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fcordova-plugin-test-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapache%2Fcordova-plugin-test-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fcordova-plugin-test-framework/lists"}