chain-prompt-spec.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. var assert = require('assert');
  2. //Gulp uses vinyl source streams
  3. var source = require('vinyl-source-stream');
  4. var proxyrequire = require('proxyquire');
  5. /**
  6. * The following test spec will verify the operation of the chain prompt function
  7. */
  8. describe('gulp chain prompt unit tests', function () {
  9. describe('verify that chain prompt function operates correctly', function () {
  10. it('verify that chain prompt does not convert questions to array if already an array', function ( ){
  11. var prompt = function ( questions ){
  12. return new Promise( (resolve,reject) => {
  13. resolve('completed prompt');
  14. });
  15. };
  16. //Mock inquirer to capture response
  17. gulpPrompt = proxyrequire('../index.js', {'inquirer':{ prompt: prompt}});
  18. let srcStream = source('../README.md');
  19. let resp = srcStream.pipe( gulpPrompt.prompt( ['options string'] ) );
  20. resp.write('../test.txt');
  21. });
  22. it('verify that chain function gets called correctly', function ( ){
  23. var prompt = function ( questions ){
  24. return new Promise( (resolve,reject) => {
  25. resolve('completed prompt');
  26. });
  27. };
  28. var chainFunction = function ( opts, resp ){
  29. console.log('Chain Function called');
  30. console.log( 'Response', resp);
  31. assert.equal( opts, options );
  32. };
  33. let index = 0;
  34. let questions = {
  35. type: 'confirm',
  36. name: 'val',
  37. message: 'Test Message?',
  38. default: true,
  39. chainFunction: chainFunction
  40. };
  41. //Mock inquirer to capture response
  42. gulpPrompt = proxyrequire('../index.js', {'inquirer':{ prompt: prompt}});
  43. let srcStream = source('../README.md');
  44. let resp = srcStream.pipe( gulpPrompt.prompt( questions ) );
  45. resp.write('../test.txt');
  46. });
  47. });
  48. });