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..63ce78aaaf2e3f353f33a048bf4196052e95659a |
--- /dev/null |
+++ b/tools/web_dev_style/js_checker_eslint_test.py |
@@ -0,0 +1,53 @@ |
+#!/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 |
+ |
+sys.path.append( |
+ os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')) |
Dan Beam
2017/05/30 23:11:09
indent is weird (should only be 4 \s for continuat
dpapad
2017/05/31 01:30:06
Done.
|
+ |
+from PRESUBMIT_test_mocks import (MockInputApi, MockOutputApi) |
Dan Beam
2017/05/30 23:11:09
nit: do you need the parens around the module name
dpapad
2017/05/31 01:30:06
Done.
|
+ |
+class JsCheckerEsLintTest(unittest.TestCase): |
+ def setUp(self): |
+ self._tmp_files = [] |
+ |
+ |
Dan Beam
2017/05/30 23:11:09
only \n (not \n\n) between these.
\n\n is only fo
dpapad
2017/05/31 01:30:06
Done.
|
+ def tearDown(self): |
+ for tmp_file in self._tmp_files: |
+ os.remove(tmp_file) |
Dan Beam
2017/05/30 23:11:09
arguable nit: map(os.remove, self._tmp_files)
dpapad
2017/05/31 01:30:06
Not needed anymore.
|
+ |
+ |
+ 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__) |
Dan Beam
2017/05/30 23:11:09
can we combine both __file__ references in a globa
dpapad
2017/05/31 01:30:06
Done.
|
+ with open(os.path.join(_HERE_PATH, 'tmp_eslint_test.js'), 'w') as f: |
+ self._tmp_files.append(f.name) |
Dan Beam
2017/05/30 23:12:27
why do we need an array still?
dpapad
2017/05/31 01:30:06
Removed the array.
|
+ 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') |
Dan Beam
2017/05/30 23:11:09
results_json
https://engdoc.corp.google.com/eng/d
dpapad
2017/05/31 01:30:06
Done.
|
+ 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() |