index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. const Coffee = require('./lib/coffee');
  3. const is = require('is-type-of');
  4. const Rule = require('./lib/rule');
  5. exports.Coffee = Coffee;
  6. exports.Rule = Rule;
  7. /**
  8. * fork a child process to test
  9. * @param {String} modulePath - The module to run in the child
  10. * @param {Array} args - List of string arguments
  11. * @param {Object} opt - fork options
  12. * @see https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options
  13. * @return {Coffee} coffee instance
  14. */
  15. exports.fork = function(modulePath, args, opt) {
  16. // fork('/path/to/cli', { execArgv: [] })
  17. if (!opt && !is.array(args)) {
  18. opt = args;
  19. args = undefined;
  20. }
  21. return new Coffee({
  22. method: 'fork',
  23. cmd: modulePath,
  24. args,
  25. opt,
  26. });
  27. };
  28. /**
  29. * spawn a child process to test
  30. * @param {String} cmd - The command to run
  31. * @param {Array} args - List of string arguments
  32. * @param {Object} opt - spawn options
  33. * @return {Coffee} coffee instance
  34. */
  35. exports.spawn = function(cmd, args, opt) {
  36. // spawn('/path/to/cli', { execArgv: [] })
  37. if (!opt && !is.array(args)) {
  38. opt = args;
  39. args = undefined;
  40. }
  41. return new Coffee({
  42. method: 'spawn',
  43. cmd,
  44. args,
  45. opt,
  46. });
  47. };