예제 #1
0
    def testErrorStackTraceHTML(self):
        file_path = self.GetTestFilePath('error_stack_test.html')
        # error_stack_test.html imports error_stack_test.js
        # error_stack_test.js imports load_simple_html.html
        # load_simple_html.html imports foo.html
        # foo.html imports error.js
        # error.js defines maybeRaiseException() method that can raise exception
        # foo.html defines maybeRaiseExceptionInFoo() method that calls
        # maybeRaiseException()
        # Finally, we call maybeRaiseExceptionInFoo() error_stack_test.js
        # Exception log should capture these method calls' stack trace.
        with self.assertRaises(RuntimeError) as context:
            vinn.ExecuteFile(file_path, source_paths=[self.test_data_dir])

        # Assert error stack trace contain src files' info.
        exception_message = context.exception.message
        self.assertIn(('error.js:7: Error: Throw ERROR\n'
                       "    throw new Error('Throw ERROR');"),
                      exception_message)

        self.AssertHasNamedFrame('maybeRaiseException', 'error.js:7',
                                 exception_message)
        self.AssertHasNamedFrame('global.maybeRaiseExceptionInFoo',
                                 'foo.html:34', exception_message)
        self.AssertHasFrame('error_stack_test.js:14', exception_message)
        self.AssertHasNamedFrame('eval', 'error_stack_test.html:22',
                                 exception_message)
예제 #2
0
 def testSimpleJsExecution(self):
     file_path = self.GetTestFilePath('print_file_content.js')
     dummy_test_path = self.GetTestFilePath('dummy_test_file')
     output = vinn.ExecuteFile(file_path,
                               source_paths=[self.test_data_dir],
                               js_args=[dummy_test_path])
     self.assertIn('This is file contains only data for testing.\n1 2 3 4',
                   output)
예제 #3
0
 def testJsFileLoadHtmlFile(self):
     file_path = self.GetTestFilePath('load_simple_html.js')
     output = vinn.ExecuteFile(file_path, source_paths=[self.test_data_dir])
     expected_output = ('File foo.html is loaded\n'
                        'x = 1\n'
                        "File foo.html's second script is loaded\n"
                        'x = 2\n'
                        'load_simple_html.js is loaded\n')
     self.assertEquals(output, expected_output)
예제 #4
0
 def testExecuteFileStdoutPiping(self):
     file_path = self.GetTestFilePath('simple.js')
     tmp_dir = tempfile.mkdtemp()
     try:
         temp_file_name = os.path.join(tmp_dir, 'out_file')
         with open(temp_file_name, 'w') as f:
             vinn.ExecuteFile(file_path, stdout=f)
         with open(temp_file_name, 'r') as f:
             self.assertEquals(f.read(), 'Hello W0rld from simple.js\n')
     finally:
         shutil.rmtree(tmp_dir)
예제 #5
0
    def testStrictError(self):
        file_path = self.GetTestFilePath('non_strict_error.html')
        with self.assertRaises(RuntimeError) as context:
            vinn.ExecuteFile(file_path, source_paths=[self.test_data_dir])

        # Assert error stack trace contain src files' info.
        exception_message = context.exception.message

        self.assertIn('non_defined_variable is not defined', exception_message)
        self.AssertHasNamedFrame('eval', 'non_strict_error.html:17',
                                 exception_message)
예제 #6
0
    def testStackTraceOfErroWhenSyntaxErrorOccurs(self):
        file_path = self.GetTestFilePath('syntax_error.html')
        with self.assertRaises(RuntimeError) as context:
            vinn.ExecuteFile(file_path, source_paths=[self.test_data_dir])

        # Assert error stack trace contain src files' info.
        exception_message = context.exception.message

        self.assertIn(
            'syntax_error.html:23: SyntaxError: Unexpected identifier',
            exception_message)
예제 #7
0
    def testRetries(self):
        file_path = self.GetTestFilePath('load_simple_js.js')

        def RaiseRuntimeError(*args, **kwargs):
            del args, kwargs
            raise RuntimeError('Error reading "blah blah"')
        with mock.patch('vinn._vinn._RunFileWithD8') as mock_d8_runner, \
            mock.patch('time.sleep'):
            mock_d8_runner.side_effect = RaiseRuntimeError
            with self.assertRaises(RuntimeError):
                output = vinn.ExecuteFile(file_path,
                                          source_paths=[self.test_data_dir])
            self.assertEqual(len(mock_d8_runner.mock_calls), _vinn._NUM_TRIALS)
예제 #8
0
    def testStackTraceOfErroWhenLoadingJS(self):
        file_path = self.GetTestFilePath('load_js_error.html')
        with self.assertRaises(RuntimeError) as context:
            vinn.ExecuteFile(file_path, source_paths=[self.test_data_dir])

        # Assert error stack trace contain src files' info.
        exception_message = context.exception.message

        self.assertIn('Error: /does_not_exist.js not found', exception_message)
        self.AssertHasNamedFrame('eval', 'load_js_error_2.html:20',
                                 exception_message)
        self.AssertHasNamedFrame('eval', 'load_js_error.html:22',
                                 exception_message)
예제 #9
0
 def testExecuteFileWithV8Args(self):
     file_path = self.GetTestFilePath('simple.js')
     vinn.ExecuteFile(file_path, v8_args=['--foo', '--bar=True'])
     v8_args = self.mock_popen.call_args[0][0]
     self.assertIn('--foo', v8_args)
     self.assertIn('--bar=True', v8_args)
예제 #10
0
 def testConsoleTimeEndAssertion(self):
     file_path = self.GetTestFilePath('console_time_test.js')
     try:
         vinn.ExecuteFile(file_path)
     except RuntimeError:
         self.fail()
예제 #11
0
 def testJsFileLoadJsFile(self):
     file_path = self.GetTestFilePath('load_simple_js.js')
     output = vinn.ExecuteFile(file_path, source_paths=[self.test_data_dir])
     expected_output = ('bar.js is loaded\n'
                        'load_simple_js.js is loaded\n')
     self.assertEquals(output, expected_output)