prompt-spec.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 prompt function
  7. */
  8. describe('gulp prompt unit tests', function () {
  9. describe('verify that prompt function operates correctly', function () {
  10. //Test is failing. not converting to string
  11. /*it('verify that prompt converts questions to array', function( done ){
  12. var prompt = function( questions ){
  13. return new Promise( (resolve,reject) => {
  14. console.log( 'q', questions);
  15. if( ( Array.isArray( questions) ) && (questions.length > 0 ) ){
  16. assert.equals(questions[0], 'options string');
  17. done();
  18. }else{
  19. done('questions is not an array');
  20. }
  21. resolve('Test Completed');
  22. });
  23. }
  24. //Mock inquirer to capture response
  25. gulpPrompt = proxyrequire('../index.js', {'inquirer':{ prompt: prompt}});
  26. let srcStream = source('../README.md');
  27. var func = function(){}
  28. let resp = srcStream.pipe( gulpPrompt.prompt( 'options string', func ) );
  29. resp.write('../test.txt');
  30. });*/
  31. it('verify that prompt does not convert questions to array if already an array', function ( done ){
  32. var prompt = function ( questions ){
  33. return new Promise( (resolve,reject) => {
  34. if( Array.isArray( questions) && questions.length > 0 ){
  35. done();
  36. }else{
  37. done('questions is not an array');
  38. }
  39. resolve('Test Completed');
  40. });
  41. };
  42. //Mock inquirer to capture response
  43. gulpPrompt = proxyrequire('../index.js', {'inquirer':{ prompt: prompt}});
  44. let srcStream = source('../README.md');
  45. var func = function (){};
  46. let resp = srcStream.pipe( gulpPrompt.prompt( ['options string'], func ) );
  47. resp.write('../test.txt');
  48. });
  49. });
  50. });