Chromium Code Reviews| 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..898c865dcd73c74c116deb69cfa3dcf90da01804 |
| --- /dev/null |
| +++ b/tools/web_dev_style/js_checker_eslint_test.py |
| @@ -0,0 +1,51 @@ |
| +#!/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 |
| +import tempfile |
| + |
| + |
| +_HERE_PATH = os.path.dirname(__file__) |
| +sys.path.append( |
| + os.path.join(os.path.dirname(_HERE_PATH), '..', '..')) |
|
Dan Beam
2017/05/31 01:40:31
why do we need the dirname() around _HERE_PATH aga
dpapad
2017/05/31 02:49:58
Removed.
|
| + |
| +from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockFile |
| + |
| + |
| +class JsCheckerEsLintTest(unittest.TestCase): |
| + def tearDown(self): |
| + os.remove(self._tmp_file) |
| + |
| + def testGetElementByIdCheck(self): |
| + with tempfile.NamedTemporaryFile( |
| + suffix='.js', dir=_HERE_PATH, delete=False) as f: |
|
Dan Beam
2017/05/31 01:40:31
arguable nit for prettiness:
tmp_args = {suffix='
dpapad
2017/05/31 02:49:58
Done.
|
| + self._tmp_file = f.name |
| + print self._tmp_file |
|
Dan Beam
2017/05/31 01:40:31
remove print
dpapad
2017/05/31 02:49:58
Done.
|
| + f.write('var a = document.getElementById(\'foo\');') |
| + |
| + input_api = MockInputApi() |
| + input_api.files = [MockFile(os.path.abspath(self._tmp_file), '')] |
| + input_api.presubmitLocalPath = _HERE_PATH |
| + |
| + checker = js_checker.JSChecker(input_api, MockOutputApi()) |
| + results_json = checker.RunEsLintChecks( |
| + input_api.AffectedFiles(), format='json') |
| + self.assertEqual(1, len(results_json)) |
| + |
| + results = json.loads(results_json[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() |