11local JavaDap = require (' java.dap' )
22
33local log = require (' java.utils.log' )
4- local get_error_handler = require (' java.handlers.error' )
54local jdtls = require (' java.utils.jdtls' )
5+ local get_error_handler = require (' java.handlers.error' )
6+
67local async = require (' java-core.utils.async' ).sync
78
8- local M = {}
9+ local JUnitReport = require (' java-test.reports.junit' )
10+ local ResultParserFactory = require (' java-test.results.result-parser-factory' )
11+ local ReportViewer = require (' java-test.ui.floating-report-viewer' )
912
10- --- Setup dap config & adapter on jdtls attach event
13+ local M = {
14+ --- @type java_test.JUnitTestReport
15+ last_report = nil ,
16+ }
1117
12- function M .run_current_test_class ()
18+ --- Setup dap config & adapter on jdtls attach event
19+ function M .run_current_class ()
1320 log .info (' run current test class' )
1421
1522 return async (function ()
16- return JavaDap :new (jdtls ()):execute_current_test_class ({ noDebug = true })
23+ return JavaDap :new (jdtls ())
24+ :execute_current_test_class (M .get_report (), { noDebug = true })
1725 end )
1826 .catch (get_error_handler (' failed to run the current test class' ))
1927 .run ()
2028end
2129
22- function M .debug_current_test_class ()
30+ function M .debug_current_class ()
2331 log .info (' debug current test class' )
2432
2533 return async (function ()
26- JavaDap :new (jdtls ()):execute_current_test_class ({})
34+ JavaDap :new (jdtls ()):execute_current_test_class (M . get_report (), {})
2735 end )
2836 .catch (get_error_handler (' failed to debug the current test class' ))
2937 .run ()
@@ -33,7 +41,8 @@ function M.debug_current_method()
3341 log .info (' debug current test method' )
3442
3543 return async (function ()
36- return JavaDap :new (jdtls ()):execute_current_test_method ()
44+ return JavaDap :new (jdtls ())
45+ :execute_current_test_method (M .get_report (), {})
3746 end )
3847 .catch (get_error_handler (' failed to run the current test method' ))
3948 .run ()
@@ -44,12 +53,19 @@ function M.run_current_method()
4453
4554 return async (function ()
4655 return JavaDap :new (jdtls ())
47- :execute_current_test_method ({ noDebug = true })
56+ :execute_current_test_method (M . get_report (), { noDebug = true })
4857 end )
4958 .catch (get_error_handler (' failed to run the current test method' ))
5059 .run ()
5160end
5261
62+ function M .view_report ()
63+ if M .last_report then
64+ M .last_report :show_report ()
65+ end
66+ end
67+
68+ --- @private
5369function M .config_dap ()
5470 log .info (' configuring dap' )
5571
@@ -60,4 +76,11 @@ function M.config_dap()
6076 .run ()
6177end
6278
79+ --- @private
80+ function M .get_report ()
81+ local report = JUnitReport (ResultParserFactory (), ReportViewer ())
82+ M .last_report = report
83+ return report
84+ end
85+
6386return M
0 commit comments