test-map 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +45 -15
- data/lib/test_map/config.rb +2 -1
- data/lib/test_map/file_recorder.rb +8 -2
- data/lib/test_map/plugins/minitest.rb +1 -2
- data/lib/test_map/plugins/rspec.rb +3 -6
- data/lib/test_map/report.rb +16 -1
- data/lib/test_map/test_task.rb +13 -2
- data/lib/test_map/version.rb +1 -1
- metadata +4 -4
- /data/{LICENSE → LICENSE.txt} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd8d77a4693229a3bdc64882a2771830090f7b04ae977df9eec5386e3ffc16e3
|
4
|
+
data.tar.gz: dc04407d47b77d1b5a6418072c8e380a327417a82fe27a21f31e1020d7b6b2aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d80247e944cecd9b3c06b48b63bae9052589f97713496f674dc9ad23524ebfe6e8bb0720d38a90d0ba9b0874cb33c6a9422d6cd9bf3c49c2f8db252c26dde011
|
7
|
+
data.tar.gz: 1690f86016ea54148386896023ba40e22210e2559c8d7dd175c7b728c458a9e2abdfdaa7f3a73997cbb4da446186e51033313a35df8c3e7e158a1a8cd8359f5a
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.
|
|
6
6
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
7
7
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
8
8
|
|
9
|
-
##
|
9
|
+
## 0.2.0 - 2024-10-25
|
10
|
+
|
11
|
+
Provide explicit Test Task via Rake for Minitest, Rspec, and Rails. Extend
|
12
|
+
documentation.
|
13
|
+
|
14
|
+
## 0.1.0 - 2024-09-22
|
10
15
|
|
11
16
|
Initial release.
|
data/README.md
CHANGED
@@ -19,20 +19,6 @@ Add test-map to your Gemfile.
|
|
19
19
|
$ bundle add test-map
|
20
20
|
```
|
21
21
|
|
22
|
-
On demand you can adapt the configuration to your needs.
|
23
|
-
|
24
|
-
```ruby
|
25
|
-
TestMap::Configure.configure do |config|
|
26
|
-
config.logger = Logger.new($stdout) # default logs to dev/null
|
27
|
-
config.out_file = 'my-test-map.yml' # default is .test-map.yml
|
28
|
-
# defaults to [%r{^(vendor|test|spec)/}] }
|
29
|
-
config.exclude_patterns = [%r{^(libraries|testsuite)/}]
|
30
|
-
# register a custom rule to match new files; must implement `call(file)`;
|
31
|
-
# defaults to nil
|
32
|
-
config.natural_mapping = ->(file) { file.sub(%r{^library/}, 'test/') }
|
33
|
-
end
|
34
|
-
```
|
35
|
-
|
36
22
|
### Minitest
|
37
23
|
|
38
24
|
Include test-map in your test helper. Typically you want to include it
|
@@ -53,6 +39,25 @@ $ TEST_MAP=1 bundle exec ruby -Itest test/models/user_test.rb
|
|
53
39
|
$ TEST_MAP=1 bundle exec rake test
|
54
40
|
```
|
55
41
|
|
42
|
+
Using the a dedicated rake task you can connect a file watcher and trigger
|
43
|
+
tests on file changes.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
# filename: Rakefile
|
47
|
+
require 'test_map/test_task'
|
48
|
+
|
49
|
+
TestMap::TestTask.create
|
50
|
+
```
|
51
|
+
|
52
|
+
Using [entr](https://eradman.com/entrproject/) as example file watcher.
|
53
|
+
|
54
|
+
```sh
|
55
|
+
# find all ruby files | watch them, postpone first execution, clear screen
|
56
|
+
# with every run and on file change run test suite for the changed file
|
57
|
+
# (placeholder /_).
|
58
|
+
$ find . -name "*.rb" | entr -cp bundle exec rake test:changes /_
|
59
|
+
```
|
60
|
+
|
56
61
|
### Rspec
|
57
62
|
|
58
63
|
Include test-map in your test helper. Typically you want to include it
|
@@ -69,8 +74,33 @@ Run your tests with the `TEST_MAP` environment variable set.
|
|
69
74
|
$ TEST_MAP=1 bundle exec rspec
|
70
75
|
```
|
71
76
|
|
77
|
+
## Configuration
|
78
|
+
|
79
|
+
On demand you can adapt the configuration to your needs.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
TestMap::Config.configure do |config|
|
83
|
+
config[:logger] = Logger.new($stdout) # default logs to dev/null
|
84
|
+
config[:merge] = false # merge results (e.g. with multiple testsuites)
|
85
|
+
config[:out_file] = 'my-test-map.yml' # default is .test-map.yml
|
86
|
+
# defaults to [%r{^(vendor)/}] }
|
87
|
+
config[:exclude_patterns] = [%r{^(vendor|other_libraries)/}]
|
88
|
+
# register a custom rule to match new files; must implement `call(file)`;
|
89
|
+
# defaults to nil
|
90
|
+
config[:natural_mapping] = ->(file) { file.sub(%r{^library/}, 'test/') }
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
72
94
|
## Development
|
73
95
|
|
96
|
+
Open list of features:
|
97
|
+
|
98
|
+
- [x] Configure file exclude list (e.g. test files are not needed).
|
99
|
+
- [ ] Auto-handle packs, packs with subdirectories.
|
100
|
+
- [x] Demonstrate usage with file watchers.
|
101
|
+
- [ ] Demonstrate CI pipelines with GitHub actions and GitLab CI.
|
102
|
+
- [x] Merge results.
|
103
|
+
|
74
104
|
```sh
|
75
105
|
$ bundle install # install dependencies
|
76
106
|
$ bundle exec rake # run testsuite
|
@@ -79,5 +109,5 @@ $ bundle exec rubocop # run linter
|
|
79
109
|
|
80
110
|
## Contributing
|
81
111
|
|
82
|
-
Bug reports and pull requests are welcome on
|
112
|
+
Bug reports and pull requests are very welcome on
|
83
113
|
[GitHub](https://github.com/unused/test-map).
|
data/lib/test_map/config.rb
CHANGED
@@ -11,7 +11,8 @@ module TestMap
|
|
11
11
|
|
12
12
|
def self.default_config
|
13
13
|
{ logger: Logger.new('/dev/null'), out_file: '.test-map.yml',
|
14
|
-
exclude_patterns: [%r{^(vendor)/}], natural_mapping: nil
|
14
|
+
exclude_patterns: [%r{^(vendor)/}], natural_mapping: nil,
|
15
|
+
skip_files: [%r{^(test/)}], merge: false }
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -5,13 +5,19 @@ module TestMap
|
|
5
5
|
class FileRecorder
|
6
6
|
def initialize = @files = []
|
7
7
|
|
8
|
-
def trace
|
8
|
+
def trace(&block)
|
9
9
|
raise TraceInUseError.default if @trace&.enabled?
|
10
10
|
|
11
11
|
@trace = TracePoint.new(:call) do |tp|
|
12
12
|
TestMap.logger.debug "#{tp.path}:#{tp.lineno}"
|
13
13
|
@files << tp.path
|
14
|
-
end
|
14
|
+
end
|
15
|
+
|
16
|
+
if block_given?
|
17
|
+
@trace.enable { block.call }
|
18
|
+
else
|
19
|
+
@trace.enable
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
def stop = @trace&.disable
|
@@ -7,8 +7,7 @@ module TestMap
|
|
7
7
|
def self.included(_base)
|
8
8
|
TestMap.logger.info 'Registering hooks for Minitest'
|
9
9
|
::Minitest.after_run do
|
10
|
-
|
11
|
-
File.write "#{Dir.pwd}/#{Config.config[:out_file]}", result
|
10
|
+
TestMap.reporter.write "#{Dir.pwd}/#{Config.config[:out_file]}"
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
@@ -5,15 +5,12 @@ TestMap.logger.info 'Loading RSpec plugin'
|
|
5
5
|
RSpec.configure do |config|
|
6
6
|
config.around(:example) do |example|
|
7
7
|
# path = example.metadata[:example_group][:file_path]
|
8
|
-
recorder = TestMap::FileRecorder.new
|
9
|
-
example.run
|
10
|
-
ensure
|
11
|
-
recorder.stop
|
8
|
+
recorder = TestMap::FileRecorder.new
|
9
|
+
recorder.trace { example.run }
|
12
10
|
TestMap.reporter.add recorder.results
|
13
11
|
end
|
14
12
|
|
15
13
|
config.after(:suite) do
|
16
|
-
|
17
|
-
File.write "#{Dir.pwd}/#{TestMap::Config.config[:out_file]}", result
|
14
|
+
TestMap.reporter.write "#{Dir.pwd}/#{TestMap::Config.config[:out_file]}"
|
18
15
|
end
|
19
16
|
end
|
data/lib/test_map/report.rb
CHANGED
@@ -15,7 +15,22 @@ module TestMap
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def write(file)
|
19
|
+
content = if File.exist?(file) && Config.config[:merge]
|
20
|
+
merge(results, YAML.safe_load_file(file)).to_yaml
|
21
|
+
else
|
22
|
+
to_yaml
|
23
|
+
end
|
24
|
+
File.write file, content
|
25
|
+
end
|
26
|
+
|
27
|
+
def results = @results.transform_values { _1.to_a.uniq.sort }.sort.to_h
|
19
28
|
def to_yaml = results.to_yaml
|
29
|
+
|
30
|
+
def merge(result, current)
|
31
|
+
current.merge(result) do |_key, oldval, newval|
|
32
|
+
(oldval + newval).uniq.sort
|
33
|
+
end
|
34
|
+
end
|
20
35
|
end
|
21
36
|
end
|
data/lib/test_map/test_task.rb
CHANGED
@@ -15,6 +15,13 @@ module TestMap
|
|
15
15
|
@name = name
|
16
16
|
end
|
17
17
|
|
18
|
+
# Adapter for rspec test task
|
19
|
+
class RailsTestTask
|
20
|
+
attr_accessor :files
|
21
|
+
|
22
|
+
def call = Rails::TestUnit::Runner.run_from_rake('test', files)
|
23
|
+
end
|
24
|
+
|
18
25
|
# Adapter for minitest test task.
|
19
26
|
class MinitestTask < Minitest::TestTask
|
20
27
|
def call = ruby(make_test_cmd, verbose: false)
|
@@ -38,7 +45,8 @@ module TestMap
|
|
38
45
|
desc 'Run tests for changed files'
|
39
46
|
task :changes do
|
40
47
|
out_file = "#{Dir.pwd}/.test-map.yml"
|
41
|
-
|
48
|
+
args = defined?(Rails) ? ENV['TEST']&.split : ARGV[1..]
|
49
|
+
test_files = Mapping.new(out_file).lookup(*args)
|
42
50
|
|
43
51
|
# puts "Running tests #{test_files.join(' ')}"
|
44
52
|
test_task.files = test_files
|
@@ -50,7 +58,10 @@ module TestMap
|
|
50
58
|
def test_task = @test_task ||= build_test_task
|
51
59
|
|
52
60
|
def build_test_task
|
53
|
-
if defined?(
|
61
|
+
if defined?(Rails)
|
62
|
+
return RailsTestTask.new
|
63
|
+
elsif defined?(Minitest)
|
64
|
+
require 'minitest/test_task'
|
54
65
|
return MinitestTask.new
|
55
66
|
elsif defined?(RSpec)
|
56
67
|
return RSpecTask.new
|
data/lib/test_map/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Lipautz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Track files that are covered by test files to execute only the necessary
|
@@ -18,11 +18,11 @@ email:
|
|
18
18
|
executables: []
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files:
|
21
|
-
- LICENSE
|
21
|
+
- LICENSE.txt
|
22
22
|
- README.md
|
23
23
|
files:
|
24
24
|
- CHANGELOG.md
|
25
|
-
- LICENSE
|
25
|
+
- LICENSE.txt
|
26
26
|
- README.md
|
27
27
|
- lib/test_map.rb
|
28
28
|
- lib/test_map/config.rb
|
/data/{LICENSE → LICENSE.txt}
RENAMED
File without changes
|