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

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: 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
« tools/web_dev_style/js_checker.py ('K') | « 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..dd6f54a7e0fe9e3a32305b46b07d14e262eb5f15
--- /dev/null
+++ b/tools/web_dev_style/js_checker_eslint_test.py
@@ -0,0 +1,60 @@
+#!/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 os
+import shutil
+import sys
+import tempfile
+import unittest
+import json
+
+sys.path.append(
+ os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..'))
+
+from PRESUBMIT_test_mocks import (MockInputApi, MockOutputApi, MockFile,
+ MockChange)
+
+class JsCheckerEsLintTest(unittest.TestCase):
+ def setUp(self):
+ self._tmp_files = []
+
+ input_api = MockInputApi()
+ output_api = MockOutputApi()
+ self.checker = js_checker.JSChecker(input_api, output_api)
+
+
+ def tearDown(self):
+ for tmp_file in self._tmp_files:
+ os.remove(tmp_file)
+
+
+ def _create_tmp_file(self, file_contents):
+ # Temp files need to be under src/ such that src/.eslintrc.js takes effect.
+ _HERE_PATH = os.path.dirname(__file__)
+ with open(os.path.join(_HERE_PATH, 'tmp_eslint_test.js'), 'w') as f:
+ self._tmp_files.append(f.name)
+ f.write(file_contents)
+ return f
+
+
+ def testGetElementByIdCheck(self):
+ checker = js_checker.JSChecker(MockInputApi(), MockOutputApi())
+ tmp = self._create_tmp_file('var a = document.getElementById(\'foo\');')
+
+ resultsJson = checker.RunEsLintChecks([tmp.name], format='json')
+ self.assertEqual(1, len(resultsJson))
+
+ results = json.loads(resultsJson[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()
« tools/web_dev_style/js_checker.py ('K') | « 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