xvfb.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict';
  2. var _templateObject = _taggedTemplateLiteral(['\n DISPLAY environment variable is set to ', ' on Linux\n Assuming this DISPLAY points at working X11 server,\n Cypress will not spawn own Xvfb\n\n NOTE: if the X11 server is NOT working, Cypress will exit without explanation,\n see ', '\n Solution: Unset the DISPLAY variable and try again:\n DISPLAY= npx cypress run ...\n '], ['\n DISPLAY environment variable is set to ', ' on Linux\n Assuming this DISPLAY points at working X11 server,\n Cypress will not spawn own Xvfb\n\n NOTE: if the X11 server is NOT working, Cypress will exit without explanation,\n see ', '\n Solution: Unset the DISPLAY variable and try again:\n DISPLAY= npx cypress run ...\n ']);
  3. function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
  4. var os = require('os');
  5. var Promise = require('bluebird');
  6. var Xvfb = require('@cypress/xvfb');
  7. var _require = require('common-tags'),
  8. stripIndent = _require.stripIndent;
  9. var debug = require('debug')('cypress:cli');
  10. var debugXvfb = require('debug')('cypress:xvfb');
  11. var _require2 = require('../errors'),
  12. throwFormErrorText = _require2.throwFormErrorText,
  13. errors = _require2.errors;
  14. var util = require('../util');
  15. var xvfb = Promise.promisifyAll(new Xvfb({
  16. timeout: 30000, // milliseconds
  17. onStderrData: function onStderrData(data) {
  18. if (debugXvfb.enabled) {
  19. debugXvfb(data.toString());
  20. }
  21. }
  22. }));
  23. module.exports = {
  24. _debugXvfb: debugXvfb, // expose for testing
  25. _xvfb: xvfb, // expose for testing
  26. start: function start() {
  27. debug('Starting Xvfb');
  28. return xvfb.startAsync().return(null).catch({ nonZeroExitCode: true }, throwFormErrorText(errors.nonZeroExitCodeXvfb)).catch(function (err) {
  29. if (err.known) {
  30. throw err;
  31. }
  32. return throwFormErrorText(errors.missingXvfb)(err);
  33. });
  34. },
  35. stop: function stop() {
  36. debug('Stopping Xvfb');
  37. return xvfb.stopAsync().return(null).catch(function () {
  38. // noop
  39. });
  40. },
  41. isNeeded: function isNeeded() {
  42. if (os.platform() !== 'linux') {
  43. return false;
  44. }
  45. if (process.env.DISPLAY) {
  46. var issueUrl = util.getGitHubIssueUrl(4034);
  47. var message = stripIndent(_templateObject, process.env.DISPLAY, issueUrl);
  48. debug(message);
  49. return false;
  50. }
  51. debug('undefined DISPLAY environment variable');
  52. debug('Cypress will spawn its own Xvfb');
  53. return true;
  54. },
  55. // async method, resolved with Boolean
  56. verify: function verify() {
  57. return xvfb.startAsync().return(true).catch(function (err) {
  58. debug('Could not verify xvfb: %s', err.message);
  59. return false;
  60. }).finally(xvfb.stopAsync);
  61. }
  62. };