[gjs: 23/43] CI: Disallow imports.mainloop in new code with no-restricted-properties
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 23/43] CI: Disallow imports.mainloop in new code with no-restricted-properties
- Date: Wed, 14 Aug 2019 17:29:00 +0000 (UTC)
commit db0b5551d53759775b11b89b8b978096f8d9e89a
Author: Philip Chimento <philip chimento gmail com>
Date: Sat Aug 3 22:59:30 2019 -0700
CI: Disallow imports.mainloop in new code with no-restricted-properties
We consider it better to use GLib timeouts and main loops.
.eslintrc.yml | 3 +++
installed-tests/js/testGObjectInterface.js | 28 ++++++++++++++++------------
installed-tests/js/testMainloop.js | 2 ++
3 files changed, 21 insertions(+), 12 deletions(-)
---
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 4d1029bb..819183b5 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -90,6 +90,9 @@ rules:
- object: Lang
property: Class
message: Use ES6 classes
+ - object: imports
+ property: mainloop
+ message: Use GLib main loops and timeouts
no-tabs: error
no-unused-vars:
- error
diff --git a/installed-tests/js/testGObjectInterface.js b/installed-tests/js/testGObjectInterface.js
index d2d12af1..2098f9fe 100644
--- a/installed-tests/js/testGObjectInterface.js
+++ b/installed-tests/js/testGObjectInterface.js
@@ -1,7 +1,6 @@
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
-const Mainloop = imports.mainloop;
const AGObjectInterface = GObject.registerClass({
GTypeName: 'ArbitraryGTypeName',
@@ -222,29 +221,34 @@ describe('GObject interface', function () {
}, class BadObject {})).toThrow();
});
- it('can define signals on the implementing class', function () {
+ it('can connect class signals on the implementing class', function (done) {
function quitLoop() {
- Mainloop.quit('signal');
+ expect(classSignalSpy).toHaveBeenCalled();
+ done();
}
let obj = new GObjectImplementingGObjectInterface();
- let interfaceSignalSpy = jasmine.createSpy('interfaceSignalSpy')
- .and.callFake(quitLoop);
let classSignalSpy = jasmine.createSpy('classSignalSpy')
.and.callFake(quitLoop);
- obj.connect('interface-signal', interfaceSignalSpy);
obj.connect('class-signal', classSignalSpy);
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
- obj.emit('interface-signal');
+ obj.emit('class-signal');
return GLib.SOURCE_REMOVE;
});
- Mainloop.run('signal');
+ });
+
+ it('can connect interface signals on the implementing class', function (done) {
+ function quitLoop() {
+ expect(interfaceSignalSpy).toHaveBeenCalled();
+ done();
+ }
+ let obj = new GObjectImplementingGObjectInterface();
+ let interfaceSignalSpy = jasmine.createSpy('interfaceSignalSpy')
+ .and.callFake(quitLoop);
+ obj.connect('interface-signal', interfaceSignalSpy);
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
- obj.emit('class-signal');
+ obj.emit('interface-signal');
return GLib.SOURCE_REMOVE;
});
- Mainloop.run('signal');
- expect(interfaceSignalSpy).toHaveBeenCalled();
- expect(classSignalSpy).toHaveBeenCalled();
});
it('can define properties on the implementing class', function () {
diff --git a/installed-tests/js/testMainloop.js b/installed-tests/js/testMainloop.js
index 0ffcf37c..8215baef 100644
--- a/installed-tests/js/testMainloop.js
+++ b/installed-tests/js/testMainloop.js
@@ -1,3 +1,5 @@
+/* eslint-disable no-restricted-properties */
+
const Mainloop = imports.mainloop;
describe('Mainloop.timeout_add()', function () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]