0.2.6 • Published 4 years ago

titanium-karma-client v0.2.6

Weekly downloads
128
License
Apache-2.0
Repository
github
Last release
4 years ago

Karma client for Titanium

Greenkeeper badge

Axway Titanium version of the Karma client

Installation

npm i titanium-karma-client -S

Usage

:bulb: If you just want to run unit tests consider using the karma-titanium-launcher wich makes use of this package and does all the required setup for you to test your projects.

This client connects to a Karma server, loads all required files including the testing framework and individual unit tests, executes the tests and then reports the results back to the Karma server. This client is heavily inspired by the default Karma Web client that is used for Browser testing and was adapted to work inside Titanium.

You create a client by instantiating KarmaClient, passing it the URL it should connect to. After that you do the actual connect and can optionally bind a few events to listen for status changes.

import KarmaClient from 'titanium-karma-client';
const client = new KarmaClient({ url: 'http://localhost:9876/?id=123456' });
client.connect();
client.on('execute', () => console.log('Loading files ...'));
client.on('result', e => console.log(`Running tests (${e.completed} / ${e.total})`));
client.on('complete', e => {
	let resultMessage = `Executed ${e.total - e.skipped} / ${e.total}`;
	if (e.failed) {
		resultMessage += ` (${e.failed} FAILED)`;
	}
	resultMessage += ' - DONE';
	console.log(resultMessage);
});

Public API

new KarmaClient(options)

Creates a new KarmaClient instance and sets the passed options. The options object can contain the following settings:

NameTypeRequiredDescription
urlSringYesThe base url of the Karma server to connect to. If the URL contains an id query parameter the client will register to the Karma server using this identifer. If the parameter is missing the client generates a random identifier to connect with.
singleRunBooleanNoDisconnect the client from the Karma server after a single run. Used in consuction with the Karma config of the same name. Defaults to false.

KarmaClient.connect()

Connects to the Karma server and starts the test run.

KarmaClient.disconnect()

Disconnects the client from the Karma server.

Event API

KarmaClient implements the Node event emitter API. Refer to https://nodejs.org/api/events.html for a full API documention.

Events

You can listen to a set of events to respond to certain status changes using the on method. Available events are:

  • execute Emitted when the Karma server sends the execute message. This will cause the client to start loading all required files for the test run from the Karma server.
  • result This event will be emitted when the client reports a test result back to Karma. The event will include information about the current number of completed tests as well as the total number of tests being executed.
    • completed <Number> The number of completed tests
    • total <Number> The number of total tests in this test run
  • complete Emitted when the test run is complete. Includes information about skipped and failed tests and the total number of tests executed.
    • skipped <Number> Number of skipped tests
    • failed <Number> Number of failed tests
    • total <Number> Total tests executed during this run

Contributions

Open source contributions are greatly appreciated! If you have a bugfix, improvement or new feature, please create an issue first and submit a pull request against master.

Getting Help

If you have questions about unit testing your Titanium apps or libraries with Karma, feel free to reach out on Stackoverflow or the #helpme channel on TiSlack. In case you find a bug related to this library, create a new issue or open a new JIRA ticket.

License

Apache License, Version 2.0

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago