describe('failure', () => { test('<failure message=""></failure>', () => { const mock = 'Lorem ispum' const actualReport = xml(failure(mock)) expect(actualReport).toMatchSnapshot() }) })
const processor = (report, reporterOptions = {}, jestRootDir = null) => { // If jest-junit is used as a reporter allow for reporter options // to be used. Env and package.json will override. const options = getOptions.options(reporterOptions); report.testResults.forEach((t, i) => { t.console = consoleBuffer[t.testFilePath]; }); const jsonResults = buildJsonResults(report, fs.realpathSync(process.cwd()), options); // Set output to use new outputDirectory and fallback on original output const outputName = (options.uniqueOutputName === 'true') ? getOptions.getUniqueOutputName() : options.outputName const output = path.join(options.outputDirectory, outputName); const finalOutput = getOptions.replaceRootDirInOutput(jestRootDir, output); // Ensure output path exists mkdirp.sync(path.dirname(finalOutput)); // Write data to file fs.writeFileSync(finalOutput, xml(jsonResults, { indent: ' ', declaration: true })); // Jest 18 compatibility return report; }
expect.extend({ toConvertToXmlAndPassXsd(jsonResults) { const xmlStr = xml(jsonResults, { indent: ' '}); const libxmljsObj = libxmljs.parseXmlString(xmlStr); const isValid = libxmljsObj.validate(schema); if (!isValid) { return { message: () => libxmljsObj.validationErrors.join('\n'), pass: false } } else { return { message: () => `expected not to validate against junit xsd`, pass: true } } } });
res.send('<?xml version="1.0" encoding="utf-8"?>\n' + xml(xmlString));
describe('testCase', () => { test('<testCase name="" duration=""/>', () => { const mock = { duration: 5, fullName: 'lorem ipsum' } const actualReport = xml(testCase(mock)) expect(actualReport).toMatchSnapshot() }) test('failing test case', () => { const mock = { failureMessages: ['Lorem ipsum'], status: 'failed', title: 'lorem ipsum' } const actualReport = xml(testCase(mock), true) expect(actualReport).toMatchSnapshot() }) })
describe('file', () => { test('<file path=""></file>', () => { const mock = { testFilePath: 'test/FooTest.js', testResults: [] } const actualReport = xml(file(mock)) expect(actualReport).toMatchSnapshot() }) test('testCase tag', () => { const mock = { testFilePath: 'test/FooTest.js', testResults: [ {title: 'lorem ipsum'}, {title: 'lorem ipsum'} ] } const actualReport = xml(file(mock), true) expect(actualReport).toMatchSnapshot() }) })