mirror of
https://github.com/electron/electron.git
synced 2026-10-28 11:44:46 +08:00
test: fix desktopCapturer restore-token specs on main (#55118)
The restore-token specs added in #54550 were written against a base that predated #54439, which dropped chai/chai-as-promised/dirty-chai in favour of vitest's own matchers and added the no-chai-assertions lint rule. On main, `.to.be.eventually.rejectedWith()` and `.to.be.empty()` throw at runtime and every chai chain trips lint. Switch them to vitest matchers. Claude-Session: https://claude.ai/code/session_012AdLYu5PBMGgRbsE7frDma Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
37d0d2b4ce
commit
7a353a3c8c
1 file changed
+12
-10
@@ -29,12 +29,12 @@ describe('desktopCapturer', { tags: ['serial'] }, () => {
|
||||
|
||||
it('throws an error for an unknown persistMode', async () => {
|
||||
const promise = desktopCapturer.getSources({ types: getSourceTypes(), persistMode: 'forever' as any });
|
||||
await expect(promise).to.be.eventually.rejectedWith(Error, 'Invalid options');
|
||||
await expect(promise).rejects.toThrow('Invalid options');
|
||||
});
|
||||
|
||||
it('throws an error for a non-string restoreToken', async () => {
|
||||
const promise = desktopCapturer.getSources({ types: getSourceTypes(), restoreToken: 42 as any });
|
||||
await expect(promise).to.be.eventually.rejectedWith(Error, 'Invalid options');
|
||||
await expect(promise).rejects.toThrow('Invalid options');
|
||||
});
|
||||
|
||||
it('accepts persistMode and restoreToken and returns a restoreToken for each source', async () => {
|
||||
@@ -44,21 +44,22 @@ describe('desktopCapturer', { tags: ['serial'] }, () => {
|
||||
persistMode: 'transient',
|
||||
restoreToken: ''
|
||||
});
|
||||
expect(sources).to.be.an('array').that.is.not.empty();
|
||||
expect(sources).toBeInstanceOf(Array);
|
||||
expect(sources).not.toHaveLength(0);
|
||||
for (const source of sources) {
|
||||
expect(source.restoreToken).to.be.a('string');
|
||||
if (!isWayland) expect(source.restoreToken).to.be.empty();
|
||||
expect(source.restoreToken).toBeTypeOf('string');
|
||||
if (!isWayland) expect(source.restoreToken).toBe('');
|
||||
}
|
||||
});
|
||||
|
||||
it('throws when restoreToken is passed without persistMode', async () => {
|
||||
const promise = desktopCapturer.getSources({ types: getSourceTypes(), restoreToken: 'token' });
|
||||
await expect(promise).to.be.eventually.rejectedWith(Error, 'Invalid options');
|
||||
await expect(promise).rejects.toThrow('Invalid options');
|
||||
});
|
||||
|
||||
it('getRestoreToken returns an empty string for a source that has no token', () => {
|
||||
expect(desktopCapturer.getRestoreToken('window:0:0')).to.equal('');
|
||||
expect(desktopCapturer.getRestoreToken('not-a-source-id')).to.equal('');
|
||||
expect(desktopCapturer.getRestoreToken('window:0:0')).toBe('');
|
||||
expect(desktopCapturer.getRestoreToken('not-a-source-id')).toBe('');
|
||||
});
|
||||
|
||||
it('getRestoreToken returns the restoreToken of a returned source', async () => {
|
||||
@@ -66,9 +67,10 @@ describe('desktopCapturer', { tags: ['serial'] }, () => {
|
||||
types: getSourceTypes(),
|
||||
thumbnailSize: { width: 0, height: 0 }
|
||||
});
|
||||
expect(sources).to.be.an('array').that.is.not.empty();
|
||||
expect(sources).toBeInstanceOf(Array);
|
||||
expect(sources).not.toHaveLength(0);
|
||||
for (const source of sources) {
|
||||
expect(desktopCapturer.getRestoreToken(source.id)).to.equal(source.restoreToken);
|
||||
expect(desktopCapturer.getRestoreToken(source.id)).toBe(source.restoreToken);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user