Code coverage report for preceptor-reporter/lib/listener/preceptor.js

Statements: 100% (16 / 16)      Branches: 100% (4 / 4)      Functions: 100% (2 / 2)      Lines: 100% (16 / 16)      Ignored: none     

All files » preceptor-reporter/lib/listener/ » preceptor.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80      1             1                   1                                                 1         1   45   45 44 44     44   44   43 43   43         1       1        
// Copyright 2014, Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.
 
var AbstractListener = require('../abstractListener');
 
/**
 * @class PreceptorListener
 * @extends AbstractListener
 * @constructor
 */
var PreceptorListener = AbstractListener.extend(
 
	{
		/**
		 * Gets a list of relayed messages
		 *
		 * @method getRelayedMessages
		 * @return {string[]}
		 */
		getRelayedMessages: function () {
			return [
				'itemData',
				'itemMessage',
				'suiteStart',
				'suiteEnd',
				'testStart',
				'testFailed',
				'testUndefined',
				'testError',
				'testPassed',
				'testSkipped',
				'testIncomplete'
			];
		},
 
		/**
		 * Parses a string and extracts message information
		 *
		 * @method parse
		 * @param {string} text
		 * @param {object} [placeholder]
		 * @return {string}
		 */
		parse: function (text, placeholder) {
 
			var messageType, data,
				messageTypes = this.getRelayedMessages(),
				match = true,
				localText = text;
 
			while(match) {
 
				match = localText.match(/^#\|#\s(\w*?)\s(.*?)\s#\|#$/m);
 
				if (match) {
					messageType = match[1];
					data = match[2];
 
					// Remove data from stream
					localText = localText.replace(match[0] + "\n", "");
 
					if (messageTypes.indexOf(messageType) != -1) {
 
						data = this.processPlaceholder(data, placeholder);
						data = JSON.parse(data);
 
						this.triggerMessage(messageType, data);
					}
				}
			}
 
			return localText;
		}
	});
 
module.exports = PreceptorListener;