api-desktop-capturer-spec.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const assert = require('assert')
  2. const {desktopCapturer, remote} = require('electron')
  3. const isCI = remote.getGlobal('isCi')
  4. describe('desktopCapturer', () => {
  5. before(function () {
  6. if (isCI && process.platform === 'win32') {
  7. this.skip()
  8. }
  9. })
  10. it('should return a non-empty array of sources', (done) => {
  11. desktopCapturer.getSources({
  12. types: ['window', 'screen']
  13. }, (error, sources) => {
  14. assert.equal(error, null)
  15. assert.notEqual(sources.length, 0)
  16. done()
  17. })
  18. })
  19. it('throws an error for invalid options', (done) => {
  20. desktopCapturer.getSources(['window', 'screen'], (error) => {
  21. assert.equal(error.message, 'Invalid options')
  22. done()
  23. })
  24. })
  25. it('does not throw an error when called more than once (regression)', (done) => {
  26. let callCount = 0
  27. const callback = (error, sources) => {
  28. callCount++
  29. assert.equal(error, null)
  30. assert.notEqual(sources.length, 0)
  31. if (callCount === 2) done()
  32. }
  33. desktopCapturer.getSources({types: ['window', 'screen']}, callback)
  34. desktopCapturer.getSources({types: ['window', 'screen']}, callback)
  35. })
  36. it('responds to subsequest calls of different options', (done) => {
  37. let callCount = 0
  38. const callback = (error, sources) => {
  39. callCount++
  40. assert.equal(error, null)
  41. if (callCount === 2) done()
  42. }
  43. desktopCapturer.getSources({types: ['window']}, callback)
  44. desktopCapturer.getSources({types: ['screen']}, callback)
  45. })
  46. })