spec: convert desktop capturer to expect
This commit is contained in:
parent
a0d252870c
commit
2c2e8317de
1 changed files with 29 additions and 20 deletions
|
@ -1,7 +1,11 @@
|
||||||
const assert = require('assert')
|
const chai = require('chai')
|
||||||
|
const dirtyChai = require('dirty-chai')
|
||||||
const {desktopCapturer, remote, screen} = require('electron')
|
const {desktopCapturer, remote, screen} = require('electron')
|
||||||
const features = process.atomBinding('features')
|
const features = process.atomBinding('features')
|
||||||
|
|
||||||
|
const {expect} = chai
|
||||||
|
chai.use(dirtyChai)
|
||||||
|
|
||||||
const isCI = remote.getGlobal('isCi')
|
const isCI = remote.getGlobal('isCi')
|
||||||
|
|
||||||
describe('desktopCapturer', () => {
|
describe('desktopCapturer', () => {
|
||||||
|
@ -17,19 +21,19 @@ describe('desktopCapturer', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return a non-empty array of sources', (done) => {
|
it('should return a non-empty array of sources', done => {
|
||||||
desktopCapturer.getSources({
|
desktopCapturer.getSources({
|
||||||
types: ['window', 'screen']
|
types: ['window', 'screen']
|
||||||
}, (error, sources) => {
|
}, (error, sources) => {
|
||||||
assert.equal(error, null)
|
expect(error).to.be.null()
|
||||||
assert.notEqual(sources.length, 0)
|
expect(sources.length).to.not.equal(0)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws an error for invalid options', (done) => {
|
it('throws an error for invalid options', done => {
|
||||||
desktopCapturer.getSources(['window', 'screen'], (error) => {
|
desktopCapturer.getSources(['window', 'screen'], error => {
|
||||||
assert.equal(error.message, 'Invalid options')
|
expect(error.message).to.equal('Invalid options')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -38,8 +42,8 @@ describe('desktopCapturer', () => {
|
||||||
let callCount = 0
|
let callCount = 0
|
||||||
const callback = (error, sources) => {
|
const callback = (error, sources) => {
|
||||||
callCount++
|
callCount++
|
||||||
assert.equal(error, null)
|
expect(error).to.be.null()
|
||||||
assert.notEqual(sources.length, 0)
|
expect(sources.length).to.not.equal(0)
|
||||||
if (callCount === 2) done()
|
if (callCount === 2) done()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,11 +51,11 @@ describe('desktopCapturer', () => {
|
||||||
desktopCapturer.getSources({types: ['window', 'screen']}, callback)
|
desktopCapturer.getSources({types: ['window', 'screen']}, callback)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('responds to subsequent calls of different options', (done) => {
|
it('responds to subsequent calls of different options', done => {
|
||||||
let callCount = 0
|
let callCount = 0
|
||||||
const callback = (error, sources) => {
|
const callback = (error, sources) => {
|
||||||
callCount++
|
callCount++
|
||||||
assert.equal(error, null)
|
expect(error).to.be.null()
|
||||||
if (callCount === 2) done()
|
if (callCount === 2) done()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,30 +63,35 @@ describe('desktopCapturer', () => {
|
||||||
desktopCapturer.getSources({types: ['screen']}, callback)
|
desktopCapturer.getSources({types: ['screen']}, callback)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns an empty display_id for window sources on Windows and Mac', (done) => {
|
it('returns an empty display_id for window sources on Windows and Mac', done => {
|
||||||
// Linux doesn't return any window sources.
|
// Linux doesn't return any window sources.
|
||||||
if (process.platform !== 'win32' && process.platform !== 'darwin') {
|
if (process.platform !== 'win32' && process.platform !== 'darwin') {
|
||||||
return done()
|
return done()
|
||||||
}
|
}
|
||||||
|
|
||||||
desktopCapturer.getSources({types: ['window']}, (error, sources) => {
|
desktopCapturer.getSources({types: ['window']}, (error, sources) => {
|
||||||
assert.equal(error, null)
|
expect(error).to.be.null()
|
||||||
assert.notEqual(sources.length, 0)
|
expect(sources.length).to.not.equal(0)
|
||||||
sources.forEach((source) => { assert.equal(source.display_id.length, 0) })
|
sources.forEach((source) => {
|
||||||
|
expect(source.display_id.length).to.equal(0)
|
||||||
|
})
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns display_ids matching the Screen API on Windows and Mac', (done) => {
|
it('returns display_ids matching the Screen API on Windows and Mac', done => {
|
||||||
if (process.platform !== 'win32' && process.platform !== 'darwin') {
|
if (process.platform !== 'win32' && process.platform !== 'darwin') {
|
||||||
return done()
|
return done()
|
||||||
}
|
}
|
||||||
|
|
||||||
const displays = screen.getAllDisplays()
|
const displays = screen.getAllDisplays()
|
||||||
desktopCapturer.getSources({types: ['screen']}, (error, sources) => {
|
desktopCapturer.getSources({types: ['screen']}, (error, sources) => {
|
||||||
assert.equal(error, null)
|
expect(error).to.be.null()
|
||||||
assert.notEqual(sources.length, 0)
|
expect(sources.length).to.not.equal(0)
|
||||||
assert.equal(sources.length, displays.length)
|
expect(sources.length).to.equal(displays.length)
|
||||||
|
|
||||||
for (let i = 0; i < sources.length; i++) {
|
for (let i = 0; i < sources.length; i++) {
|
||||||
assert.equal(sources[i].display_id, displays[i].id)
|
expect(sources[i].display_id).to.equal(displays[i].id.toString())
|
||||||
}
|
}
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue