From c3acf43c47fab80d8605908f6bc438e1de4e809f Mon Sep 17 00:00:00 2001
From: Scott Nonnenberg <scott@signal.org>
Date: Fri, 20 Apr 2018 12:11:56 -0700
Subject: [PATCH] Eslintify test/backup_test.js

---
 .eslintignore                       |   1 +
 test/.eslintrc.js                   |   5 +
 test/app/.eslintrc.js               |  12 ++
 test/backup_test.js                 | 194 +++++++++++++++-------------
 test/modules/.eslintrc              |   6 -
 test/modules/.eslintrc.js           |  27 ++++
 test/styleguide/legacy_bridge.js    |   2 +
 test/styleguide/legacy_templates.js |   2 +
 8 files changed, 152 insertions(+), 97 deletions(-)
 create mode 100644 test/app/.eslintrc.js
 delete mode 100644 test/modules/.eslintrc
 create mode 100644 test/modules/.eslintrc.js

diff --git a/.eslintignore b/.eslintignore
index 124d7eb31..6ffa7ebf6 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -23,6 +23,7 @@ ts/**/*.js
 !js/logging.js
 !js/models/conversations.js
 !js/models/messages.js
+!test/backup_test.js
 !js/views/attachment_view.js
 !js/views/conversation_view.js
 !js/views/conversation_search_view.js
diff --git a/test/.eslintrc.js b/test/.eslintrc.js
index 3a0872c30..30f27856c 100644
--- a/test/.eslintrc.js
+++ b/test/.eslintrc.js
@@ -3,6 +3,11 @@
 module.exports = {
   env: {
     mocha: true,
+    browser: true,
+  },
+
+  parserOptions: {
+    sourceType: 'script',
   },
 
   rules: {
diff --git a/test/app/.eslintrc.js b/test/app/.eslintrc.js
new file mode 100644
index 000000000..38ff2d117
--- /dev/null
+++ b/test/app/.eslintrc.js
@@ -0,0 +1,12 @@
+// For reference: https://github.com/airbnb/javascript
+
+module.exports = {
+  env: {
+    mocha: true,
+    browser: false,
+  },
+
+  parserOptions: {
+    sourceType: 'module',
+  },
+};
diff --git a/test/backup_test.js b/test/backup_test.js
index 1b789466c..6019a85ac 100644
--- a/test/backup_test.js
+++ b/test/backup_test.js
@@ -1,52 +1,55 @@
+/* global Signal: false */
+/* global assert: false */
+
 'use strict';
 
-describe('Backup', function() {
-  describe('_sanitizeFileName', function() {
-    it('leaves a basic string alone', function() {
-      var initial = 'Hello, how are you #5 (\'fine\' + great).jpg';
-      var expected = initial;
+describe('Backup', () => {
+  describe('_sanitizeFileName', () => {
+    it('leaves a basic string alone', () => {
+      const initial = 'Hello, how are you #5 (\'fine\' + great).jpg';
+      const expected = initial;
       assert.strictEqual(Signal.Backup._sanitizeFileName(initial), expected);
     });
 
-    it('replaces all unknown characters', function() {
-      var initial = '!@$%^&*=';
-      var expected = '________';
+    it('replaces all unknown characters', () => {
+      const initial = '!@$%^&*=';
+      const expected = '________';
       assert.strictEqual(Signal.Backup._sanitizeFileName(initial), expected);
     });
   });
 
-  describe('_trimFileName', function() {
-    it('handles a file with no extension', function() {
-      var initial = '0123456789012345678901234567890123456789';
-      var expected = '012345678901234567890123456789';
+  describe('_trimFileName', () => {
+    it('handles a file with no extension', () => {
+      const initial = '0123456789012345678901234567890123456789';
+      const expected = '012345678901234567890123456789';
       assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
     });
 
-    it('handles a file with a long extension', function() {
-      var initial = '0123456789012345678901234567890123456789.01234567890123456789';
-      var expected = '012345678901234567890123456789';
+    it('handles a file with a long extension', () => {
+      const initial = '0123456789012345678901234567890123456789.01234567890123456789';
+      const expected = '012345678901234567890123456789';
       assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
     });
 
-    it('handles a file with a normal extension', function() {
-      var initial = '01234567890123456789012345678901234567890123456789.jpg';
-      var expected = '012345678901234567890123.jpg';
+    it('handles a file with a normal extension', () => {
+      const initial = '01234567890123456789012345678901234567890123456789.jpg';
+      const expected = '012345678901234567890123.jpg';
       assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
     });
   });
 
-  describe('_getExportAttachmentFileName', function() {
-    it('uses original filename if attachment has one', function() {
-      var message = {
+  describe('_getExportAttachmentFileName', () => {
+    it('uses original filename if attachment has one', () => {
+      const message = {
         body: 'something',
       };
-      var index = 0;
-      var attachment = {
-        fileName: 'blah.jpg'
+      const index = 0;
+      const attachment = {
+        fileName: 'blah.jpg',
       };
-      var expected = 'blah.jpg';
+      const expected = 'blah.jpg';
 
-      var actual = Signal.Backup._getExportAttachmentFileName(
+      const actual = Signal.Backup._getExportAttachmentFileName(
         message,
         index,
         attachment
@@ -54,17 +57,17 @@ describe('Backup', function() {
       assert.strictEqual(actual, expected);
     });
 
-    it('uses attachment id if no filename', function() {
-      var message = {
+    it('uses attachment id if no filename', () => {
+      const message = {
         body: 'something',
       };
-      var index = 0;
-      var attachment = {
-        id: '123'
+      const index = 0;
+      const attachment = {
+        id: '123',
       };
-      var expected = '123';
+      const expected = '123';
 
-      var actual = Signal.Backup._getExportAttachmentFileName(
+      const actual = Signal.Backup._getExportAttachmentFileName(
         message,
         index,
         attachment
@@ -72,18 +75,18 @@ describe('Backup', function() {
       assert.strictEqual(actual, expected);
     });
 
-    it('uses filename and contentType if available', function() {
-      var message = {
+    it('uses filename and contentType if available', () => {
+      const message = {
         body: 'something',
       };
-      var index = 0;
-      var attachment = {
+      const index = 0;
+      const attachment = {
         id: '123',
-        contentType: 'image/jpeg'
+        contentType: 'image/jpeg',
       };
-      var expected = '123.jpeg';
+      const expected = '123.jpeg';
 
-      var actual = Signal.Backup._getExportAttachmentFileName(
+      const actual = Signal.Backup._getExportAttachmentFileName(
         message,
         index,
         attachment
@@ -91,18 +94,18 @@ describe('Backup', function() {
       assert.strictEqual(actual, expected);
     });
 
-    it('handles strange contentType', function() {
-      var message = {
+    it('handles strange contentType', () => {
+      const message = {
         body: 'something',
       };
-      var index = 0;
-      var attachment = {
+      const index = 0;
+      const attachment = {
         id: '123',
-        contentType: 'something'
+        contentType: 'something',
       };
-      var expected = '123.something';
+      const expected = '123.something';
 
-      var actual = Signal.Backup._getExportAttachmentFileName(
+      const actual = Signal.Backup._getExportAttachmentFileName(
         message,
         index,
         attachment
@@ -111,19 +114,19 @@ describe('Backup', function() {
     });
   });
 
-  describe('_getAnonymousAttachmentFileName', function() {
-    it('uses message id', function() {
-      var message = {
+  describe('_getAnonymousAttachmentFileName', () => {
+    it('uses message id', () => {
+      const message = {
         id: 'id-45',
         body: 'something',
       };
-      var index = 0;
-      var attachment = {
-        fileName: 'blah.jpg'
+      const index = 0;
+      const attachment = {
+        fileName: 'blah.jpg',
       };
-      var expected = 'id-45';
+      const expected = 'id-45';
 
-      var actual = Signal.Backup._getAnonymousAttachmentFileName(
+      const actual = Signal.Backup._getAnonymousAttachmentFileName(
         message,
         index,
         attachment
@@ -131,18 +134,18 @@ describe('Backup', function() {
       assert.strictEqual(actual, expected);
     });
 
-    it('appends index if it is above zero', function() {
-      var message = {
+    it('appends index if it is above zero', () => {
+      const message = {
         id: 'id-45',
         body: 'something',
       };
-      var index = 1;
-      var attachment = {
-        fileName: 'blah.jpg'
+      const index = 1;
+      const attachment = {
+        fileName: 'blah.jpg',
       };
-      var expected = 'id-45-1';
+      const expected = 'id-45-1';
 
-      var actual = Signal.Backup._getAnonymousAttachmentFileName(
+      const actual = Signal.Backup._getAnonymousAttachmentFileName(
         message,
         index,
         attachment
@@ -151,64 +154,73 @@ describe('Backup', function() {
     });
   });
 
-  describe('_getConversationDirName', function() {
-    it('uses name if available', function() {
-      var conversation = {
+  describe('_getConversationDirName', () => {
+    it('uses name if available', () => {
+      const conversation = {
         active_at: 123,
         name: '0123456789012345678901234567890123456789',
-        id: 'id'
+        id: 'id',
       };
-      var expected = '123 (012345678901234567890123456789 id)';
+      const expected = '123 (012345678901234567890123456789 id)';
       assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
     });
 
-    it('uses just id if name is not available', function() {
-      var conversation = {
+    it('uses just id if name is not available', () => {
+      const conversation = {
         active_at: 123,
-        id: 'id'
+        id: 'id',
       };
-      var expected = '123 (id)';
+      const expected = '123 (id)';
       assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
     });
 
-    it('uses inactive for missing active_at', function() {
-      var conversation = {
+    it('uses inactive for missing active_at', () => {
+      const conversation = {
         name: 'name',
-        id: 'id'
+        id: 'id',
       };
-      var expected = 'inactive (name id)';
+      const expected = 'inactive (name id)';
       assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
     });
   });
 
-  describe('_getConversationLoggingName', function() {
-    it('uses plain id if conversation is private', function() {
-      var conversation = {
+  describe('_getConversationLoggingName', () => {
+    it('uses plain id if conversation is private', () => {
+      const conversation = {
         active_at: 123,
         id: 'id',
-        type: 'private'
+        type: 'private',
       };
-      var expected = '123 (id)';
-      assert.strictEqual(Signal.Backup._getConversationLoggingName(conversation), expected);
+      const expected = '123 (id)';
+      assert.strictEqual(
+        Signal.Backup._getConversationLoggingName(conversation),
+        expected
+      );
     });
 
-    it('uses just id if name is not available', function() {
-      var conversation = {
+    it('uses just id if name is not available', () => {
+      const conversation = {
         active_at: 123,
         id: 'groupId',
-        type: 'group'
+        type: 'group',
       };
-      var expected = '123 ([REDACTED_GROUP]pId)';
-      assert.strictEqual(Signal.Backup._getConversationLoggingName(conversation), expected);
+      const expected = '123 ([REDACTED_GROUP]pId)';
+      assert.strictEqual(
+        Signal.Backup._getConversationLoggingName(conversation),
+        expected
+      );
     });
 
-    it('uses inactive for missing active_at', function() {
-      var conversation = {
+    it('uses inactive for missing active_at', () => {
+      const conversation = {
         id: 'id',
-        type: 'private'
+        type: 'private',
       };
-      var expected = 'inactive (id)';
-      assert.strictEqual(Signal.Backup._getConversationLoggingName(conversation), expected);
+      const expected = 'inactive (id)';
+      assert.strictEqual(
+        Signal.Backup._getConversationLoggingName(conversation),
+        expected
+      );
     });
   });
 });
diff --git a/test/modules/.eslintrc b/test/modules/.eslintrc
deleted file mode 100644
index 4cb311c54..000000000
--- a/test/modules/.eslintrc
+++ /dev/null
@@ -1,6 +0,0 @@
-{
-  "globals": {
-    "check": true,
-    "gen": true
-  }
-}
diff --git a/test/modules/.eslintrc.js b/test/modules/.eslintrc.js
new file mode 100644
index 000000000..1051e858e
--- /dev/null
+++ b/test/modules/.eslintrc.js
@@ -0,0 +1,27 @@
+// For reference: https://github.com/airbnb/javascript
+
+module.exports = {
+  env: {
+    mocha: true,
+    browser: true,
+  },
+
+  "globals": {
+    check: true,
+    gen: true,
+  },
+
+  parserOptions: {
+    sourceType: 'module',
+  },
+
+  rules: {
+    // We still get the value of this rule, it just allows for dev deps
+    'import/no-extraneous-dependencies': ['error', {
+      devDependencies: true
+    }],
+
+    // We want to keep each test structured the same, even if its contents are tiny
+    'arrow-body-style': 'off',
+  }
+};
diff --git a/test/styleguide/legacy_bridge.js b/test/styleguide/legacy_bridge.js
index ff7373dbb..33fc433f4 100644
--- a/test/styleguide/legacy_bridge.js
+++ b/test/styleguide/legacy_bridge.js
@@ -1,3 +1,5 @@
+'use strict';
+
 /* global window: false */
 
 // Because we aren't hosting the Style Guide in Electron, we can't rely on preload.js
diff --git a/test/styleguide/legacy_templates.js b/test/styleguide/legacy_templates.js
index 72c6ebf50..92770648f 100644
--- a/test/styleguide/legacy_templates.js
+++ b/test/styleguide/legacy_templates.js
@@ -1,3 +1,5 @@
+'use strict';
+
 /* global window: false */
 
 // Taken from background.html.