cypress.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. // https://github.com/cypress-io/cypress/issues/316
  3. var Promise = require('bluebird');
  4. var tmp = Promise.promisifyAll(require('tmp'));
  5. var fs = require('./fs');
  6. var _open = require('./exec/open');
  7. var _run = require('./exec/run');
  8. var util = require('./util');
  9. var cypressModuleApi = {
  10. open: function open() {
  11. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  12. options = util.normalizeModuleOptions(options);
  13. return _open.start(options);
  14. },
  15. run: function run() {
  16. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17. options = util.normalizeModuleOptions(options);
  18. return tmp.fileAsync().then(function (outputPath) {
  19. options.outputPath = outputPath;
  20. return _run.start(options).then(function (failedTests) {
  21. return fs.readJsonAsync(outputPath, { throws: false }).then(function (output) {
  22. if (!output) {
  23. return {
  24. failures: failedTests,
  25. message: 'Could not find Cypress test run results'
  26. };
  27. }
  28. return output;
  29. });
  30. });
  31. });
  32. }
  33. };
  34. module.exports = cypressModuleApi;