|
5 | 5 | * that can be found in the LICENSE file in the root of the source |
6 | 6 | * tree. |
7 | 7 | */ |
8 | | -/* eslint-env node */ |
9 | | -const chai = require('chai'); |
10 | | -const expect = chai.expect; |
11 | | -const sinon = require('sinon'); |
12 | | -const sinonChai = require('sinon-chai'); |
13 | | -chai.use(sinonChai); |
14 | 8 |
|
15 | 9 | /* a mock of the Chrome RTCLegacyStatReport */ |
16 | 10 | function RTCLegacyStatsReport() { |
@@ -41,7 +35,7 @@ describe('Chrome shim', () => { |
41 | 35 | window = { |
42 | 36 | navigator: { |
43 | 37 | mediaDevices: { |
44 | | - getUserMedia: sinon.stub().returns(Promise.resolve('stream')), |
| 38 | + getUserMedia: jest.fn().mockReturnValue(Promise.resolve('stream')), |
45 | 39 | }, |
46 | 40 | }, |
47 | 41 | RTCPeerConnection: function() {} |
@@ -74,20 +68,20 @@ describe('Chrome shim', () => { |
74 | 68 |
|
75 | 69 | it('returns chrome legacy getStats when called with a callback', (done) => { |
76 | 70 | pc.getStats((result) => { |
77 | | - expect(result).to.have.property('result'); |
| 71 | + expect(result).toHaveProperty('result'); |
78 | 72 | const report = result.result()[0]; |
79 | | - expect(report).to.have.property('id'); |
80 | | - expect(report).to.have.property('type'); |
81 | | - expect(report).to.have.property('timestamp'); |
82 | | - expect(report).to.have.property('stat'); |
| 73 | + expect(report).toHaveProperty('id'); |
| 74 | + expect(report).toHaveProperty('type'); |
| 75 | + expect(report).toHaveProperty('timestamp'); |
| 76 | + expect(report).toHaveProperty('stat'); |
83 | 77 | done(); |
84 | 78 | }); |
85 | 79 | }); |
86 | 80 |
|
87 | 81 | it('is translated into a Map', () => { |
88 | 82 | return pc.getStats() |
89 | 83 | .then(result => { |
90 | | - expect(result).to.be.a('Map'); |
| 84 | + expect(result).toBeInstanceOf(Map); |
91 | 85 | }); |
92 | 86 | }); |
93 | 87 | }); |
@@ -119,80 +113,97 @@ describe('Chrome shim', () => { |
119 | 113 | }); |
120 | 114 |
|
121 | 115 | describe('getDisplayMedia shim', () => { |
122 | | - const getSourceId = sinon.stub().returns(Promise.resolve('abc')); |
| 116 | + const getSourceId = jest.fn().mockReturnValue(Promise.resolve('abc')); |
123 | 117 |
|
124 | 118 | it('does not overwrite an existing ' + |
125 | 119 | 'navigator.mediaDevices.getDisplayMedia', () => { |
126 | 120 | window.navigator.mediaDevices.getDisplayMedia = 'foo'; |
127 | 121 | shim.shimGetDisplayMedia(window, getSourceId); |
128 | | - expect(window.navigator.mediaDevices.getDisplayMedia).to.equal('foo'); |
| 122 | + expect(window.navigator.mediaDevices.getDisplayMedia).toBe('foo'); |
129 | 123 | }); |
130 | 124 |
|
131 | 125 | it('does not if navigator.mediaDevices does not exist', () => { |
132 | 126 | delete window.navigator.mediaDevices; |
133 | 127 | shim.shimGetDisplayMedia(window); |
134 | | - expect(window.navigator.mediaDevices).to.equal(undefined); |
| 128 | + expect(window.navigator.mediaDevices).toBe(undefined); |
135 | 129 | }); |
136 | 130 |
|
137 | 131 | it('shims navigator.mediaDevices.getDisplayMedia', () => { |
138 | 132 | shim.shimGetDisplayMedia(window, getSourceId); |
139 | | - expect(window.navigator.mediaDevices.getDisplayMedia).to.be.a('function'); |
| 133 | + expect(typeof window.navigator.mediaDevices.getDisplayMedia) |
| 134 | + .toBe('function'); |
140 | 135 | }); |
141 | 136 |
|
142 | | - it('calls getUserMedia with the sourceId', () => { |
| 137 | + it('calls getUserMedia with the sourceId', async() => { |
143 | 138 | shim.shimGetDisplayMedia(window, getSourceId); |
144 | | - return window.navigator.mediaDevices.getDisplayMedia({video: true}) |
145 | | - .then(() => { |
146 | | - expect(window.navigator.mediaDevices.getUserMedia) |
147 | | - .to.have.been.calledWith({video: {mandatory: { |
| 139 | + await window.navigator.mediaDevices.getDisplayMedia({video: true}); |
| 140 | + expect(window.navigator.mediaDevices.getUserMedia.mock.calls.length) |
| 141 | + .toBe(1); |
| 142 | + expect(window.navigator.mediaDevices.getUserMedia.mock.calls[0][0]) |
| 143 | + .toEqual({ |
| 144 | + video: { |
| 145 | + mandatory: { |
148 | 146 | chromeMediaSource: 'desktop', |
149 | 147 | chromeMediaSourceId: 'abc', |
150 | 148 | maxFrameRate: 3, |
151 | | - }}}); |
| 149 | + } |
| 150 | + } |
152 | 151 | }); |
153 | 152 | }); |
154 | 153 |
|
155 | | - it('translates frameRate to legacy maxFrameRate', () => { |
| 154 | + it('translates frameRate to legacy maxFrameRate', async() => { |
156 | 155 | shim.shimGetDisplayMedia(window, getSourceId); |
157 | | - return window.navigator.mediaDevices |
158 | | - .getDisplayMedia({video: {frameRate: 25}}) |
159 | | - .then(() => { |
160 | | - expect(window.navigator.mediaDevices.getUserMedia) |
161 | | - .to.have.been.calledWith({video: {mandatory: { |
| 156 | + await window.navigator.mediaDevices |
| 157 | + .getDisplayMedia({video: {frameRate: 25}}); |
| 158 | + expect(window.navigator.mediaDevices.getUserMedia.mock.calls.length) |
| 159 | + .toBe(1); |
| 160 | + expect(window.navigator.mediaDevices.getUserMedia.mock.calls[0][0]) |
| 161 | + .toEqual({ |
| 162 | + video: { |
| 163 | + mandatory: { |
162 | 164 | chromeMediaSource: 'desktop', |
163 | 165 | chromeMediaSourceId: 'abc', |
164 | 166 | maxFrameRate: 25, |
165 | | - }}}); |
| 167 | + } |
| 168 | + } |
166 | 169 | }); |
167 | 170 | }); |
168 | 171 |
|
169 | | - it('translates width to legacy maxWidth', () => { |
| 172 | + it('translates width to legacy maxWidth', async() => { |
170 | 173 | shim.shimGetDisplayMedia(window, getSourceId); |
171 | | - return window.navigator.mediaDevices |
172 | | - .getDisplayMedia({video: {width: 640}}) |
173 | | - .then(() => { |
174 | | - expect(window.navigator.mediaDevices.getUserMedia) |
175 | | - .to.have.been.calledWith({video: {mandatory: { |
| 174 | + await window.navigator.mediaDevices |
| 175 | + .getDisplayMedia({video: {width: 640}}); |
| 176 | + expect(window.navigator.mediaDevices.getUserMedia.mock.calls.length) |
| 177 | + .toBe(1); |
| 178 | + expect(window.navigator.mediaDevices.getUserMedia.mock.calls[0][0]) |
| 179 | + .toEqual({ |
| 180 | + video: { |
| 181 | + mandatory: { |
176 | 182 | chromeMediaSource: 'desktop', |
177 | 183 | chromeMediaSourceId: 'abc', |
178 | 184 | maxFrameRate: 3, |
179 | 185 | maxWidth: 640, |
180 | | - }}}); |
| 186 | + } |
| 187 | + } |
181 | 188 | }); |
182 | 189 | }); |
183 | 190 |
|
184 | | - it('translates height to legacy maxHeight', () => { |
| 191 | + it('translates height to legacy maxHeight', async() => { |
185 | 192 | shim.shimGetDisplayMedia(window, getSourceId); |
186 | | - return window.navigator.mediaDevices |
187 | | - .getDisplayMedia({video: {height: 480}}) |
188 | | - .then(() => { |
189 | | - expect(window.navigator.mediaDevices.getUserMedia) |
190 | | - .to.have.been.calledWith({video: {mandatory: { |
| 193 | + await window.navigator.mediaDevices |
| 194 | + .getDisplayMedia({video: {height: 480}}); |
| 195 | + expect(window.navigator.mediaDevices.getUserMedia.mock.calls.length) |
| 196 | + .toBe(1); |
| 197 | + expect(window.navigator.mediaDevices.getUserMedia.mock.calls[0][0]) |
| 198 | + .toEqual({ |
| 199 | + video: { |
| 200 | + mandatory: { |
191 | 201 | chromeMediaSource: 'desktop', |
192 | 202 | chromeMediaSourceId: 'abc', |
193 | 203 | maxFrameRate: 3, |
194 | 204 | maxHeight: 480, |
195 | | - }}}); |
| 205 | + } |
| 206 | + } |
196 | 207 | }); |
197 | 208 | }); |
198 | 209 | }); |
|
0 commit comments