Cordova Plugin Test Framework

1.1.6 · abandoned · verified Sun Apr 19

The `cordova-plugin-test-framework` provides a structured approach for Cordova plugin developers to create and run tests directly within their Cordova projects. It establishes an interface where plugins can bundle their tests as nested plugins within a `/tests` directory, using a `plugin.xml` and `package.json` for definition and dependency management. The framework then offers a test harness to execute these tests, utilizing the Jasmine 2.0 format for defining test suites (`describe`, `it`). This allows for rapid iteration between development and testing, ensuring tests run against the exact versions of plugins and platforms in use. The latest published version is 1.1.6. However, the project appears to be largely unmaintained, with its last significant activity on npm and GitHub over seven years ago, suggesting an effectively abandoned status. It differentiates itself by integrating tests directly into the Cordova build lifecycle, rather than relying on external, separate test runners.

Common errors

Warnings

Install

Imports

Quickstart

This code snippet demonstrates how to define automated tests for a Cordova plugin using the `cordova-plugin-test-framework` and Jasmine 2.0 syntax.

/* In your plugin's 'tests/tests.js' file */

exports.defineAutoTests = function() {
  describe('Cordova Test Framework Basic Tests', function() {
    beforeEach(function() {
      // Optional: Setup code before each test
      console.log('Running test setup...');
    });

    it('should confirm window.cordova exists', function() {
      expect(window.cordova).toBeDefined();
      expect(typeof window.cordova).toBe('object');
    });

    it('should allow adding other plugins for testing', function() {
      // Example for a hypothetical device plugin
      // In a real scenario, cordova-plugin-device-tests would be added
      if (window.cordova && window.cordova.plugins && window.cordova.plugins.device) {
        expect(window.cordova.plugins.device).toBeDefined();
        expect(typeof window.cordova.plugins.device.platform).toBe('string');
      } else {
        pending('cordova-plugin-device is not available for testing.');
      }
    });

    // You can also define manual tests
    // exports.defineManualTests = function() { /* ... */ };
  });

  // To run this, you would add your plugin's tests as a sub-plugin:
  // cordova plugin add https://github.com/apache/cordova-plugin-device.git#:/tests
  // Then add the test framework:
  // cordova plugin add cordova-plugin-test-framework
  // Finally, set your config.xml to load the test harness:
  // <content src="cdvtests/index.html" />
};

view raw JSON →