Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: tools/web_dev_style/js_checker_eslint_test.py

Issue 2917473002: js_checker.py: Restore smoke tests for linting violations. (Closed)
Patch Set: Address nits. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/web_dev_style/js_checker.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/web_dev_style/js_checker_eslint_test.py
diff --git a/tools/web_dev_style/js_checker_eslint_test.py b/tools/web_dev_style/js_checker_eslint_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..1309c06fc1c38d9edd079e7507cfd8454a3fb524
--- /dev/null
+++ b/tools/web_dev_style/js_checker_eslint_test.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import js_checker
+import json
+import os
+import sys
+import unittest
+import tempfile
+
+
+_HERE_PATH = os.path.dirname(__file__)
+sys.path.append(os.path.join(_HERE_PATH, '..', '..'))
+
+from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockFile
+
+
+class JsCheckerEsLintTest(unittest.TestCase):
+ def tearDown(self):
+ os.remove(self._tmp_file)
+
+ def testGetElementByIdCheck(self):
+ tmp_args = {'suffix': '.js', 'dir': _HERE_PATH, 'delete': False}
+ with tempfile.NamedTemporaryFile(**tmp_args) as f:
+ self._tmp_file = f.name
+ f.write('var a = document.getElementById(\'foo\');')
+
+ input_api = MockInputApi()
+ input_api.files = [MockFile(os.path.abspath(self._tmp_file), '')]
+ input_api.presubmit_local_path = _HERE_PATH
+
+ checker = js_checker.JSChecker(input_api, MockOutputApi())
+ results_json = checker.RunEsLintChecks(
+ input_api.AffectedFiles(), format='json')
+ self.assertEqual(1, len(results_json))
+
+ results = json.loads(results_json[0].message)
+ self.assertEqual(1, len(results))
+
+ self.assertEqual(1, len(results[0].get('messages')))
+ message = results[0].get('messages')[0]
+ self.assertEqual('no-restricted-properties', message.get('ruleId'))
+ self.assertEqual(1, message.get('line'))
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « tools/web_dev_style/js_checker.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698