1
- --- @diagnostic disable : undefined-doc-name , duplicate-doc-field , duplicate-set-field
2
-
3
1
local File = require (" neotest.lib.file" )
4
2
5
3
local file_checker = require (" neotest-java.core.file_checker" )
@@ -12,7 +10,6 @@ local log = require("neotest-java.logger")
12
10
local ch = require (" neotest-java.context_holder" )
13
11
local lib = require (" neotest.lib" )
14
12
local timer = require (" neotest-java.util.timer" )
15
- local nio = require (" nio" )
16
13
17
14
local detect_project_type = require (" neotest-java.util.detect_project_type" )
18
15
@@ -28,86 +25,50 @@ local check_junit_jar = function(filepath)
28
25
)
29
26
end
30
27
31
- --- @class neotest.Adapter
32
- NeotestJavaAdapter = {
33
- name = " neotest-java" ,
34
- }
35
-
36
- --- Find the project root directory given a current directory to work from.
37
- --- Should no root be found, the adapter can still be used in a non-project context if a test file matches.
38
- --- @async
39
- --- @param dir string @Directory to treat as cwd
40
- --- @return string | nil @Absolute root dir of test suite
41
- function NeotestJavaAdapter .root (dir )
42
- local root = root_finder .find_root (dir )
43
- if root then
44
- ch .set_root (root )
45
- end
46
- return root
47
- end
48
-
49
- --- Filter directories when searching for test files
50
- --- @async
51
- --- @param name string Name of directory
52
- --- @param rel_path string Path to directory , relative to root
53
- --- @param root string Root directory of project
54
- --- @return boolean
55
- function NeotestJavaAdapter .filter_dir (name , rel_path , root )
56
- return dir_filter .filter_dir (name , rel_path , root )
57
- end
58
-
59
- --- @async
60
- --- @param file_path string
61
- --- @return boolean
62
- function NeotestJavaAdapter .is_test_file (file_path )
63
- return file_checker .is_test_file (file_path )
64
- end
65
-
66
- --- Given a file path, parse all the tests within it.
67
- --- @async
68
- --- @param file_path string Absolute file path
69
- --- @return neotest.Tree | nil
70
- function NeotestJavaAdapter .discover_positions (file_path )
71
- return position_discoverer .discover_positions (file_path )
72
- end
73
-
74
28
--- @type neotest-java.Timer
75
29
local test_timer = nil
76
30
77
- --- @param args neotest.RunArgs
78
- --- @return nil | neotest.RunSpec | neotest.RunSpec[]
79
- function NeotestJavaAdapter .build_spec (args )
80
- test_timer = timer :start ()
81
- local self = NeotestJavaAdapter
82
- check_junit_jar (ch .get_context ().config .junit_jar )
31
+ --- @class neotest.Adapter
32
+ NeotestJavaAdapter = {
33
+ name = " neotest-java" ,
34
+ root = function (dir )
35
+ local root = root_finder .find_root (dir )
36
+ if root then
37
+ ch .set_root (root )
38
+ end
39
+ return root
40
+ end ,
41
+ filter_dir = dir_filter .filter_dir ,
42
+ is_test_file = file_checker .is_test_file ,
43
+ discover_positions = position_discoverer .discover_positions ,
83
44
84
- -- TODO: find a way to avoid to make this steps every time
45
+ build_spec = function (args )
46
+ test_timer = timer :start ()
47
+ local self = NeotestJavaAdapter
48
+ check_junit_jar (ch .get_context ().config .junit_jar )
85
49
86
- -- find root
87
- local root = ch .get_context ().root or self .root (vim .fn .getcwd ())
88
- assert (root , " root directory not found" )
50
+ -- TODO: find a way to avoid to make this steps every time
89
51
90
- -- detect project type
91
- local project_type = detect_project_type (root )
52
+ -- find root
53
+ local root = ch .get_context ().root or self .root (vim .fn .getcwd ())
54
+ assert (root , " root directory not found" )
92
55
93
- -- build spec
94
- return spec_builder .build_spec (args , project_type , ch .get_context ().config )
95
- end
56
+ -- detect project type
57
+ local project_type = detect_project_type (root )
96
58
97
- --- @async
98
- --- @param spec neotest.RunSpec
99
- --- @param result neotest.StrategyResult
100
- --- @param tree neotest.Tree
101
- --- @return table<string , neotest.Result>
102
- function NeotestJavaAdapter .results (spec , result , tree )
103
- local results = result_builder .build_results (spec , result , tree )
59
+ -- build spec
60
+ return spec_builder .build_spec (args , project_type , ch .get_context ().config )
61
+ end ,
62
+ results = function (spec , result , tree )
63
+ local results = result_builder .build_results (spec , result , tree )
104
64
105
- if test_timer then
106
- lib .notify (" Tests lasted " .. test_timer :stop () .. " ms." )
107
- end
65
+ if test_timer then
66
+ lib .notify (" Tests lasted " .. test_timer :stop () .. " ms." )
67
+ end
108
68
109
- return results
110
- end
69
+ return results
70
+ end ,
71
+ };
111
72
112
73
-- on init
113
74
(function ()
0 commit comments