Mholloway has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/403324 )

Change subject: Fix misleading testing utilities and update tests
......................................................................

Fix misleading testing utilities and update tests

The deepEqual and isDeepEqual wrapper methods in test/util/assert.js
confusingly use RegExp matching for string inputs in a way that is not
at all equivalent to === and makes it very easy to write tests resulting
in false positives (see
https://github.com/wikimedia/service-template-node/issues/94, for
example).

This eliminates the alternate string behavior and updates the tests that
are broken by that change.

This should be upstreamed in some form.

Change-Id: Ia9b01b26ac004294e10901736ed3d8e8653be984
---
M test/features/app/app.js
M test/utils/assert.js
M test/utils/headers.js
3 files changed, 7 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/24/403324/1

diff --git a/test/features/app/app.js b/test/features/app/app.js
index 3bd5758..2035558 100644
--- a/test/features/app/app.js
+++ b/test/features/app/app.js
@@ -52,9 +52,9 @@
             assert.deepEqual(res.headers['x-xss-protection'], '1; mode=block');
             assert.deepEqual(res.headers['x-content-type-options'], 'nosniff');
             assert.deepEqual(res.headers['x-frame-options'], 'SAMEORIGIN');
-            assert.deepEqual(res.headers['content-security-policy'], 
'default-src');
-            assert.deepEqual(res.headers['x-content-security-policy'], 
'default-src');
-            assert.deepEqual(res.headers['x-webkit-csp'], 'default-src');
+            assert.contains(res.headers['content-security-policy'], 
'default-src');
+            assert.contains(res.headers['x-content-security-policy'], 
'default-src');
+            assert.contains(res.headers['x-webkit-csp'], 'default-src');
         });
     });
 
diff --git a/test/utils/assert.js b/test/utils/assert.js
index fcdd736..f20d959 100644
--- a/test/utils/assert.js
+++ b/test/utils/assert.js
@@ -9,11 +9,7 @@
 function deepEqual(result, expected, message) {
 
     try {
-        if (typeof expected === 'string') {
-            assert.ok(result === expected || (new 
RegExp(expected).test(result)));
-        } else {
-            assert.deepEqual(result, expected, message);
-        }
+        assert.deepEqual(result, expected, message);
     } catch (e) {
         console.log(`Expected:\n${JSON.stringify(expected, null, 2)}`);
         console.log(`Result:\n${JSON.stringify(result, null, 2)}`);
@@ -40,7 +36,7 @@
 function contentType(res, expected) {
 
     const actual = res.headers['content-type'];
-    deepEqual(actual, expected,
+    assert.ok(RegExp(expected).test(actual),
         `Expected content-type to be ${expected}, but was ${actual}`);
 
 }
@@ -49,11 +45,7 @@
 function isDeepEqual(result, expected, message) {
 
     try {
-        if (typeof expected === 'string') {
-            assert.ok(result === expected || (new 
RegExp(expected).test(result)), message);
-        } else {
-            assert.deepEqual(result, expected, message);
-        }
+        assert.deepEqual(result, expected, message);
         return true;
     } catch (e) {
         return false;
diff --git a/test/utils/headers.js b/test/utils/headers.js
index 0447ba3..73c01f5 100644
--- a/test/utils/headers.js
+++ b/test/utils/headers.js
@@ -14,7 +14,7 @@
             assert.deepEqual(res.status, 200);
             expContentType = expContentType || JSON_CONTENT_TYPE_REGEX;
             assert.contentType(res, expContentType);
-            assert.deepEqual(res.headers.etag, '^"[^/"]+/[^/"]+"$',
+            assert.ok(RegExp('^"[^/"]+/[^/"]+"$').test(res.headers.etag),
                 'The ETag header is not present or invalid');
             assert.deepEqual(res.headers.etag.indexOf('undefined'), -1,
                 'etag should not contain "undefined"');

-- 
To view, visit https://gerrit.wikimedia.org/r/403324
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia9b01b26ac004294e10901736ed3d8e8653be984
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Mholloway <mhollo...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to