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

Side by Side 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, 6 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 unified diff | Download patch
« no previous file with comments | « tools/web_dev_style/js_checker.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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()
OLDNEW
« 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