Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #11949
- Loading branch information
Showing
12 changed files
with
387 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* @typedef {Object} ReportInfo | ||
* @property {String} data | ||
* @property {String} packageName | ||
*/ | ||
|
||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
/** | ||
* Creates directories (if missing corresponding) to a provided file path | ||
* | ||
* @param {String} filePath The file path | ||
*/ | ||
function createDirectoriesIfMissing(filePath) { | ||
const dirname = path.dirname(filePath); | ||
if (fs.existsSync(dirname)) { | ||
return; | ||
} | ||
createDirectoriesIfMissing(dirname); | ||
fs.mkdirSync(dirname); | ||
} | ||
|
||
/** | ||
* Writes a JUnit report as a single test | ||
* | ||
* @param {ReportInfo} | ||
* @param {String} outputFile The file path describing the file that will hold the JUnit report | ||
*/ | ||
function writeReportAsSingleTest({data, packageName}, outputFile) { | ||
const xmlOutput = buildXMLOutputAsSingleTest({data, packageName}); | ||
createDirectoriesIfMissing(outputFile); | ||
fs.writeFileSync(outputFile, xmlOutput, 'utf8'); | ||
} | ||
|
||
/** | ||
* Builds the output that will be written in the XML JUnit report | ||
* | ||
* @param {ReportInfo} | ||
* @returns {String} The output that will be written in the JUnit report | ||
*/ | ||
function buildXMLOutputAsSingleTest({data, packageName}) { | ||
const testSuite = !data | ||
? '' | ||
: ` | ||
<testsuite package="${packageName}" time="0" tests="1" errors="1" name=""> | ||
<testcase time="0" name="${packageName} merged report"> | ||
<failure message=""><![CDATA[ | ||
${data} | ||
]]> | ||
</failure> | ||
</testcase> | ||
</testsuite> | ||
`; | ||
return `<?xml version="1.0"?> | ||
<testsuites> | ||
${testSuite} | ||
</testsuites> | ||
`; | ||
} | ||
|
||
module.exports = { | ||
writeReportAsSingleTest, | ||
createDirectoriesIfMissing, | ||
buildXMLOutputAsSingleTest, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const formatterConfig = require('../formatterConfig'); | ||
|
||
const immutableDefaultConfig = { | ||
name: 'defaultName', | ||
outputFile: 'defaultFile', | ||
formatterFlag: '--formatter', | ||
outputFlag: '--output', | ||
}; | ||
let defaultConfig; | ||
|
||
describe('formatterConfig', () => { | ||
beforeEach(() => { | ||
defaultConfig = {...immutableDefaultConfig}; | ||
}); | ||
|
||
it('should work with empty process arguments', () => { | ||
expect(formatterConfig(defaultConfig)).toEqual(immutableDefaultConfig); | ||
}); | ||
|
||
it('should work when provided a formatter name', () => { | ||
expect(formatterConfig(defaultConfig, ['--formatter=junit'])).toEqual({ | ||
name: 'junit', | ||
outputFile: 'defaultFile', | ||
formatterFlag: '--formatter', | ||
outputFlag: '--output', | ||
}); | ||
}); | ||
|
||
it('should work when provided a file output path', () => { | ||
expect( | ||
formatterConfig(defaultConfig, ['Hello', '--output=some/path/result.xml']) | ||
).toEqual({ | ||
name: 'defaultName', | ||
outputFile: 'some/path/result.xml', | ||
formatterFlag: '--formatter', | ||
outputFlag: '--output', | ||
}); | ||
}); | ||
|
||
it('should work when provided a formatter name and a file output path', () => { | ||
expect( | ||
formatterConfig(defaultConfig, [ | ||
'Hi', | ||
'--output=some/path/result.xml', | ||
'Hello', | ||
'--formatter=junit', | ||
]) | ||
).toEqual({ | ||
name: 'junit', | ||
outputFile: 'some/path/result.xml', | ||
formatterFlag: '--formatter', | ||
outputFlag: '--output', | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.