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

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: 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
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 os
8 import shutil
9 import sys
10 import tempfile
11 import unittest
12 import json
13
14 sys.path.append(
15 os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..'))
16
17 from PRESUBMIT_test_mocks import (MockInputApi, MockOutputApi, MockFile,
18 MockChange)
19
20 class JsCheckerEsLintTest(unittest.TestCase):
21 def setUp(self):
22 self._tmp_files = []
23
24 input_api = MockInputApi()
25 output_api = MockOutputApi()
26 self.checker = js_checker.JSChecker(input_api, output_api)
27
28
29 def tearDown(self):
30 for tmp_file in self._tmp_files:
31 os.remove(tmp_file)
32
33
34 def _create_tmp_file(self, file_contents):
35 # Temp files need to be under src/ such that src/.eslintrc.js takes effect.
36 _HERE_PATH = os.path.dirname(__file__)
37 with open(os.path.join(_HERE_PATH, 'tmp_eslint_test.js'), 'w') as f:
38 self._tmp_files.append(f.name)
39 f.write(file_contents)
40 return f
41
42
43 def testGetElementByIdCheck(self):
44 checker = js_checker.JSChecker(MockInputApi(), MockOutputApi())
45 tmp = self._create_tmp_file('var a = document.getElementById(\'foo\');')
46
47 resultsJson = checker.RunEsLintChecks([tmp.name], format='json')
48 self.assertEqual(1, len(resultsJson))
49
50 results = json.loads(resultsJson[0].message)
51 self.assertEqual(1, len(results))
52
53 self.assertEqual(1, len(results[0].get('messages')))
54 message = results[0].get('messages')[0]
55 self.assertEqual('no-restricted-properties', message.get('ruleId'))
56 self.assertEqual(1, message.get('line'))
57
58
59 if __name__ == '__main__':
60 unittest.main()
OLDNEW
« 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