npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-test-framework

v1.1.6

Published

Cordova Test Framework Plugin

Downloads

2,161

Readme

Build Status

Cordova Plugin Test Framework

The cordova-plugin-test-framework plugin does two things:

  1. Defines the interface for cordova plugins to write tests
  2. Provides a test harness for actually running those tests

Tests 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.

TLDR; Try it

  1. Use your existing cordova app, or create a new one.

  2. Plugins bundle their tests using a nested plugin in a /tests directory. To make this interesting, add some of these plugins and their respective tests. Here are a few examples:

     cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
     cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git#:/tests
    	
     cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion.git
     cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion.git#:/tests
    	
     cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
     cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation#:/tests
  3. Follow the docs for Setting up the test harness.

Writing Plugin Tests

Where do tests live?

Add 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 plugin-id-tests (e.g. the cordova-plugin-device plugin has the nested id cordova-plugin-device-tests) and should contain a <js-module> named tests. E.g:

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

For example, the cordova-plugin-device plugin has this nested plugin.xml.

Create 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.

For example,the cordova-plugin-device plugin contains a package.json.

The cordova-plugin-test-framework plugin will automatically find all tests modules across all plugins for which the nested tests plugin is installed.

Defining Auto Tests

Simply export a function named defineAutoTests, which (gasp!) defines your auto-tests when run. Use the jasmine-2.0 format. E.g.:

exports.defineAutoTests = function() {

  describe('awesome tests', function() {
    it('do something sync', function() {
      expect(1).toBe(1);
      ...
    });

    it('do something async', function(done) {
      setTimeout(function() {
        expect(1).toBe(1);
        ...
        done();
      }, 100);
    });
  });

  describe('more awesome tests', function() {
    ...
  });

};

Note: Your tests will automatically be labeled with your plugin id, so do not prefix your test descriptions.

Defining Manual Tests

Simply export a function named defineManualTests, which (gasp!) defines your manual-tests when run. Manual tests do not use jasmine-2.0, 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.:

exports.defineManualTests = function(contentEl, createActionButton) {

  createActionButton('Simple Test', function() {
    console.log(JSON.stringify(foo, null, '\t'));
  });

  createActionButton('Complex Test', function() {
    contentEl.innerHTML = ...;
  });

};

Note: Your tests will automatically be labeled with your plugin id, so do not prefix your test descriptions.

Example

See: cordova-plugin-device tests.

Running Plugin Tests

  1. Use your existing cordova app, or create a new one.

  2. Add this plugin:

     cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework.git
  3. Change the start page in config.xml with <content src="cdvtests/index.html" /> or navigate to cdvtests/index.html from within your app.

  4. Thats it!

FAQ

  • Q: Should I add cordova-plugin-test-framework as a <dependency> of my plugin?

    • A: No. The end-user should decide if they want to install the test framework, not your plugin (most users won't).
  • Q: What do I do if my plugin tests must have very large assets?

    • 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.
  • Q: Should I ship my app with the test framework plugin installed?

    • 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.