| 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..dd6f54a7e0fe9e3a32305b46b07d14e262eb5f15
|
| --- /dev/null
|
| +++ b/tools/web_dev_style/js_checker_eslint_test.py
|
| @@ -0,0 +1,60 @@
|
| +#!/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 os
|
| +import shutil
|
| +import sys
|
| +import tempfile
|
| +import unittest
|
| +import json
|
| +
|
| +sys.path.append(
|
| + os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..'))
|
| +
|
| +from PRESUBMIT_test_mocks import (MockInputApi, MockOutputApi, MockFile,
|
| + MockChange)
|
| +
|
| +class JsCheckerEsLintTest(unittest.TestCase):
|
| + def setUp(self):
|
| + self._tmp_files = []
|
| +
|
| + input_api = MockInputApi()
|
| + output_api = MockOutputApi()
|
| + self.checker = js_checker.JSChecker(input_api, output_api)
|
| +
|
| +
|
| + def tearDown(self):
|
| + for tmp_file in self._tmp_files:
|
| + os.remove(tmp_file)
|
| +
|
| +
|
| + 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__)
|
| + with open(os.path.join(_HERE_PATH, 'tmp_eslint_test.js'), 'w') as f:
|
| + self._tmp_files.append(f.name)
|
| + 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')
|
| + 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()
|
|
|