OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import js_checker |
| 7 import json |
| 8 import os |
| 9 import sys |
| 10 import unittest |
| 11 import tempfile |
| 12 |
| 13 |
| 14 _HERE_PATH = os.path.dirname(__file__) |
| 15 sys.path.append(os.path.join(_HERE_PATH, '..', '..')) |
| 16 |
| 17 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockFile |
| 18 |
| 19 |
| 20 class JsCheckerEsLintTest(unittest.TestCase): |
| 21 def tearDown(self): |
| 22 os.remove(self._tmp_file) |
| 23 |
| 24 def testGetElementByIdCheck(self): |
| 25 tmp_args = {'suffix': '.js', 'dir': _HERE_PATH, 'delete': False} |
| 26 with tempfile.NamedTemporaryFile(**tmp_args) as f: |
| 27 self._tmp_file = f.name |
| 28 f.write('var a = document.getElementById(\'foo\');') |
| 29 |
| 30 input_api = MockInputApi() |
| 31 input_api.files = [MockFile(os.path.abspath(self._tmp_file), '')] |
| 32 input_api.presubmit_local_path = _HERE_PATH |
| 33 |
| 34 checker = js_checker.JSChecker(input_api, MockOutputApi()) |
| 35 results_json = checker.RunEsLintChecks( |
| 36 input_api.AffectedFiles(), format='json') |
| 37 self.assertEqual(1, len(results_json)) |
| 38 |
| 39 results = json.loads(results_json[0].message) |
| 40 self.assertEqual(1, len(results)) |
| 41 |
| 42 self.assertEqual(1, len(results[0].get('messages'))) |
| 43 message = results[0].get('messages')[0] |
| 44 self.assertEqual('no-restricted-properties', message.get('ruleId')) |
| 45 self.assertEqual(1, message.get('line')) |
| 46 |
| 47 |
| 48 if __name__ == '__main__': |
| 49 unittest.main() |
OLD | NEW |