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

Commit

Permalink
Merge pull request #7 from bountytesting123/configurable-output-file-…
Browse files Browse the repository at this point in the history
…name

Add junit_xml_filename configuration option

- Merges #7 from @bountytesting123
  • Loading branch information
Gregg Van Hove authored Feb 26, 2018
2 parents abf7ac1 + ae833e7 commit 2903c9f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ The config file will be processed with ERB if you want to make the destination d
---
junit_xml_path: <%= File.join(Dir.pwd, 'some', 'relative', 'path')

### Configuring the output filename:

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`

---
junit_xml_filename: custom_filename.junit.xml

## Contributing

1. Fork it
Expand Down
6 changes: 5 additions & 1 deletion lib/jasmine/formatters/junit_xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def done(run_details)
testsuite['errors'] = 0

FileUtils.mkdir_p(output_dir)
File.open(File.join(output_dir, 'junit_results.xml'), 'w') do |file|
File.open(File.join(output_dir, output_filename), 'w') do |file|
file.puts doc.to_xml(indent: 2)
end
end
Expand All @@ -95,6 +95,10 @@ def output_dir
config['junit_xml_path'] || Dir.pwd
end

def output_filename
config['junit_xml_filename'] || 'junit_results.xml'
end

def load_config(filepath=nil)
filepath ||= File.join(Dir.pwd, 'spec', 'javascripts', 'support', 'jasmine_junitxml_formatter.yml')
@config = YAML::load(ERB.new(File.read(filepath)).result(binding)) if File.exist?(filepath)
Expand Down
58 changes: 58 additions & 0 deletions spec/lib/jasmine/formatters/junit_xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,64 @@ def puts(content)
end
end

describe 'when the output filename has been customized' do
before do
allow(Dir).to receive(:pwd).and_return('/default_path')
end

it 'writes to the specified location if provided in jasmine_junitxml_formatter.yml' do
config_path = File.join('/default_path', 'spec', 'javascripts', 'support', 'jasmine_junitxml_formatter.yml')
allow(File).to receive(:exist?).with(config_path).and_return(true)
allow(File).to receive(:read).with(config_path).and_return <<-YAML
---
junit_xml_filename: "custom_filename.junit.xml"
YAML
allow(File).to receive(:open).and_call_original
allow(File).to receive(:open).with('/default_path/custom_filename.junit.xml', 'w').and_yield(file_stub)

results = [passing_result('fullName' => 'Passing test', 'description' => 'test')]
subject = Jasmine::Formatters::JunitXml.new

subject.format(results)
subject.done({})
expect(file_stub.content).to_not eq ''
end

it 'writes to default location if junit_xml_filename is not provided in jasmine_junitxml_formatter.yml' do
allow(File).to receive(:open).and_call_original
allow(File).to receive(:open).with('/default_path/junit_results.xml', 'w').and_yield(file_stub)

results = [passing_result('fullName' => 'Passing test', 'description' => 'test')]
subject = Jasmine::Formatters::JunitXml.new

subject.format(results)
subject.done({})
expect(file_stub.content).to_not eq ''
end
end

describe 'when both the output directory and output filename has been customized' do
it 'writes to the customized location using the customized filename if provided in jasmine_junitxml_formatter.yml' do
allow(Dir).to receive(:pwd).and_return('/default_path')
config_path = File.join('/default_path', 'spec', 'javascripts', 'support', 'jasmine_junitxml_formatter.yml')
allow(File).to receive(:exist?).with(config_path).and_return(true)
allow(File).to receive(:read).with(config_path).and_return <<-YAML
---
junit_xml_path: "/custom_path"
junit_xml_filename: "custom_filename.junit.xml"
YAML
allow(File).to receive(:open).and_call_original
allow(File).to receive(:open).with('/custom_path/custom_filename.junit.xml', 'w').and_yield(file_stub)

results = [passing_result('fullName' => 'Passing test', 'description' => 'test')]
subject = Jasmine::Formatters::JunitXml.new

subject.format(results)
subject.done({})
expect(file_stub.content).to_not eq ''
end
end

describe 'with a custom config file path' do
before do
allow(Dir).to receive(:pwd).and_return('/default_path')
Expand Down

0 comments on commit 2903c9f

Please sign in to comment.