# Path: tests/js_helper.py
# def _do_real_test_raw(script, path='foo.js', versions=None, detected_type=None,
#                       metadata=None, resources=None, jetpack=False):
#     """Perform a JS test using a non-mock bundler."""
# 
#     err = ErrorBundle(for_appversions=versions or {})
#     if detected_type:
#         err.detected_type = detected_type
#     if metadata is not None:
#         err.metadata = metadata
#     if resources is not None:
#         err.resources = resources
#     if jetpack:
#         err.metadata['is_jetpack'] = True
# 
#     validator.testcases.content._process_file(err, MockXPI(), path, script,
#                                               path.lower())
#     return err


import mock
from .js_helper import _do_real_test_raw as _test_js
"""Tests various aspects of the JS traverser."""



@mock.patch('validator.testcases.javascript.traverser.JSWrapper')
def test_js_traversal_error_reporting(JSWrapper):
    """Test that an internal error in JS traversal is correctly reported as
    a system error."""

    JSWrapper.side_effect = Exception('Inigo Montoya...')
    err = _test_js('hello();', path='my_name_is.js')

    assert len(err.errors) == 1
    assert err.errors[0]['id'] == ('validator', 'unexpected_exception')

# Path: tests/js_helper.py
# def _do_real_test_raw(script, path='foo.js', versions=None, detected_type=None,
#                       metadata=None, resources=None, jetpack=False):
#     """Perform a JS test using a non-mock bundler."""
# 
#     err = ErrorBundle(for_appversions=versions or {})
#     if detected_type:
#         err.detected_type = detected_type
#     if metadata is not None:
#         err.metadata = metadata
#     if resources is not None:
#         err.resources = resources
#     if jetpack:
#         err.metadata['is_jetpack'] = True
# 
#     validator.testcases.content._process_file(err, MockXPI(), path, script,
#                                               path.lower())
#     return err


# Path: tests/test_js_traversal.py
import mock
from .js_helper import _do_real_test_raw as _test_js

"""Tests various aspects of the JS traverser."""



@mock.patch('validator.testcases.javascript.traverser.JSWrapper')
def test_js_traversal_error_reporting(JSWrapper):
    """Test that an internal error in JS traversal is correctly reported as
    a system error."""

    JSWrapper.side_effect = Exception('Inigo Montoya...')
    err = _test_js('hello();', path='my_name_is.js')

    assert len(err.errors) == 1
    assert err.errors[0]['id'] == ('validator', 'unexpected_exception')

    assert err.errors[0]['file'] == 'my_name_is.js'