API Docs for: 0.9.3
Show:

File: lib/task/cucumber.js

  1. // Copyright 2014, Yahoo! Inc.
  2. // Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.
  3.  
  4. var AbstractForkTask = require('../abstractForkTask');
  5. var path = require('path');
  6. var utils = require('preceptor-core').utils;
  7. var _ = require('underscore');
  8.  
  9. /**
  10. * @class CucumberTask
  11. * @extends AbstractForkTask
  12. * @constructor
  13. */
  14. var CucumberTask = AbstractForkTask.extend(
  15.  
  16. {
  17. /**
  18. * Initializes the instance
  19. *
  20. * @method initialize
  21. */
  22. initialize: function () {
  23. this.setCucumberConfiguration(utils.deepExtend({}, [
  24. {
  25. path: null,
  26. tags: [],
  27. require: [],
  28. functions: [],
  29. format: 'progress',
  30. coffeeScript: false
  31. },
  32. this.getCucumberConfiguration()
  33. ]));
  34.  
  35. this.__super();
  36. },
  37.  
  38.  
  39. /**
  40. * Validates the given data
  41. *
  42. * @method validate
  43. */
  44. validate: function () {
  45. this.__super();
  46.  
  47. if (!_.isString(this.getPath())) {
  48. throw new Error('The "path" parameter is not a string.');
  49. }
  50. if (!_.isArray(this.getTags())) {
  51. throw new Error('The "tags" parameter is not an array of strings.');
  52. }
  53. if (!_.isArray(this.getRequires())) {
  54. throw new Error('The "require" parameter is not an array of strings.');
  55. }
  56. if (!_.isArray(this.getFunctions())) {
  57. throw new Error('The "functions" parameter is not an array of functions.');
  58. }
  59. if (!_.isBoolean(this.shouldOutputCoffeeScript())) {
  60. throw new Error('The "coffeeScript" parameter is not a boolean.');
  61. }
  62. if (!_.isString(this.getFormat())) {
  63. throw new Error('The "format" parameter is not a string.');
  64. }
  65. },
  66.  
  67.  
  68. /**
  69. * Gets the cucumber configuration
  70. * Overwrite this function if the cucumber configuration is found somewhere else.
  71. *
  72. * @method getCucumberConfiguration
  73. * @return {object}
  74. */
  75. getCucumberConfiguration: function () {
  76. return this.getConfiguration();
  77. },
  78.  
  79. /**
  80. * Sets the cucumber configuration
  81. * Overwrite this function if the cucumber configuration is found somewhere else.
  82. *
  83. * @method setCucumberConfiguration
  84. * @param {object} options
  85. */
  86. setCucumberConfiguration: function (options) {
  87. this.getOptions().configuration = options;
  88. },
  89.  
  90.  
  91. /**
  92. * Gets the path to the text files
  93. * Cucumber Option: <Last parameter>
  94. *
  95. * @method getPath
  96. * @return {string}
  97. */
  98. getPath: function () {
  99. return this.getCucumberConfiguration().path;
  100. },
  101.  
  102. /**
  103. * Gets the tags to include/exclude
  104. * Cucumber Option: tags
  105. *
  106. * @method getTags
  107. * @return {string[]}
  108. */
  109. getTags: function () {
  110. return this.getCucumberConfiguration().tags;
  111. },
  112.  
  113. /**
  114. * Gets the required file before running the tests
  115. * Cucumber Option: require
  116. *
  117. * @method getRequires
  118. * @return {string[]}
  119. */
  120. getRequires: function () {
  121. return this.getCucumberConfiguration().require;
  122. },
  123.  
  124. /**
  125. * Gets the functions to execute as part of files to execute
  126. * Cucumber Option: <does not exist>
  127. *
  128. * @method getFunctions
  129. * @return {function[]}
  130. */
  131. getFunctions: function () {
  132. return this.getCucumberConfiguration().functions;
  133. },
  134.  
  135. /**
  136. * Should output in coffee-script?
  137. * Cucumber Option: coffee
  138. *
  139. * @method shouldOutputCoffeeScript
  140. * @return {boolean}
  141. */
  142. shouldOutputCoffeeScript: function () {
  143. return this.getCucumberConfiguration().coffeeScript;
  144. },
  145.  
  146. /**
  147. * Gets the output format for cucumber
  148. * Cucumber Option: format
  149. *
  150. * @method getFunctions
  151. * @return {string}
  152. */
  153. getFormat: function () {
  154. return this.getCucumberConfiguration().format;
  155. },
  156.  
  157.  
  158. /**
  159. * Run the client
  160. *
  161. * @method _run
  162. * @param {string} parentId
  163. * @return {Promise}
  164. * @private
  165. */
  166. _run: function (parentId) {
  167. return this.runClient(parentId, path.join(__dirname, 'client', 'cucumber'));
  168. }
  169. });
  170.  
  171. module.exports = CucumberTask;
  172.