Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.

Commit 2903c9f

Browse files
author
Gregg Van Hove
authored
Merge pull request #7 from bountytesting123/configurable-output-file-name
Add junit_xml_filename configuration option - Merges #7 from @bountytesting123
2 parents abf7ac1 + ae833e7 commit 2903c9f

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ The config file will be processed with ERB if you want to make the destination d
3333
---
3434
junit_xml_path: <%= File.join(Dir.pwd, 'some', 'relative', 'path')
3535

36+
### Configuring the output filename:
37+
38+
To configure the filename of the XML file that is generated, the `junit_xml_filename` configuration option can be used, otherwise the default filename is `junit_results.xml`
39+
40+
---
41+
junit_xml_filename: custom_filename.junit.xml
42+
3643
## Contributing
3744

3845
1. Fork it

lib/jasmine/formatters/junit_xml.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def done(run_details)
8383
testsuite['errors'] = 0
8484

8585
FileUtils.mkdir_p(output_dir)
86-
File.open(File.join(output_dir, 'junit_results.xml'), 'w') do |file|
86+
File.open(File.join(output_dir, output_filename), 'w') do |file|
8787
file.puts doc.to_xml(indent: 2)
8888
end
8989
end
@@ -95,6 +95,10 @@ def output_dir
9595
config['junit_xml_path'] || Dir.pwd
9696
end
9797

98+
def output_filename
99+
config['junit_xml_filename'] || 'junit_results.xml'
100+
end
101+
98102
def load_config(filepath=nil)
99103
filepath ||= File.join(Dir.pwd, 'spec', 'javascripts', 'support', 'jasmine_junitxml_formatter.yml')
100104
@config = YAML::load(ERB.new(File.read(filepath)).result(binding)) if File.exist?(filepath)

spec/lib/jasmine/formatters/junit_xml_spec.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,64 @@ def puts(content)
169169
end
170170
end
171171

172+
describe 'when the output filename has been customized' do
173+
before do
174+
allow(Dir).to receive(:pwd).and_return('/default_path')
175+
end
176+
177+
it 'writes to the specified location if provided in jasmine_junitxml_formatter.yml' do
178+
config_path = File.join('/default_path', 'spec', 'javascripts', 'support', 'jasmine_junitxml_formatter.yml')
179+
allow(File).to receive(:exist?).with(config_path).and_return(true)
180+
allow(File).to receive(:read).with(config_path).and_return <<-YAML
181+
---
182+
junit_xml_filename: "custom_filename.junit.xml"
183+
YAML
184+
allow(File).to receive(:open).and_call_original
185+
allow(File).to receive(:open).with('/default_path/custom_filename.junit.xml', 'w').and_yield(file_stub)
186+
187+
results = [passing_result('fullName' => 'Passing test', 'description' => 'test')]
188+
subject = Jasmine::Formatters::JunitXml.new
189+
190+
subject.format(results)
191+
subject.done({})
192+
expect(file_stub.content).to_not eq ''
193+
end
194+
195+
it 'writes to default location if junit_xml_filename is not provided in jasmine_junitxml_formatter.yml' do
196+
allow(File).to receive(:open).and_call_original
197+
allow(File).to receive(:open).with('/default_path/junit_results.xml', 'w').and_yield(file_stub)
198+
199+
results = [passing_result('fullName' => 'Passing test', 'description' => 'test')]
200+
subject = Jasmine::Formatters::JunitXml.new
201+
202+
subject.format(results)
203+
subject.done({})
204+
expect(file_stub.content).to_not eq ''
205+
end
206+
end
207+
208+
describe 'when both the output directory and output filename has been customized' do
209+
it 'writes to the customized location using the customized filename if provided in jasmine_junitxml_formatter.yml' do
210+
allow(Dir).to receive(:pwd).and_return('/default_path')
211+
config_path = File.join('/default_path', 'spec', 'javascripts', 'support', 'jasmine_junitxml_formatter.yml')
212+
allow(File).to receive(:exist?).with(config_path).and_return(true)
213+
allow(File).to receive(:read).with(config_path).and_return <<-YAML
214+
---
215+
junit_xml_path: "/custom_path"
216+
junit_xml_filename: "custom_filename.junit.xml"
217+
YAML
218+
allow(File).to receive(:open).and_call_original
219+
allow(File).to receive(:open).with('/custom_path/custom_filename.junit.xml', 'w').and_yield(file_stub)
220+
221+
results = [passing_result('fullName' => 'Passing test', 'description' => 'test')]
222+
subject = Jasmine::Formatters::JunitXml.new
223+
224+
subject.format(results)
225+
subject.done({})
226+
expect(file_stub.content).to_not eq ''
227+
end
228+
end
229+
172230
describe 'with a custom config file path' do
173231
before do
174232
allow(Dir).to receive(:pwd).and_return('/default_path')

0 commit comments

Comments
 (0)