[gjs] coverage: Scan ES6 classes for functions



commit 547a8a498ed93e625c860d088bda7e748ee70a42
Author: Philip Chimento <philip chimento gmail com>
Date:   Fri Sep 22 22:57:11 2017 -0700

    coverage: Scan ES6 classes for functions
    
    Previously, class methods and property getters/setters were not counted
    for coverage statistics.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788166

 installed-tests/js/testCoverage.js |   72 ++++++++++++++++++++++++++++++++++++
 modules/_bootstrap/coverage.js     |    5 ++-
 2 files changed, 76 insertions(+), 1 deletions(-)
---
diff --git a/installed-tests/js/testCoverage.js b/installed-tests/js/testCoverage.js
index 8a0cbe6..a5fb2bf 100644
--- a/installed-tests/js/testCoverage.js
+++ b/installed-tests/js/testCoverage.js
@@ -455,6 +455,78 @@ describe('Coverage.functionsForAST', function () {
                 { key: "(anonymous):2:0", line: 2, n_params: 0 }
             ],
         ],
+
+        'finds class methods': [
+            `class Foo {
+                bar() {}
+            }`,
+            [
+                { key: 'bar:2:0', line: 2, n_params: 0 },
+            ],
+        ],
+
+        'finds class property setters': [
+            `class Foo {
+                set bar(value) {}
+            }`,
+            [
+                { key: 'set bar:2:1', line: 2, n_params: 1 },
+            ],
+        ],
+
+        'finds class property getters': [
+            `class Foo {
+                get bar() {}
+            }`,
+            [
+                { key: 'get bar:2:0', line: 2, n_params: 0 },
+            ],
+        ],
+
+        'finds class constructors': [
+            `class Foo {
+                constructor(baz) {}
+            }`,
+            [
+                { key: 'Foo:2:1', line: 2, n_params: 1 },
+            ],
+        ],
+
+        'finds class expression methods': [
+            `void class {
+                baz() {}
+            }`,
+            [
+                { key: 'baz:2:0', line: 2, n_params: 0 },
+            ],
+        ],
+
+        'finds class expression property setters': [
+            `void class {
+                set baz(value) {}
+            }`,
+            [
+                { key: 'set baz:2:1', line: 2, n_params: 1 },
+            ],
+        ],
+
+        'finds class expression property getters': [
+            `void class {
+                get baz() {}
+            }`,
+            [
+                { key: 'get baz:2:0', line: 2, n_params: 0 },
+            ],
+        ],
+
+        'finds class expression constructors': [
+            `void class {
+                constructor(baz) {}
+            }`,
+            [
+                { key: '(anonymous):2:1', line: 2, n_params: 1 },
+            ],
+        ],
     };
 
     Object.keys(testTable).forEach(testcase => {
diff --git a/modules/_bootstrap/coverage.js b/modules/_bootstrap/coverage.js
index b7beae3..ec3a4b4 100644
--- a/modules/_bootstrap/coverage.js
+++ b/modules/_bootstrap/coverage.js
@@ -31,6 +31,7 @@ function getSubNodesForNode(node) {
     case 'FunctionDeclaration':
     case 'FunctionExpression':
     case 'CatchClause':
+    case 'ClassMethod':
         subNodes.push(node.body);
         break;
     case 'LetStatement':
@@ -62,7 +63,9 @@ function getSubNodesForNode(node) {
         subNodes.push(node.left, node.right, node.body);
         break;
     case 'BlockStatement':
-        Array.prototype.push.apply(subNodes, node.body);
+    case 'ClassStatement':
+    case 'ClassExpression':
+        subNodes.push(...node.body);
         break;
     case 'ThrowStatement':
     case 'ReturnStatement':


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