[gjs: 40/43] CI: Add a rule to prevent arrow functions in Jasmine test cases



commit f7c4757d6dfd35da49f898a128521d353bb05061
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Aug 4 16:44:58 2019 -0700

    CI: Add a rule to prevent arrow functions in Jasmine test cases
    
    Arrow functions bind the surrounding context's `this` value to the
    function, which interferes with Jasmine APIs that use `this` as a test
    context object. See https://github.com/jasmine/jasmine/issues/1416 for
    more information. We can create a custom rule for this with
    no-restricted-syntax.

 installed-tests/js/.eslintrc.yml                   | 15 ++++++++++++++
 installed-tests/js/testGObjectDestructionAccess.js | 24 +++++++++++-----------
 2 files changed, 27 insertions(+), 12 deletions(-)
---
diff --git a/installed-tests/js/.eslintrc.yml b/installed-tests/js/.eslintrc.yml
index b91f167b..3358bdbd 100644
--- a/installed-tests/js/.eslintrc.yml
+++ b/installed-tests/js/.eslintrc.yml
@@ -1,6 +1,21 @@
 ---
 env:
   jasmine: true
+rules:
+  no-restricted-syntax:
+    - error
+    - selector: CallExpression[callee.name="it"] > ArrowFunctionExpression
+      message: Arrow functions can mess up some Jasmine APIs. Use function () instead
+    - selector: CallExpression[callee.name="describe"] > ArrowFunctionExpression
+      message: Arrow functions can mess up some Jasmine APIs. Use function () instead
+    - selector: CallExpression[callee.name="beforeEach"] > ArrowFunctionExpression
+      message: Arrow functions can mess up some Jasmine APIs. Use function () instead
+    - selector: CallExpression[callee.name="afterEach"] > ArrowFunctionExpression
+      message: Arrow functions can mess up some Jasmine APIs. Use function () instead
+    - selector: CallExpression[callee.name="beforeAll"] > ArrowFunctionExpression
+      message: Arrow functions can mess up some Jasmine APIs. Use function () instead
+    - selector: CallExpression[callee.name="afterAll"] > ArrowFunctionExpression
+      message: Arrow functions can mess up some Jasmine APIs. Use function () instead
 globals:
   clearInterval: writable
   clearTimeout: writable
diff --git a/installed-tests/js/testGObjectDestructionAccess.js 
b/installed-tests/js/testGObjectDestructionAccess.js
index dffd4be0..46b7e1de 100644
--- a/installed-tests/js/testGObjectDestructionAccess.js
+++ b/installed-tests/js/testGObjectDestructionAccess.js
@@ -4,19 +4,19 @@ imports.gi.versions.Gtk = '3.0';
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
 
-describe('Access to destroyed GObject', () => {
+describe('Access to destroyed GObject', function () {
     let destroyedWindow;
 
-    beforeAll(() => {
+    beforeAll(function () {
         Gtk.init(null);
     });
 
-    beforeEach(() => {
+    beforeEach(function () {
         destroyedWindow = new Gtk.Window({type: Gtk.WindowType.TOPLEVEL});
         destroyedWindow.destroy();
     });
 
-    it('Get property', () => {
+    it('Get property', function () {
         GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
             'Object Gtk.Window (0x*');
 
@@ -26,7 +26,7 @@ describe('Access to destroyed GObject', () => {
             'testExceptionInDestroyedObjectPropertyGet');
     });
 
-    it('Set property', () => {
+    it('Set property', function () {
         GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
             'Object Gtk.Window (0x*');
 
@@ -36,7 +36,7 @@ describe('Access to destroyed GObject', () => {
             'testExceptionInDestroyedObjectPropertySet');
     });
 
-    it('Access to getter method', () => {
+    it('Access to getter method', function () {
         GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
             'Object Gtk.Window (0x*');
 
@@ -46,7 +46,7 @@ describe('Access to destroyed GObject', () => {
             'testExceptionInDestroyedObjectMethodGet');
     });
 
-    it('Access to setter method', () => {
+    it('Access to setter method', function () {
         GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
             'Object Gtk.Window (0x*');
 
@@ -56,7 +56,7 @@ describe('Access to destroyed GObject', () => {
             'testExceptionInDestroyedObjectMethodSet');
     });
 
-    it('Proto function connect', () => {
+    it('Proto function connect', function () {
         GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
             'Object Gtk.Window (0x*');
 
@@ -66,7 +66,7 @@ describe('Access to destroyed GObject', () => {
             'testExceptionInDestroyedObjectConnect');
     });
 
-    it('Proto function connect_after', () => {
+    it('Proto function connect_after', function () {
         GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
             'Object Gtk.Window (0x*');
 
@@ -76,7 +76,7 @@ describe('Access to destroyed GObject', () => {
             'testExceptionInDestroyedObjectConnectAfter');
     });
 
-    it('Proto function emit', () => {
+    it('Proto function emit', function () {
         GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
             'Object Gtk.Window (0x*');
 
@@ -86,12 +86,12 @@ describe('Access to destroyed GObject', () => {
             'testExceptionInDestroyedObjectEmit');
     });
 
-    it('Proto function toString', () => {
+    it('Proto function toString', function () {
         expect(destroyedWindow.toString()).toMatch(
             /\[object \(FINALIZED\) instance wrapper GIName:Gtk.Window jsobj@0x[a-f0-9]+ 
native@0x[a-f0-9]+\]/);
     });
 
-    it('Proto function toString before/after', () => {
+    it('Proto function toString before/after', function () {
         var validWindow = new Gtk.Window({type: Gtk.WindowType.TOPLEVEL});
 
         expect(validWindow.toString()).toMatch(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]